微信小程序生成带参二维码参数的处理

小程序二维码生成官方文档链接 https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html

  接口地址:https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN

 

    

getQCoder: function() {
var that = this
wx.request({
url: url + "/mini/createwxaqrcode",
data: {
page: "pages/Community/C-product/C-product",
scene: that.data.productId + "-" + that.data.spikeId
},
method: 'GET',
dataType: 'json',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: (res) => {
//从res中获取海报商品二维码
},

})
},

rl:是后台小伙伴给你提供的路径

data:page是通过识别小程序码进入的那个页面路径;scene是小程序码带的参数

scene参数不能有参数名,只能直接写值,若多参数的情况下你要在值与值之间拿分隔符隔开(这里分隔符使用的啥,后面获取参数值的时候就得拿这个分隔符截取);

不固定的参数:scene: that.data.productId + "-" + that.data.spikeId

固定的参数:scene: "123-csh"

其次,截取二维码参数:

: function(options) {

var that = this

if (options.scene) {

let scene = decodeURIComponent(options.scene);

//-是我们分隔参数的方式

let productId = scene.split("-")[0];

let spikeId = scene.split('-')[1];

that.setData({

productId: productId,

spikeId: spikeId

})

}

}

最后,使用小程序开发工具中 编译状态下的 "通过二维码编译" 识别小程序码测试是否获取到参数:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章