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'