微信SDK接通

This commit is contained in:
2026-07-01 19:56:44 +08:00
parent a1cbfc7241
commit aea1513836
38 changed files with 1610 additions and 92 deletions
@@ -0,0 +1,43 @@
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 interface IWechatProvider {
isEnabled(): boolean;
/** 小程序 code2session */
code2Session(code: string): Promise<WechatCodeSession>;
/** 公众号 H5 OAuth code 换 openId */
oauth2AccessToken(code: string): Promise<WechatOAuthSession>;
/** JSSDK 签名配置 */
createJssdkConfig(url: string): Promise<WechatJssdkConfig>;
/** 构建公众号 OAuth 授权 URL */
buildOAuthUrl(redirectUri: string, state: string, scope?: string): string;
/** 小程序手机号 code 解密(或调用微信 getPhoneNumber 接口) */
getPhoneNumberByCode(code: string, platform: 'mini' | 'h5'): Promise<string>;
/** 创建 JSAPI 预支付参数 */
createJsapiPrepay(params: {
orderNo: string;
description: string;
amountFen: number;
openId: string;
notifyUrl: string;
}): Promise<WechatJsapiPrepayParams>;
}