var jWeixin = require('jweixin-module') // 配置微信config function getSign() { // 获取微信签名 uni.request({ url: '',//后端获取签名的请求地址 method: '',//请求方式 data: { url: encodeURIComponent(location.href.split('#')[0]) }, success: (wxres) => { jWeixin.config({ debug: false, // 开启调试模式, appId: wxres.data.data.appId, // 必填,公众号的唯一标识 timestamp: wxres.data.data.timestamp, // 必填,生成签名的时间戳 nonceStr: wxres.data.data.nonceStr, // 必填,生成签名的随机串 signature: wxres.data.data.signature, // 必填,签名 jsApiList: ["scanQRCode", "chooseWXPay",'hideToolbar'] }); jWeixin.ready(function(res) { console.log('微信config配置成功res', res) }) } }) } // 微信扫一扫 function toggle() { return new Promise((resolve, reject) => { jWeixin.scanQRCode({ needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, scanType: ["qrCode"], success: function(res) { resolve(res.resultStr) // 当needResult 为 1 时,扫码返回的结果 }, fail: function(err) { reject(err) } }); }); } // 微信支付 function payment() { let paymentcon = JSON.parse(uni.getStorageSync('payment')) jWeixin.chooseWXPay({ timestamp: paymentcon.timeStamp, // 支付签名时间戳 nonceStr: paymentcon.nonceStr, // 支付签名随机串,不长于 32 位 package: paymentcon.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*) signType: paymentcon.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致 paySign: paymentcon.paySign, // 支付签名 success: function(res) { console.log(res, '支付成功') // 支付成功后的回调函数 } }); } export { getSign, toggle, payment }