完善认证功能,添加实名认证和回调处理逻辑

This commit is contained in:
2025-04-16 09:43:12 +08:00
parent 1f1f603523
commit d435d98887
8 changed files with 502 additions and 10 deletions

View File

@@ -238,6 +238,48 @@ async function callByUser<R = undefined>(
// endregion
// ======================
// region no token
// ======================
// 不需要令牌的公共API调用函数
async function callPublic<R = undefined>(
endpoint: string,
data?: unknown,
): Promise<ApiResponse<R>> {
try {
// 发送请求
const requestOptions: RequestInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data ? JSON.stringify(data) : undefined,
}
const response = await fetch(`${API_BASE_URL}${endpoint}`, requestOptions)
// 检查响应状态
if (!response.ok) {
console.log('公共接口响应不成功', `status=${response.status}`, await response.text())
return {
status: response.status,
success: false,
message: response.status >= 500 ? '服务器错误' : '请求失败',
}
}
return handleResponse(response)
}
catch (e) {
console.error('Public API call failed:', e)
throw new Error('服务调用失败', { cause: e })
}
}
// endregion
// 统一响应解析
async function handleResponse<R = undefined>(response: Response): Promise<ApiResponse<R>> {
@@ -286,4 +328,5 @@ export {
getUserToken,
callByDevice,
callByUser,
callPublic,
}