// 扫描
scanning() {
this.scanQRCodeByWX();
}
// 调用微信扫码功能
async scanQRCodeByWX() {
// 先配置微信数据
this.scanQRCodeConfig();
/* eslint-disable */
const _this = this;
window.wx.scanQRCode({
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function (res) {
// TODO 执行自己的逻辑
_this.form.serialNumber = res.resultStr.split(",")[1];
},
});
},
// 微信扫码配置
async scanQRCodeConfig() {
try {
// 调用接口获取微信签名,入参url一般是当前页面的url(不包括#及后面部分)
const res = await getWxOpenSubscribeParams({
url: window.location.href,
});
if (res.code !== 200) return this.msgDanger(res.msg);
if (Object.keys(res)) {
const { appId, nonceStr, signature, timestamp } = res.data;
window.wx.config({
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
debug: false,
// 必填,公众号的唯一标识
appId, // appId
// 必填,生成签名的时间戳
timestamp: "" + timestamp,
// 必填,生成签名的随机串
nonceStr: nonceStr,
// 必填,签名,见附录1
signature: signature,
// 必填,需要使用的JS接口列表,所有JS接口列表见附录2
jsApiList: ["checkJsApi", "scanQRCode"],
});
}
} catch (e) {
console.log("wxconfig配置catch", e);
}
},