微信小程式掃碼的程式碼及獲取二維碼的url地址
阿新 • • 發佈:2019-01-08
<view bindtap="scanCode">點選掃碼</view> scanCode: function (options) { var that = this; wx.scanCode({ success: function (res) { console.log(res); that.setData({ result: res.result }); var txt = that.data.result; var d = txt.split('?'); var e = d[1]; var g = '?'+e; var getUrlParam= function (name,t) { console.log(t); var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //構造一個含有目標引數的正則表示式物件 var r = t.substr(1).match(reg); //匹配目標引數 if (r != null) return unescape(r[2]); return null; //返回引數值 }; var a = getUrlParam('device_secret', g); console.log(a); //二維碼引數的值 wx.setStorageSync('device_secret', a) wx.request({ url: txt, data: { device_secret:a }, method: "GET", header: { 'content-type': 'application/json' }, success: function (res) { var data = JSON.stringify(res.data); console.log(data) if(data!=''){ wx.navigateTo({ url: '../pay/pay?data=' + data }) } } }) }, fail: function (res) { } }); }