From f43f563ea8eabb3215eae3a976eda74e5dffcab3 Mon Sep 17 00:00:00 2001 From: jerry Date: Fri, 15 Aug 2025 17:46:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=AF=E4=BB=98=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/usePayment.js | 42 ++++++++++++++++++++------------- src/pages/cart/cashier-weapp.js | 8 ++++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/hooks/usePayment.js b/src/hooks/usePayment.js index 77525c082..5532352b4 100644 --- a/src/hooks/usePayment.js +++ b/src/hooks/usePayment.js @@ -79,7 +79,7 @@ export default (props = {}) => { case 'alipaymini': alipaymini(params, orderInfo) case 'offline_pay': - offlinePay(params,orderInfo) + offlinePay(params, orderInfo) } } @@ -146,8 +146,8 @@ export default (props = {}) => { // payError(orderInfo) // }); // } else { - await Taro.requestPayment(weappOrderInfo) - paySuccess(params, orderInfo) + await Taro.requestPayment(weappOrderInfo) + paySuccess(params, orderInfo) // } } catch (e) { Taro.hideLoading() @@ -177,6 +177,14 @@ export default (props = {}) => { const wxpayjsPay = async (params, orderInfo) => { // const $instance = getCurrentInstance() const { order_id, code } = router.params + if (!code) { + // 微信客户端code授权 + const loc = window.location + // const url = `${loc.protocol}//${loc.host}/pages/cart/cashier-result?order_id=${orderId}` + const url = `${loc.protocol}//${loc.host}/pages/cart/cashier-weapp?order_id=${orderId}` + let { redirect_url } = await api.wx.getredirecturl({ url }) + window.location.href = redirect_url + } const { open_id } = await api.wx.getOpenid({ code }) const { pay_channel } = params const { pay_type, order_type = 'normal' } = orderInfo @@ -220,10 +228,10 @@ export default (props = {}) => { console.log(`wxpayh5Pay res:`, res) const loc = window.location const redirect_url = `${loc.protocol}//${loc.host}${cashierResultUrl}?order_id=${order_id}` - if(!res.mweb_url){ + if (!res.mweb_url) { //积分抵扣了所有金额,订单直接支付完成了 window.location.href = redirect_url - }else{ + } else { window.location.href = `${res.mweb_url}&redirect_url=${encodeURIComponent(redirect_url)}` } @@ -355,7 +363,7 @@ export default (props = {}) => { order_type: order_type }) paySuccess(params, orderInfo) - } catch(e) { + } catch (e) { payError(orderInfo) } } @@ -380,19 +388,19 @@ export default (props = {}) => { } const offlinePay = async (params, orderInfo) => { - console.log('offlinePay',params, orderInfo,isTradeDetaiPage()) + console.log('offlinePay', params, orderInfo, isTradeDetaiPage()) const { pay_channel, pay_type } = params - const { order_id, order_type, has_check} = orderInfo - await api.cashier.getPayment({ - pay_type, - pay_channel, - order_id, - order_type: order_type - }) + const { order_id, order_type, has_check } = orderInfo + await api.cashier.getPayment({ + pay_type, + pay_channel, + order_id, + order_type: order_type + }) if (isTradeDetaiPage()) { - Taro.navigateTo({url:`/pages/cart/offline-transfer?isDetail=true&order_id=${order_id}&has_check=${has_check}`}) - }else{ - Taro.redirectTo({url:'/pages/cart/offline-transfer?order_id='+order_id}) + Taro.navigateTo({ url: `/pages/cart/offline-transfer?isDetail=true&order_id=${order_id}&has_check=${has_check}` }) + } else { + Taro.redirectTo({ url: '/pages/cart/offline-transfer?order_id=' + order_id }) } diff --git a/src/pages/cart/cashier-weapp.js b/src/pages/cart/cashier-weapp.js index a37acaeff..7729b25ab 100644 --- a/src/pages/cart/cashier-weapp.js +++ b/src/pages/cart/cashier-weapp.js @@ -80,10 +80,12 @@ function CashierWeApp(props) { } const handlePay = async () => { - if(source){ - params.source = source + const { source } = $instance.router.params + let _params = { ...params } + if (source) { + _params.source = source } - cashierPayment(params, orderInfo) + cashierPayment(_params, orderInfo) } return (