微信扫码

scanQrcode:function (callBack) {
let data = {
appId: JSON.parse(sessionStorage.getItem('appIdSecret')).appId,
url: window.location.href.split('#')[0]
};
console.log('scanQrcode');
axios.$http(api.common.getJsApiConfig, data, 'get')
.then(res => {
if (res.data.status === 0) {
wx.config({
appId: res.data.data.appId, // 必填,公众号的唯一标识
timestamp: res.data.data.timestamp, // 必填,生成签名的时间戳
nonceStr: res.data.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.data.signature,// 必填,签名
jsApiList: ['scanQRCode']// 必填,需要使用的JS接口列表
});
wx.ready(function () {
wx.scanQRCode({
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["barCode","qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function (resData) {
let ticketUrl = resData.resultStr; // 当needResult 为 1 时,扫码返回的结果
console.log('ticketUrl====',ticketUrl)
callBack(ticketUrl);//扫码后结果处理
},
fail:function (res) {
bus.$createToast({type: 'error', time: 1000, txt: 'fail:扫码出错'})
console.log('fail:::',JSON.stringify(res));
}
});
})
}
else {
bus.$createToast({type: 'error', time: 1000, txt: res.data.message});
}
});

},

猜你喜欢

转载自www.cnblogs.com/lovemiao/p/10297681.html