Auth API
Auth API
login(options)
执行用户登录并签发认证码。
选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
timeout | number | - | 超时时间 (ms) |
success | function | - | 成功回调 |
fail | function | - | 失败回调 |
complete | function | - | 完成回调 |
成功响应:
| 字段 | 类型 | 说明 |
|---|---|---|
code | string | 用户登录码(用于服务器认证) |
userId | string | 用户唯一 ID |
errMsg | string | 结果消息 |
TudadaSDK.login({
timeout: 10000,
success: (res) => {
console.log('登录码:', res.code);
console.log('用户 ID:', res.userId);
// 将 code 发送到服务器创建会话
},
fail: (err) => console.error('登录失败:', err.errMsg),
});
checkSession(options)
检查当前会话的有效性。
选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
success | function | - | 成功回调(会话有效) |
fail | function | - | 失败回调(会话过期) |
complete | function | - | 完成回调 |
TudadaSDK.checkSession({
success: (res) => console.log('会话有效'),
fail: () => {
console.log('会话过期,需要重新登录');
TudadaSDK.login({ ... });
},
});
getUserInfo(options)
查询用户资料信息。
选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
withCredentials | boolean | - | 是否包含加密数据 |
lang | 'KO' | - | 返回语言 |
success | function | - | 成功回调 |
fail | function | - | 失败回调 |
complete | function | - | 完成回调 |
成功响应:
| 字段 | 类型 | 说明 |
|---|---|---|
userInfo.nickName | string | 昵称 |
userInfo.avatarUrl | string | 头像图片 URL |
encryptedData | string | 加密数据(使用 withCredentials 时) |
iv | string | 加密初始向量(使用 withCredentials 时) |
signature | string | 签名(使用 withCredentials 时) |
rawData | string | 原始数据(使用 withCredentials 时) |
TudadaSDK.getUserInfo({
success: (res) => {
console.log('昵称:', res.userInfo.nickName);
console.log('头像:', res.userInfo.avatarUrl);
},
});
// 包含加密数据
TudadaSDK.getUserInfo({
withCredentials: true,
success: (res) => {
// 将 encryptedData、iv 发送到服务器进行验证
sendToServer(res.encryptedData, res.iv);
},
});