From 9871c1147687d933fe43840b289157a895569a72 Mon Sep 17 00:00:00 2001 From: ozh Date: Tue, 15 Sep 2026 12:33:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E5=BE=AE=E4=BF=A1=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=20wxMini?= =?UTF-8?q?appLogin=20=E6=9B=BF=E6=8D=A2=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth.ts | 42 +++++++++++++++++++++++++++--------------- src/constants/auth.ts | 7 +++++++ 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/constants/auth.ts diff --git a/src/api/auth.ts b/src/api/auth.ts index d01ef52..7f302de 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,23 +1,35 @@ import { request } from '@/http' -const USE_MOCK = true - -export interface LoginParams { - username: string - password: string +// 微信小程序登录请求参数(2026-09-14 文档版,openId 为二次登录回传字段) +export interface WxMiniappLoginParams { + appId: string // 小程序 appId + code: string // Taro.login() 一次性 code,5 分钟有效 + openId?: string // 首次登录响应返回,后续登录/解密回传 + iv?: string + encryptedData?: string } -export interface LoginResult { - token: string +export interface WxUserInfo { userId: string + userType: number + avatar: string + nickName: string + mobile: string + gender: number + region: string + loginFrom: string } -export function login(params: LoginParams): Promise { - if (USE_MOCK) { - return Promise.resolve({ - token: 'mock-token-' + Date.now(), - userId: 'u-001' - }) - } - return request.post('/auth/login', params as unknown as Record) +export interface WxLoginResult { + userInfo: WxUserInfo + code: string // 登录凭证(token) + openId?: string // 首次登录返回,需本地缓存 +} + +export function wxMiniappLogin(params: WxMiniappLoginParams): Promise { + return request.post( + '/thirdPlatform/wxDevLogin/miniapp/login', + params as unknown as Record, + { needAuth: false } + ) } diff --git a/src/constants/auth.ts b/src/constants/auth.ts new file mode 100644 index 0000000..ca462cb --- /dev/null +++ b/src/constants/auth.ts @@ -0,0 +1,7 @@ +// 微信登录相关常量 + +// 二次登录回传 openId 的缓存 key(spec D3) +export const WX_OPENID_STORAGE_KEY = 'wx_openid' + +// getAccountInfoSync 取不到 appId 时的回退值(与 project.config.json 一致的测试号) +export const FALLBACK_WX_APP_ID = 'wxe9773bb6f025ab00'