4 changed files with 225 additions and 23 deletions
@ -0,0 +1,56 @@ |
|||||||
|
/** |
||||||
|
* 充值相关 API |
||||||
|
*/ |
||||||
|
import { get, post } from '../services/request' |
||||||
|
import { |
||||||
|
CreateRechargePaymentDto, |
||||||
|
RechargePaymentResponseDto, |
||||||
|
RechargeWechatPayParameters, |
||||||
|
PaymentChannel, |
||||||
|
} from '../types/recharge' |
||||||
|
|
||||||
|
/** 小程序 JSAPI 支付固定交易类型 */ |
||||||
|
const MINI_PROGRAM_TRADE_TYPE = 1 |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建充值订单 |
||||||
|
* @param dto 充值请求参数 |
||||||
|
* @returns 充值支付响应(含微信支付参数) |
||||||
|
*/ |
||||||
|
export const createRechargeOrder = (dto: CreateRechargePaymentDto) => { |
||||||
|
return post<RechargePaymentResponseDto>('/Recharge/create', { |
||||||
|
tradeType: MINI_PROGRAM_TRADE_TYPE, |
||||||
|
...dto, |
||||||
|
}, { |
||||||
|
showLoading: true, |
||||||
|
loadingText: '创建订单中...', |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询支付状态 |
||||||
|
* @param outTradeNo 商户订单号(创建充值订单时返回) |
||||||
|
* @param channel 支付渠道 |
||||||
|
* @returns 支付状态 |
||||||
|
*/ |
||||||
|
export const queryPaymentStatus = (outTradeNo: string, channel?: PaymentChannel) => { |
||||||
|
return get<boolean>(`/Recharge/query/${outTradeNo}`, channel ? { channel } : undefined) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 调起微信支付(充值场景) |
||||||
|
* @param payParams 微信支付参数 |
||||||
|
*/ |
||||||
|
export const invokeWechatPayForRecharge = (payParams: RechargeWechatPayParameters): Promise<void> => { |
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
wx.requestPayment({ |
||||||
|
timeStamp: payParams.timeStamp, |
||||||
|
nonceStr: payParams.nonceStr, |
||||||
|
package: payParams.package, |
||||||
|
signType: payParams.signType as 'MD5' | 'HMAC-SHA256' | 'RSA', |
||||||
|
paySign: payParams.paySign, |
||||||
|
success: () => resolve(), |
||||||
|
fail: (err) => reject(err), |
||||||
|
}) |
||||||
|
}) |
||||||
|
} |
||||||
@ -0,0 +1,61 @@ |
|||||||
|
/** |
||||||
|
* 充值相关类型定义 |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建充值订单请求参数 |
||||||
|
*/ |
||||||
|
export interface CreateRechargePaymentDto { |
||||||
|
/** 用户ID */ |
||||||
|
userId?: string |
||||||
|
/** 客户编码(充值对象) */ |
||||||
|
customerSn?: string |
||||||
|
/** 充值金额 */ |
||||||
|
amount?: number |
||||||
|
/** 赠送金额 */ |
||||||
|
giftAmount?: number |
||||||
|
/** 充值类型 */ |
||||||
|
rcgType?: number |
||||||
|
/** 交易类型:1-JSAPI/小程序 */ |
||||||
|
tradeType?: number |
||||||
|
/** 店铺编码 */ |
||||||
|
bpSn?: string |
||||||
|
/** 机构编码 */ |
||||||
|
instSn?: string |
||||||
|
/** OpenId(微信支付必传) */ |
||||||
|
openId?: string |
||||||
|
/** 支付标题 */ |
||||||
|
subject?: string |
||||||
|
/** 支付描述 */ |
||||||
|
body?: string |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建充值订单响应(data 字段内容) |
||||||
|
*/ |
||||||
|
export interface RechargePaymentResponseDto { |
||||||
|
/** 商户订单号 */ |
||||||
|
outTradeNo: string |
||||||
|
/** 支付渠道:1-微信、2-支付宝等 */ |
||||||
|
channel: number |
||||||
|
/** 调起微信支付所需参数 */ |
||||||
|
payParameters: RechargeWechatPayParameters | null |
||||||
|
/** 支付链接(Native扫码支付用) */ |
||||||
|
payUrl: string |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 微信支付参数(充值场景) |
||||||
|
*/ |
||||||
|
export interface RechargeWechatPayParameters { |
||||||
|
timeStamp: string |
||||||
|
nonceStr: string |
||||||
|
package: string |
||||||
|
signType: string |
||||||
|
paySign: string |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询支付状态的支付渠道枚举 |
||||||
|
*/ |
||||||
|
export type PaymentChannel = 'WechatPay' | 'Alipay' | 'UnionPay' | 'Balance' | 'BankCard' |
||||||
Loading…
Reference in new issue