<!--引入微信sdk-->
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
clickScanCode() {
let url = window.location.href.split('#')[0];
newApi.getSignature({ url }).then(res => {
if (res.code == 0) {
this.sdk.config({
beta: true,
debug: false,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: ["scanQRCode"]
});
this.sdk.ready(() => {
this.sdk.checkJsApi({
jsApiList: [
'scanQRCode',
],
success: (res) => {
console.log("jweixin.ready", res)
if (res.checkResult.getLocation == false) {
console.log('微信版本低')
return;
}
}
});
this.sdk.error((err) => {
this.sdk.error("接口调取失败", err)
});
this.sdk.scanQRCode({
desc: 'scanQRCode desc',
needResult: 1,
scanType: ["qrCode"],
success: (r) => {
window.location.href = r.resultStr
},
error: function (error) {
if (error.errMsg.indexOf('function_not_exist') > 0) {
alert('版本过低请升级')
}
}
});
});
}
})
}