diff --git a/common/utils/index.js b/common/utils/index.js index b49d528..1217e76 100644 --- a/common/utils/index.js +++ b/common/utils/index.js @@ -2,15 +2,17 @@ * @Author: ch * @Date: 2022-03-22 16:52:28 * @LastEditors: ch - * @LastEditTime: 2022-04-26 19:04:27 + * @LastEditTime: 2022-04-29 14:49:13 * @Description: 所有工具类统一在这输出 */ import * as util from './utils'; import * as requset from './requset'; import * as websocket from './requset'; +import * as wxpay from './wxpay'; export * from './utils'; export * from './requset'; export * from './websocket'; +export * from './wxpay'; -export default { ...util, ...requset, ...websocket} \ No newline at end of file +export default { ...util, ...requset, ...websocket, ...wxpay} \ No newline at end of file diff --git a/common/utils/requset.js b/common/utils/requset.js index 16c6494..ca41300 100644 --- a/common/utils/requset.js +++ b/common/utils/requset.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-17 17:42:32 * @LastEditors: ch - * @LastEditTime: 2022-04-29 14:03:56 + * @LastEditTime: 2022-04-29 15:15:55 * @Description: 项目接口请求统一处理器,返回一个需要token和不需要token的请求封装方法 */ @@ -14,7 +14,7 @@ const BASE_URL = { 'test' : 'https://k8s-horse-gateway.mashibing.cn', 'dev' : '', 'release' : '', - 'prod' : '//like-gateway.mashibing.com' + 'prod' : '//you-gateway.mashibing.com' }; /** * 接口返回成功结果统一处理 @@ -22,7 +22,7 @@ const BASE_URL = { * @param {*} option */ const successIntercept = (response, option) =>{ - clearRepeat(option) + clearRepeat(option); if(response.statusCode === 200){ const result = response.data; if(result.code === 'SUCCESS'){ diff --git a/common/utils/wxpay.js b/common/utils/wxpay.js new file mode 100644 index 0000000..dfb2f2c --- /dev/null +++ b/common/utils/wxpay.js @@ -0,0 +1,56 @@ +/* + * @Author: ch + * @Date: 2022-04-29 14:26:10 + * @LastEditors: ch + * @LastEditTime: 2022-04-29 14:54:16 + * @Description: file content + */ + +import { ApiPostWxH5Pay, ApiPostWxJsApiPay } from '@/common/api/wx'; +export const Wxpay = async ({orderId,openId})=>{ + // 有openId则表示在微信浏览器内 + 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?id=${orderId}` + }); + }else{ + uni.navigateTo({ + url : `/payResult?orderId=${orderId}` + }); + } + }) + }else{ + // h5支付 + const {error, result} = await ApiPostWxH5Pay({orderId}); + if(error){ + uni.$u.toast(error.message); + return false; + } + const redirect_url = decodeURIComponent(`https://like-app.mashibing.com/payResult?orderId=${orderId}`); + window.location.href = `${result.dataInfo.payUrl}&redirect_url=${redirect_url}`; + } +} \ No newline at end of file diff --git a/components/BsPay.vue b/components/BsPay.vue index 3fb82bf..e62db59 100644 --- a/components/BsPay.vue +++ b/components/BsPay.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-04-19 11:37:50 * @LastEditors: ch - * @LastEditTime: 2022-04-22 18:11:00 + * @LastEditTime: 2022-04-29 15:29:47 * @Description: file content -->