feat(auth): 微信小程序登录接口 wxMiniappLogin 替换 mock
This commit is contained in:
parent
c65d179333
commit
9871c11476
|
|
@ -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<LoginResult> {
|
||||
if (USE_MOCK) {
|
||||
return Promise.resolve({
|
||||
token: 'mock-token-' + Date.now(),
|
||||
userId: 'u-001'
|
||||
})
|
||||
}
|
||||
return request.post<LoginResult>('/auth/login', params as unknown as Record<string, unknown>)
|
||||
export interface WxLoginResult {
|
||||
userInfo: WxUserInfo
|
||||
code: string // 登录凭证(token)
|
||||
openId?: string // 首次登录返回,需本地缓存
|
||||
}
|
||||
|
||||
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