小程序码传参&小程序URL Scheme
获取小程序码,适用于需要的码数量极多的业务场景
获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。
token接口:传送门
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=##&secret=##
生成小程序码接口:传送门
https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=##
// Headers 设置
Content-Type: application/json
// 参数
{
"path": "pages/index/index",
"scene": "a=2",
"env_version": "develop"
}
生成URL Scheme: 传送门
https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN
// Headers 设置
Content-Type: application/json
// 参数
{
"jump_wxa": {
"path": "pages/index/index",
"query": "a=2",
"env_version": "develop"
}
}
// 返回示例
{
"errcode": 0,
"errmsg": "ok",
"openlink": "weixin://URL"
}
开发者工具演示
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// option 小程序码,URL Scheme,获取传参参数
// scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
const scene = decodeURIComponent(options)
console.log(options,scene)
// 上报自定义埋点
wx.reportEvent("source", {
"source_type": options.scene
})
},
利用发开着工具调试
设置进入场景模式