From 6651ffd06f77a711d50706aea8e3e6f6aaba02d4 Mon Sep 17 00:00:00 2001 From: ndbs Date: Thu, 27 Oct 2022 14:43:16 +0800 Subject: [PATCH] =?UTF-8?q?app2.0=E5=BE=AE=E4=BF=A1=E6=89=AB=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LearunApp-2.2.0/common/js/scanCodeFun.js | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/js/scanCodeFun.js b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/js/scanCodeFun.js index 509568d1b..98895eade 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/js/scanCodeFun.js +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/js/scanCodeFun.js @@ -1,28 +1,37 @@ +import wx from './weixin-js-sdk.js'; export default { scanCodeFun() { const promise = new Promise((resolve, reject) => { - // #ifdef APP-PLUS || MP-WEIXIN - uni.scanCode({ - success: function(res) { - // console.log(res) - // console.log('条码类型:' + res.scanType); - // console.log('条码内容:' + res.result); - resolve(res) - }, - fail: function(res) { + this.HTTP_GET("weixinapi/getweixinwebaccess_token?url=" + encodeURIComponent(window.location.href)).then((success)=>{ + if(!success){ resolve(false) + return } - }); - // #endif - - // #ifndef APP-PLUS || MP-WEIXIN - resolve(false) - uni.showToast({ - title: '请下载app或者到微信浏览器打开网页', - icon: 'none', - mask: false + wx.config({ + debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 + appId: success.appid, // 必填,公众号的唯一标识 + timestamp: success.timestamp, // 必填,生成签名的时间戳 + nonceStr: success.noncestr, // 必填,生成签名的随机串 + signature: success.certificate, // 必填,签名 + jsApiList: ["scanQRCode"] // 必填,需要使用的JS接口列表 + }); + wx.ready(() => { + wx.scanQRCode({ + needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, + scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有 + success: function (res) { + var result = res.resultStr; // 当 needResult 为 1 时,扫码返回的结果 + var resultArr = result.split(','); // 扫描结果以逗号分割数组 + var codeContent = resultArr[resultArr.length - 1]; // 获取数组最后一个元素,也就是最终的内容 + resolve({result:codeContent}) + }, + fail: function (res) { + this.TOAST("调用扫码失败") + resolve(false) + } + }); + }) }) - // #endif }) return promise }