feat(auth): 微信小程序登录接口 wxMiniappLogin 替换 mock
This commit is contained in:
parent
c65d179333
commit
9871c11476
|
|
@ -1,23 +1,35 @@
|
||||||
import { request } from '@/http'
|
import { request } from '@/http'
|
||||||
|
|
||||||
const USE_MOCK = true
|
// 微信小程序登录请求参数(2026-09-14 文档版,openId 为二次登录回传字段)
|
||||||
|
export interface WxMiniappLoginParams {
|
||||||
export interface LoginParams {
|
appId: string // 小程序 appId
|
||||||
username: string
|
code: string // Taro.login() 一次性 code,5 分钟有效
|
||||||
password: string
|
openId?: string // 首次登录响应返回,后续登录/解密回传
|
||||||
|
iv?: string
|
||||||
|
encryptedData?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginResult {
|
export interface WxUserInfo {
|
||||||
token: string
|
|
||||||
userId: string
|
userId: string
|
||||||
|
userType: number
|
||||||
|
avatar: string
|
||||||
|
nickName: string
|
||||||
|
mobile: string
|
||||||
|
gender: number
|
||||||
|
region: string
|
||||||
|
loginFrom: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function login(params: LoginParams): Promise<LoginResult> {
|
export interface WxLoginResult {
|
||||||
if (USE_MOCK) {
|
userInfo: WxUserInfo
|
||||||
return Promise.resolve({
|
code: string // 登录凭证(token)
|
||||||
token: 'mock-token-' + Date.now(),
|
openId?: string // 首次登录返回,需本地缓存
|
||||||
userId: 'u-001'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return request.post<LoginResult>('/auth/login', params as unknown as Record<string, unknown>)
|
|
||||||
|
export function wxMiniappLogin(params: WxMiniappLoginParams): Promise<WxLoginResult> {
|
||||||
|
return request.post<WxLoginResult>(
|
||||||
|
'/thirdPlatform/wxDevLogin/miniapp/login',
|
||||||
|
params as unknown as Record<string, unknown>,
|
||||||
|
{ needAuth: false }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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'
|
||||||
Loading…
Reference in New Issue