微信小程序生成帶參二維碼參數的處理

小程序二維碼生成官方文檔鏈接 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

})

}

}

最後,使用小程序開發工具中 編譯狀態下的 "通過二維碼編譯" 識別小程序碼測試是否獲取到參數:

 

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