Auth API
Auth API
Login(onSuccess, onFail, timeout)
执行用户登录。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
onSuccess | Action<LoginResult> | - | 成功回调 |
onFail | Action<string> | - | 失败回调 |
timeout | int | - | 超时时间 (ms) |
成功响应 (LoginResult):
| 字段 | 类型 | 说明 |
|---|---|---|
code | string | 登录码(用于服务器认证) |
userId | string | 用户唯一 ID |
errMsg | string | 结果消息 |
errCode | int | 错误码 |
TudadaSDK.Instance.Login(
onSuccess: (result) => {
Debug.Log("登录码: " + result.code);
Debug.Log("用户ID: " + result.userId);
// 将result.code发送到服务器以创建会话
},
onFail: (err) => Debug.LogError("登录失败: " + err),
timeout: 10000 // 可选: 超时时间(ms)
);
CheckSession(onSuccess, onFail)
检查会话有效性。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
onSuccess | Action<CheckSessionResult> | - | 会话有效时的回调 |
onFail | Action<string> | - | 会话过期时的回调 |
TudadaSDK.Instance.CheckSession(
onSuccess: (result) => Debug.Log("会话有效"),
onFail: (err) => {
Debug.Log("会话已过期,需要重新登录");
TudadaSDK.Instance.Login(...);
}
);
GetUserInfo(withCredentials, onSuccess, onFail)
查询用户个人资料信息。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
withCredentials | bool | - | 是否包含加密数据 |
onSuccess | Action<GetUserInfoResult> | - | 成功回调 |
onFail | Action<string> | - | 失败回调 |
成功响应 (GetUserInfoResult):
| 字段 | 类型 | 说明 |
|---|---|---|
userInfo.nickName | string | 昵称 |
userInfo.avatarUrl | string | 头像 URL |
encryptedData | string | 加密数据 |
iv | string | 加密向量 |
signature | string | 签名 |
TudadaSDK.Instance.GetUserInfo(
withCredentials: false, // 是否包含加密数据
onSuccess: (result) => {
Debug.Log("昵称: " + result.userInfo.nickName);
Debug.Log("头像: " + result.userInfo.avatarUrl);
},
onFail: (err) => Debug.LogError("查询失败: " + err)
);