Auth API
Auth API
Login(onSuccess, onFail, timeout)
执行用户登录。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
onSuccess | Action<LoginResult> | - | 成功回调 |
onFail | Action<string> | - | 失败回调 |
timeout | int | - | 超时时间 (ms) |
成功响应 (LoginResult):
| 字段 | 类型 | 说明 |
|---|---|---|
code | string | 登录码(用于服务器认证) |
userId | string | 用户唯一 ID |
userInfoPayload | string | 可验证的用户信息 payload (URL-encoded query string) |
userInfoSignature | string | 对 userInfoPayload 的签名 |
errMsg | string | 结果消息 |
errCode | int | 错误码 |
TudadaSDK.Instance.Login(
onSuccess: (result) => {
Debug.Log("登录码: " + result.code);
Debug.Log("用户ID: " + result.userId);
// 将 result.code 发送到服务器以创建会话
// 游戏服务器使用密钥自行验证
SendToGameServer(result.userInfoPayload, result.userInfoSignature);
},
onFail: (err) => Debug.LogError("登录失败: " + err),
timeout: 10000 // 可选: 超时时间(ms)
);
用户信息凭证 (userInfoPayload / userInfoSignature)
游戏服务器仅使用密钥即可自行验证的已签名用户信息。
userInfoPayload: URL-encoded query string。包含attribute,authDate,gameUserId,name,profileImageUrluserInfoSignature: 签名
签名验证完成后,游戏服务器可基于 authDate(unix timestamp ms)自由决定 token 过期策略。
CheckSession(onSuccess, onFail)
检查会话有效性。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
onSuccess | Action<CheckSessionResult> | - | 会话有效时的回调 |
onFail | Action<string> | - | 会话过期时的回调 |
TudadaSDK.Instance.CheckSession(
onSuccess: (result) => Debug.Log("会话有效"),
onFail: (err) => {
Debug.Log("会话已过期,需要重新登录");
TudadaSDK.Instance.Login(...);
}
);
GetUserInfo(onSuccess, onFail)
查询用户个人资料信息。返回用户资料和用于游戏服务器验证的用户信息凭证(userInfoPayload/userInfoSignature),凭证值与登录时签发的相同。
参数:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
onSuccess | Action<GetUserInfoResult> | - | 成功回调 |
onFail | Action<string> | - | 失败回调 |
成功响应 (GetUserInfoResult):
| 字段 | 类型 | 说明 |
|---|---|---|
userInfo.nickName | string | 昵称 |
userInfo.avatarUrl | string | 头像 URL |
userInfoPayload | string | 可验证的用户信息 payload (URL-encoded query string) |
userInfoSignature | string | 对 userInfoPayload 的签名 |
TudadaSDK.Instance.GetUserInfo(
onSuccess: (result) => {
Debug.Log("昵称: " + result.userInfo.nickName);
Debug.Log("头像: " + result.userInfo.avatarUrl);
// 游戏服务器验证
SendToGameServer(result.userInfoPayload, result.userInfoSignature);
},
onFail: (err) => Debug.LogError("查询失败: " + err)
);