SEC_Warehouse/src/api/auth.ts

48 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { request } from '@/http'
// 微信小程序登录请求参数(2026-09-14 文档版,openId 为二次登录回传字段)
export interface WxMiniappLoginParams {
appId: string // 小程序 appId
code: string // Taro.login() 一次性 code,5 分钟有效
openId?: string // 首次登录响应返回,后续登录/解密回传
iv?: string // 加密资料初始向量(getUserProfile 授权后补传)
encryptedData?: string // 加密用户资料(getUserProfile 授权后补传)
}
// 首次登录(needUserInfo)响应:仅含绑定凭证,无 token/用户信息
export interface WxNeedUserInfoResult {
openId: string
bindKey: string
}
// 用户信息(补授权后完整登录返回;联调前字段按文档版,实际字段名待确认)
export interface WxUserInfo {
userId: string
userType: number
avatar: string
nickName: string
mobile: string
gender: number
region: string
loginFrom: string
}
// 完整登录响应(needUserInfo=false 时)
export interface WxLoginResult {
userInfo: WxUserInfo
code: string // 登录凭证(token)
openId?: string // 首次登录返回,需本地缓存
}
// 登录响应联合体:Message === 'needUserInfo' 时为绑定凭证形态(needUserInfo 由 http 层标记)
export type WxMiniappLoginResponse = WxLoginResult &
Partial<WxNeedUserInfoResult> & { needUserInfo?: boolean }
export function wxMiniappLogin(params: WxMiniappLoginParams): Promise<WxMiniappLoginResponse> {
return request.post<WxLoginResult>(
'/thirdPlatform/wxDevLogin/miniapp/login',
params as unknown as Record<string, unknown>,
{ needAuth: false }
)
}