handleScan() {
// #ifndef H5
const that = this;
uni.scanCode({
onlyFromCamera: true,
success: function (res) {
if (that.detail.hardwareType && that.detail.hardwareType === 2) {
that.handleGetHardware(res.result);
} else {
that.$navTo(`./scan?id=${that.id}&qrcode=${res.result}`);
}
},
});
// #endif
// #ifdef H5
this.handleGetQYWX();
// #endif
},
async handleGetQYWX() {
try {
const that = this;
const { data } = await getConfig({
url: `${window.location.href}`,
});
that.obj.config({
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
// debug: true,
appId: data.corp_id, // 必填,企业微信的corpID
timestamp: data.timestamp, // 必填,生成签名的时间戳
nonceStr: data.nonceStr, // 必填,生成签名的随机串
signature: data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList: ['scanQRCode'], //必填,传入需要使用的接口名称
});
// eslint-disable-next-line
console.log(2);
// eslint-disable-next-line
that.obj.ready(function () {
// eslint-disable-next-line
console.log(4);
// eslint-disable-next-line
console.log('success', wx);
// eslint-disable-next-line
that.obj.scanQRCode({
desc: 'scanQRCode desc',
needResult: 1, // 默认为0,扫描结果由企业微信处理,1则直接返回扫描结果,
scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是条形码(一维码),默认二者都有
success: function (res) {
// 回调
let result = res.resultStr;
if (that.detail.hardwareType === 2) {
that.handleGetHardware(result);
} else {
that.$navTo(`./scan?id=${that.id}&qrcode=${result}`);
}
},
error: function (res) {
that.$refs.uToast.show({
title: '扫码失败,请重试',
type: 'default',
});
// if (res.errMsg.indexOf('function_not_exist') > 0) {
// alert('版本过低请升级')
// }
},
});
});
// eslint-disable-next-line
that.obj.error(function (res) {
// eslint-disable-next-line
console.log(3);
console.log(res);
});
} catch {}
},
你好,请移步企微官方讨论区:https://developer.work.weixin.qq.com/community/question