From eacb092b13a8aedb489474dda20fdf7bef8164cf Mon Sep 17 00:00:00 2001 From: ch Date: Wed, 15 Jun 2022 14:45:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/api/wx.js | 8 +++---- src/common/utils/pay.js | 46 +-------------------------------------- src/common/utils/wxpay.js | 10 ++++----- 3 files changed, 10 insertions(+), 54 deletions(-) diff --git a/src/common/api/wx.js b/src/common/api/wx.js index 9274bab..32d6a5a 100644 --- a/src/common/api/wx.js +++ b/src/common/api/wx.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-04-28 16:30:54 * @LastEditors: ch - * @LastEditTime: 2022-05-17 20:07:26 + * @LastEditTime: 2022-06-15 14:29:03 * @Description: file content */ @@ -39,18 +39,18 @@ export const ApiPostThirdInfo = (data) => * @param {*} data */ export const ApiPostWxH5Pay = (data) => - ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/pay/wxPay/h5`, data)); + ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/h5`, data)); /** * 微信JSAPI支付,获取支付参数 * @param {*} data */ export const ApiPostWxJsApiPay = (data) => - ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/pay/wxPay/jsapi`, data)); + ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/jsapi`, data)); /** * 微信APP支付 * @param {*} data */ export const ApiPostWxAppPay = (data) => - ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/pay/wxPay/app`, data)); \ No newline at end of file + ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/app`, data)); \ No newline at end of file diff --git a/src/common/utils/pay.js b/src/common/utils/pay.js index 593f342..4cb8dd0 100644 --- a/src/common/utils/pay.js +++ b/src/common/utils/pay.js @@ -2,57 +2,13 @@ * @Author: ch * @Date: 2022-05-06 15:33:55 * @LastEditors: ch - * @LastEditTime: 2022-05-26 19:04:50 + * @LastEditTime: 2022-06-15 14:26:16 * @Description: file content */ -import { ApiPostWxH5Pay, ApiPostWxJsApiPay } from '@/common/api/wx'; import ENV from '@/common/config/env'; import { Wxpay } from './wxpay'; export const pay = ({orderId, openId, payType})=>{ if(payType === 'wxpay'){ Wxpay({orderId, openId}); } - // #ifdef H5 - if(openId) { - // 微信JSAPI - const {error, result} = await ApiPostWxJsApiPay({orderId,openId}); - if(error){ - uni.$u.toast(error.message); - return false; - } - /* - * 公众号id appId 是 String(16) wx8888888888888888 - 时间戳 timeStamp 是 String(32) 1414561699 当前的时间 - 随机字符串 nonceStr 是 String(32) 5K8264ILTKCH16CQ2502SI8ZNMTM67VS 随机字符串,不长于32位。推荐随机数生成算法 - 订单详情扩展字符串 package 是 String(128) prepay_id=123456789 统一下单接口返回的prepay_id参数值,提交格式如:prepay_id=*** - 签名方式 signType 是 String(32) MD5 签名类型,默认为MD5,支持HMAC-SHA256和MD5。注意此处需与统一下单的签名类型一致 - 签名 paySign 是 String(64) C380BEC2BFD727A4B6845133519F3AD6 签名 - */ - const par = result.dataInfo; - WeixinJSBridge.invoke('getBrandWCPayRequest', { - appId : par.appId, - timeStamp : par.timeStamp, - nonceStr : par.nonceStr, - package : par.packageValue, - signType : par.signType, - paySign : par.paySign - }, res => { - if(res.err_msg !== 'get_brand_wcpay_request:cancel'){ - uni.navigateTo({ - url : `/payResult?orderId=${orderId}&payType=wxjsapi` - }); - } - }) - }else{ - // h5支付 - const {error, result} = await ApiPostWxH5Pay({orderId}); - if(error){ - uni.$u.toast(error.message); - return false; - } - const redirect_url = decodeURIComponent(`${ENV.staticUrl}/payResult?orderId=${orderId}&payType=wxh5`); - window.location.href = `${result.dataInfo.payUrl}&redirect_url=${redirect_url}`; - } - // #ednif - } \ No newline at end of file diff --git a/src/common/utils/wxpay.js b/src/common/utils/wxpay.js index 611caa2..eed3ae5 100644 --- a/src/common/utils/wxpay.js +++ b/src/common/utils/wxpay.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-04-29 14:26:10 * @LastEditors: ch - * @LastEditTime: 2022-05-26 20:28:48 + * @LastEditTime: 2022-06-15 14:43:50 * @Description: file content */ @@ -16,7 +16,7 @@ export const Wxpay = async ({orderId,openId})=>{ uni.$u.toast(error.message); return false; } - const par = result.dataInfo; + const par = result.payDataInfo; uni.requestPayment({ provider: 'wxpay', orderInfo :{ @@ -52,12 +52,12 @@ export const Wxpay = async ({orderId,openId})=>{ uni.$u.toast(error.message); return false; } - const par = result.dataInfo; + const par = result.payDataInfo; WeixinJSBridge.invoke('getBrandWCPayRequest', { appId : par.appId, timeStamp : par.timeStamp, nonceStr : par.nonceStr, - package : par.packageValue, + package: par.packageValue, signType : par.signType, paySign : par.paySign }, res => { @@ -75,7 +75,7 @@ export const Wxpay = async ({orderId,openId})=>{ return false; } const redirect_url = decodeURIComponent(`${ENV.staticUrl}/payResult?orderId=${orderId}&payType=wxh5`); - window.location.href = `${result.dataInfo.payUrl}&redirect_url=${redirect_url}`; + window.location.href = `${result.payDataInfo.h5Url}&redirect_url=${redirect_url}`; } // #endif