From d60d552bb1d03ec3eb5ad3c0f4a2037517cc7fb7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 24 Dec 2023 13:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=BE=AE=E4=BF=A1=E5=85=AC?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=94=AF=E4=BB=98=EF=BC=9A=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=20100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/libs/sdk-h5-weixin.js | 1 - sheep/platform/pay.js | 32 ++++++++++++++++++++------------ sheep/request/index.js | 1 - 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/sheep/libs/sdk-h5-weixin.js b/sheep/libs/sdk-h5-weixin.js index a280b897..57cafc4a 100644 --- a/sheep/libs/sdk-h5-weixin.js +++ b/sheep/libs/sdk-h5-weixin.js @@ -162,7 +162,6 @@ export default { // 微信支付 wxpay(data, callback) { this.isReady(() => { - debugger jweixin.chooseWXPay({ timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位 diff --git a/sheep/platform/pay.js b/sheep/platform/pay.js index 47f1f9f5..447b64ad 100644 --- a/sheep/platform/pay.js +++ b/sheep/platform/pay.js @@ -92,7 +92,7 @@ export default class SheepPay { channelExtras: {} }; // 特殊逻辑:微信公众号、小程序支付时,必须传入 openid - if (['wx_pub'].includes(channel)) { + if (['wx_pub', 'wx_lite'].includes(channel)) { const openid = await sheep.$platform.useProvider('wechat').getOpenid(); // 如果获取不到 openid,微信无法发起支付,此时需要引导 if (!openid) { @@ -101,6 +101,7 @@ export default class SheepPay { } data.channelExtras.openid = openid; } + // 发起预支付 API 调用 PayOrderApi.submitOrder(data).then((res) => { // 成功时 res.code === 0 && resolve(res); @@ -140,12 +141,11 @@ export default class SheepPay { }); } - // 浏览器微信H5支付 TODO 芋艿:待接入 + // 浏览器微信 H5 支付 TODO 芋艿:待接入 async wechatWapPay() { const { error, data } = await this.prepay(); if (error === 0) { - const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment - }&orderType=${this.orderType}`; + const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment}&orderType=${this.orderType}`; location.href = `${data.pay_data.h5_url}&redirect_url=${encodeURIComponent(redirect_url)}`; } } @@ -154,29 +154,37 @@ export default class SheepPay { async redirectPay() { let { error, data } = await this.prepay(); if (error === 0) { - const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment - }&orderType=${this.orderType}`; + const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment}&orderType=${this.orderType}`; location.href = data.pay_data + encodeURIComponent(redirect_url); } } // #endif - // 微信小程序支付 TODO 芋艿:待接入 + // 微信小程序支付 async wechatMiniProgramPay() { - let that = this; - let result = await this.prepay(); + // let that = this; + let { code, data } = await this.prepay('wx_lite'); + if (code !== 0) { + return; + } + // 调用微信小程序支付 + const payConfig = JSON.parse(data.displayContent); uni.requestPayment({ provider: 'wxpay', - ...result.data.pay_data, + timeStamp: payConfig.timeStamp, + nonceStr: payConfig.nonceStr, + package: payConfig.packageValue, + signType: payConfig.signType, + paySign: payConfig.paySign, success: (res) => { - that.payResult('success'); + this.payResult('success'); }, fail: (err) => { if (err.errMsg === 'requestPayment:fail cancel') { sheep.$helper.toast('支付已手动取消'); } else { - that.payResult('fail'); + this.payResult('fail'); } }, }); diff --git a/sheep/request/index.js b/sheep/request/index.js index cea66c9d..2ddd7f3a 100644 --- a/sheep/request/index.js +++ b/sheep/request/index.js @@ -115,7 +115,6 @@ http.interceptors.response.use( } // TODO 芋艿:如果是登录的 API,则自动设置 token if (response.data?.data?.accessToken) { - debugger $store('user').setToken(response.data.data.accessToken); }