diff --git a/src/common/api/pay.js b/src/common/api/pay.js new file mode 100644 index 0000000..87e97af --- /dev/null +++ b/src/common/api/pay.js @@ -0,0 +1,47 @@ +/* + * @Author: ch + * @Date: 2022-04-28 16:30:54 + * @LastEditors: ch + * @LastEditTime: 2022-06-29 17:15:57 + * @Description: file content + */ + +import {ToAsyncAwait, MsbRequest, MsbRequestTk} from '@/common/utils'; + +const BASE_URL = '/mall/trade'; + +/** + * 微信h5支付,获取支付URL + * @param {*} data + */ +export const ApiPostWxH5Pay = (data) => + ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/h5`, data)); + +/** + * 微信JSAPI支付,获取支付参数 + * @param {*} data + */ +export const ApiPostWxJsApiPay = (data) => + ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/jsapi`, data)); + +/** + * 微信APP支付 + * @param {*} data + */ +export const ApiPostWxAppPay = (data) => + ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/app`, data)); + + +/** + * 支付宝APP支付 + * @param {*} data + */ +export const ApiPostAliAppPay = (data) => + ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/aliPay/app`, data)); + +/** + * 支付宝h5支付,获取支付URL + * @param {*} data + */ +export const ApiPostAliH5Pay = (data) => +ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/aliPay/wap`, data)); diff --git a/src/common/api/wx.js b/src/common/api/wx.js index 32d6a5a..cc9e806 100644 --- a/src/common/api/wx.js +++ b/src/common/api/wx.js @@ -2,13 +2,12 @@ * @Author: ch * @Date: 2022-04-28 16:30:54 * @LastEditors: ch - * @LastEditTime: 2022-06-15 14:29:03 + * @LastEditTime: 2022-06-29 17:16:50 * @Description: file content */ import {ToAsyncAwait, MsbRequest, MsbRequestTk} from '@/common/utils'; -const BASE_URL = '/mall/trade'; // 第三方鉴权服务 const AUTH_URL = '/third'; const APPID = 'wxd2015f0c56defa02'; @@ -33,24 +32,3 @@ export const ApiGetOpenId = ({code}) => */ export const ApiPostThirdInfo = (data) => ToAsyncAwait(MsbRequestTk.post(`${AUTH_URL}/third/saveThirdInfo`, {...data, appId:APPID})); - -/** - * 微信h5支付,获取支付URL - * @param {*} data - */ -export const ApiPostWxH5Pay = (data) => - ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/h5`, data)); - -/** - * 微信JSAPI支付,获取支付参数 - * @param {*} data - */ -export const ApiPostWxJsApiPay = (data) => - ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/jsapi`, data)); - -/** - * 微信APP支付 - * @param {*} data - */ -export const ApiPostWxAppPay = (data) => - ToAsyncAwait(MsbRequestTk.post(`${BASE_URL}/payCenter/wxPay/app`, data)); \ No newline at end of file diff --git a/src/common/utils/alipay.js b/src/common/utils/alipay.js new file mode 100644 index 0000000..4f37359 --- /dev/null +++ b/src/common/utils/alipay.js @@ -0,0 +1,58 @@ +/* + * @Author: ch + * @Date: 2022-04-29 14:26:10 + * @LastEditors: ch + * @LastEditTime: 2022-06-29 17:25:38 + * @Description: file content + */ + +import { ApiPostAliH5Pay, ApiPostAliAppPay } from '@/common/api/pay'; +import ENV from '@/common/config/env'; +export const Alipay = async ({orderId})=>{ + + // #ifdef APP-PLUS + const {error, result} = await ApiPostAliAppPay({orderId}); + if(error){ + uni.$u.toast(error.message); + return false; + } + const par = result.payDataInfo; + uni.requestPayment({ + provider: 'alipay', + orderInfo :{ + "appid": par.appId, // 微信开放平台 - 应用 - AppId + "noncestr": par.nonceStr, // 随机字符串 + "package": par.packageValue, // 固定值 + "partnerid": par.partnerId, // 微信支付商户号 + "prepayid": par.prepayId, // 统一下单订单号 + "timestamp": par.timeStamp ,// 时间戳(单位:秒) + "sign": par.sign // 签名,这里用的 MD5 签名 + }, + success(res) { + uni.navigateTo({ + url : `/payResult?orderId=${orderId}&payType=appWx` + }); + }, + fail(e) { + uni.navigateTo({ + url : `/payResult?orderId=${orderId}&payType=appWx` + }); + } + }).then(res => { + console.log('res',res); + }) + // #endif + + // #ifdef H5 + const { error, result } = await ApiPostAliH5Pay({ + orderId, + returnUrl : decodeURIComponent(`${ENV.staticUrl}/payResult?orderId=${orderId}&payType=alih5`) + }); + if(error){ + uni.$u.toast(error.message); + return false; + } + window.location.href = result.payDataInfo.payUrl; + // #endif + +} \ No newline at end of file diff --git a/src/common/utils/index.js b/src/common/utils/index.js index 75ac9ef..d1df7e4 100644 --- a/src/common/utils/index.js +++ b/src/common/utils/index.js @@ -2,17 +2,19 @@ * @Author: ch * @Date: 2022-03-22 16:52:28 * @LastEditors: ch - * @LastEditTime: 2022-05-20 11:42:33 + * @LastEditTime: 2022-06-29 17:22:32 * @Description: 所有工具类统一在这输出 */ import * as util from './utils'; import * as requset from './requset'; import * as im from './im'; import * as wxpay from './wxpay'; +import * as alipay from './alipay'; export * from './utils'; export * from './requset'; export * from './im'; export * from './wxpay'; +export * from './alipay'; -export default { ...util, ...requset, ...im, ...wxpay} \ No newline at end of file +export default { ...util, ...requset, ...im, ...wxpay, ...alipay} \ No newline at end of file diff --git a/src/common/utils/wxpay.js b/src/common/utils/wxpay.js index eed3ae5..7609196 100644 --- a/src/common/utils/wxpay.js +++ b/src/common/utils/wxpay.js @@ -2,11 +2,11 @@ * @Author: ch * @Date: 2022-04-29 14:26:10 * @LastEditors: ch - * @LastEditTime: 2022-06-15 14:43:50 + * @LastEditTime: 2022-06-29 17:17:40 * @Description: file content */ -import { ApiPostWxH5Pay, ApiPostWxJsApiPay, ApiPostWxAppPay } from '@/common/api/wx'; +import { ApiPostWxH5Pay, ApiPostWxJsApiPay, ApiPostWxAppPay } from '@/common/api/pay'; import ENV from '@/common/config/env'; export const Wxpay = async ({orderId,openId})=>{ diff --git a/src/components/BsPay.vue b/src/components/BsPay.vue index 7650657..9bb0136 100644 --- a/src/components/BsPay.vue +++ b/src/components/BsPay.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-04-19 11:37:50 * @LastEditors: ch - * @LastEditTime: 2022-05-05 11:08:44 + * @LastEditTime: 2022-06-29 17:27:12 * @Description: file content -->