对接微信支付

This commit is contained in:
2026-07-01 22:41:49 +08:00
parent b78ef8798c
commit ff4622ff6c
14 changed files with 389 additions and 19 deletions
@@ -14,9 +14,22 @@ export type WechatOAuthSession = {
refreshToken?: string;
};
export type WechatPayNotifyResult = {
transactionId: string;
outTradeNo: string;
tradeState: string;
amountFen: number;
};
export interface IWechatProvider {
isEnabled(): boolean;
/** 微信支付是否已配置(商户号 + 证书) */
isPayEnabled(): boolean;
/** 当前商户号(用于日志/排查) */
getMchId(): string;
/** 小程序 code2session */
code2Session(code: string): Promise<WechatCodeSession>;
@@ -32,7 +45,7 @@ export interface IWechatProvider {
/** 小程序手机号 code 解密(或调用微信 getPhoneNumber 接口) */
getPhoneNumberByCode(code: string, platform: 'mini' | 'h5'): Promise<string>;
/** 创建 JSAPI 预支付参数 */
/** 创建 JSAPI 预支付参数(使用 WX_MCH_ID 统一下单) */
createJsapiPrepay(params: {
orderNo: string;
description: string;
@@ -40,4 +53,10 @@ export interface IWechatProvider {
openId: string;
notifyUrl: string;
}): Promise<WechatJsapiPrepayParams>;
/** 解析并验签支付回调通知 */
parsePayNotification(
headers: Record<string, string | string[] | undefined>,
rawBody: string,
): Promise<WechatPayNotifyResult>;
}