跳到主要内容

Auth API

Auth API

Login(onSuccess, onFail, timeout)

执行用户登录。

参数:

参数类型必须说明
onSuccessAction<LoginResult>-成功回调
onFailAction<string>-失败回调
timeoutint-超时时间 (ms)

成功响应 (LoginResult):

字段类型说明
codestring登录码(用于服务器认证)
userIdstring用户唯一 ID
errMsgstring结果消息
errCodeint错误码
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)

检查会话有效性。

参数:

参数类型必须说明
onSuccessAction<CheckSessionResult>-会话有效时的回调
onFailAction<string>-会话过期时的回调
TudadaSDK.Instance.CheckSession(
onSuccess: (result) => Debug.Log("会话有效"),
onFail: (err) => {
Debug.Log("会话已过期,需要重新登录");
TudadaSDK.Instance.Login(...);
}
);

GetUserInfo(withCredentials, onSuccess, onFail)

查询用户个人资料信息。

参数:

参数类型必须说明
withCredentialsbool-是否包含加密数据
onSuccessAction<GetUserInfoResult>-成功回调
onFailAction<string>-失败回调

成功响应 (GetUserInfoResult):

字段类型说明
userInfo.nickNamestring昵称
userInfo.avatarUrlstring头像 URL
encryptedDatastring加密数据
ivstring加密向量
signaturestring签名
TudadaSDK.Instance.GetUserInfo(
withCredentials: false, // 是否包含加密数据
onSuccess: (result) => {
Debug.Log("昵称: " + result.userInfo.nickName);
Debug.Log("头像: " + result.userInfo.avatarUrl);
},
onFail: (err) => Debug.LogError("查询失败: " + err)
);