1、获取加密scheme码
获取加密scheme码 用于获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放。
注意事项:
- 加密 URL Scheme 支持开发者自行在链接后面拼接 query 参数
- 微信内的网页如需打开小程序请使用微信开放标签-小程序跳转按钮,无公众号也可以直接使用小程序身份开发网页并免鉴权跳转小程序,见云开发静态网站跳转小程序。符合开放范围的小程序可以下发支持打开小程序的短信
- 该功能基本覆盖当前用户正在使用的微信版本,开发者无需进行低版本兼容
- 只能生成已发布的小程序的 URL Scheme
- 通过 URL Scheme 跳转到微信时,可能会触发系统弹框询问,若用户选择不跳转,则无法打开小程序。请开发者妥善处理用户选择不跳转的场景
- 部分浏览器会限制打开网页直接跳转,可参考示例网页设置跳转按钮
2、生成加密scheme码
- 生成加密scheme码
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class WxSchemeService {
private final WxMaService wxMaService;
public String getUnlimitWxaCode() throws Exception {
// 正式版
String envVersion = WxMaConstants.DEFAULT_ENV_VERSION;
// 体验版
// String envVersion = WxMaConstants.MiniProgramState.TRIAL;
// 开发版
// String envVersion = WxMaConstants.MiniProgramState.DEVELOPER;
WxMaGenerateSchemeRequest request = WxMaGenerateSchemeRequest.newBuilder()
.jumpWxa(WxMaGenerateSchemeRequest.JumpWxa.newBuilder()
// 通过 scheme 码进入的小程序页面路径
.path("pages/station/stationDetail")
// 通过 scheme 码进入小程序时的 query
.query("stationId=10001")
// 要打开的小程序版本,默认值"release"
.envVersion(envVersion)
.build())
// 到期失效的 scheme 码的失效时间
.expireTime(System.currentTimeMillis() + 24 * 60 * 60)
.build();
return wxMaService.getWxMaSchemeService().generate(request);
}
}
- 得到scheme码如下:
weixin://dl/business/?t=XTSkBZlzqmn&cq=a%3Dhello
- 小程序端获取参数
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let query = options.query
}
如您在阅读中发现不足,欢迎留言!!!