Files
xin-school-taro/src/services/auth.ts
T
2026-07-15 12:24:06 +08:00

40 lines
1.1 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 { post } from '@/utils/request'
import type { ApiResponse } from '@/types/api'
import type { User } from '@/types/user'
/** 登录请求参数 */
export interface WxLoginParams {
/** 前端调用 Taro.login() 获取的临时凭证(用于换取 openid/session_key */
code: string
/**
* 手机号动态令牌(新版微信 API)
* openType="getPhoneNumber" 回调 e.detail.code
* 后端用此 code 调用微信接口换取手机号
*/
phoneCode?: string
/**
* 手机号加密数据(旧版微信 API,与 iv 配套使用)
* openType="getPhoneNumber" 回调 e.detail.encryptedData
*/
encryptedData?: string
/**
* 加密算法初始向量(旧版微信 API,与 encryptedData 配套使用)
* openType="getPhoneNumber" 回调 e.detail.iv
*/
iv?: string
}
/** 登录响应 data */
export interface WxLoginData {
token: string
user: User
}
/**
* 微信小程序登录
* POST /api/wx/login(公开接口,不附带 token
*/
export function wxLoginApi(params: WxLoginParams): Promise<ApiResponse<WxLoginData>> {
return post<WxLoginData>('/api/wx/login', params, { skipToken: true })
}