Files
dukang/server/dukang-api/src/integrations/wechat/wechat.interface.ts
T
2026-07-06 20:56:25 +08:00

81 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { WechatJssdkConfig, WechatJsapiPrepayParams } from '@dukang/shared-types';
export type WechatCodeSession = {
openId: string;
unionId?: string;
sessionKey?: string;
accessToken?: string;
};
export type WechatOAuthSession = {
openId: string;
unionId?: string;
accessToken?: string;
refreshToken?: string;
};
export type WechatOAuthUserInfo = {
openId: string;
nickname?: string;
headImgUrl?: string;
unionId?: 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, actorRef?: { refType: string; refId: bigint }): Promise<WechatCodeSession>;
/** 公众号 H5 OAuth code 换 openId */
oauth2AccessToken(code: string, actorRef?: { refType: string; refId: bigint }): Promise<WechatOAuthSession>;
/** 公众号 OAuth access_token 拉取用户昵称头像(snsapi_userinfo */
fetchOAuthUserInfo(
accessToken: string,
openId: string,
actorRef?: { refType: string; refId: bigint },
): Promise<WechatOAuthUserInfo>;
/** JSSDK 签名配置 */
createJssdkConfig(url: string, actorRef?: { refType: string; refId: bigint }): Promise<WechatJssdkConfig>;
/** 构建公众号 OAuth 授权 URL */
buildOAuthUrl(redirectUri: string, state: string, scope?: string): string;
/** 小程序手机号 code 解密(或调用微信 getPhoneNumber 接口) */
getPhoneNumberByCode(
code: string,
platform: 'mini' | 'h5',
actorRef?: { refType: string; refId: bigint },
): Promise<string>;
/** 创建 JSAPI 预支付参数(使用 WX_MCH_ID 统一下单) */
createJsapiPrepay(params: {
orderNo: string;
description: string;
amountFen: number;
openId: string;
notifyUrl: string;
}): Promise<WechatJsapiPrepayParams>;
/** 解析并验签支付回调通知 */
parsePayNotification(
headers: Record<string, string | string[] | undefined>,
rawBody: string,
): Promise<WechatPayNotifyResult>;
}