Android
本文旨在介绍如何设置 Square Enix 身份验证,让您的游戏可以使用 Player Network 登录鉴权服务通过 Square Enix 渠道登录。
前提条件
1. 设置 Square Enix 应用
联系 Square Enix 团队激活您的应用程序,从 Square Enix Bridge 获取 タイトルID(SE Game ID)、Consumer Key 和 Consumer Secret。
获取应用程序信息
- 获取 Player Network 控制台登录账号。
- 为游戏创建新项目,或加入已有项目。
- 下载 SDK。
- 接入 SDK。
- 在 Player Network 控制台添加 Square Enix 为业务的登录鉴权方式。
步骤1:为 Square Enix 登录配置 SDK
在
AndroidManifest
文件中,添加所需的权限。SquareEnix 需要网络访问权限。<uses-permission android:name="android.permission.INTERNET"/>
打开项目的 INTLConfig.ini 文件:
[SquareEnix]
SQUARE_ENIX_APP_ID = {INTL_SQUARE_ENIX_APP_ID}
SQUARE_ENIX_CONSUMER_KEY = {INTL_SQUARE_ENIX_CONSUMER_KEY}
SQUARE_ENIX_CONSUMER_SECRET = {INTL_SQUARE_ENIX_CONSUMER_SECRET}
SQUARE_ENIX_TEST = 0- 将
{INTL_SQUARE_ENIX_APP_ID}
替换为游戏团队提交的应用程序的 Square Enix 应用程序 ID。 - 将
{INTL_SQUARE_ENIX_CONSUMER_KEY}
替换为游戏团队提交的应用程序的 Square Enix 消费者密钥。 - 将
{INTL_SQUARE_ENIX_CONSUMER_SECRET}
替换为游戏团队提交的应用程序的 Square Enix 消费者密匙。 SQUARE_ENIX_TEST
:用于确定是否为 Square Enix 测试环境; 0:正式环境,1:测试环境; 默认为 0。
- 将
步骤2:添加 Square Enix 登录
首次调用登录 API 时,会自动调用 people.create
API 进行注册。
更多信息,请参见 Square Enix Bridge Developer Center 内的 注册 或 登录 文档。
注册登录相关回调。
- Unity
- Unreal Engine
// Add callbacks
public void AddAuthObserver()
{
INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
}
// Remove callbacks
public void RemoveAuthObserver()
{
INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
}
// Process the INTLAuthResult callback
public void OnAuthResultEvent(INTLAuthResult ret)
{
Debug.Log($"MethodID: {ret.MethodId}");
string methodTag = "";
if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
{
methodTag = "Login";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
{
methodTag = "Bind";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
{
methodTag = "AutoLogin";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
{
methodTag = "QueryUserInfo";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
{
methodTag = "GetAuthResult";
}
}C++ Event Handling (above v1.15)
//configure callback
FINTLAuthEvent authEvent;
authEvent.AddUObject(this, &OnAuthResult_Implementation);
UINTLSDKAPI::SetAuthResultObserver(authEvent);
// Remove callbacks
UINTLSDKAPI::GetAuthResultObserver().Clear();void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Unreal Event Handling
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}调用
AutoLogin
接口自动登录。- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
在自动登录失败时调用
Login
接口使玩家手动登录。- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.SquareEnix, "", "");
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelSquareEnix);
与游戏后台同步客户端身份验证状态,等待最终验证结果。
注销功能
目前,注销功能只退出登录状态,并不清除 UUID。游戏需要使用 resetUuid
来清除 UUID。
- Unity
- Unreal Engine
INTLAPI.Logout(INTLChannel.SquareEnix);
UINTLSDKAPI::Logout(EINTLLoginChannel::kChannelSquareEnix);
步骤3:验收登录功能
- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.SquareEnix, "", "{\"se_login_only\":true}");
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelSquareEnix, "", "{\"se_login_only\":true}");
- 如果登录成功,返回的结果与正常登录结果相同。
- 如果登录不成功,请查看具体的错误代码和错误信息:RetCode
、
RetMsg、
ThirdCode、
ThirdMsg`。
返回结果示例(成功):
{
"OpenId": "xxxxxxxxxxxxxxx",
"Token": "xxxxxxxxxxxxxxx",
"TokenExpire": 1641044623,
"FirstLogin": 0,
"UserName": "",
"Gender": 0,
"Birthdate": "",
"PictureUrl": "",
"Pf": "xxxxxxxxxxxxx",
"PfKey": "xxxxxxxxxxxxx",
"NeedRealNameAuth": false,
"ChannelID": 32,
"Channel": "SquareEnix",
"ChannelInfo": {
"se_sessionid": "xxxxxxxxxxxxxxx",
"expire_ts": 1641044623
},
"ConfirmCode": "",
"BindList": "",
"MethodId": 102,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 0,
"ThirdMsg": "success",
"ExtraJson": {}
}
如果设备在成功登录后被其他设备重定向,并执行登录或自动登录过程,则将返回一个 ThirdCode
为 1276
的错误代码,表示当前登录状态无效。
这种情况下的登录必须使用以下方法:
- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.SquareEnix, "", "{\"se_register\":true}");
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelSquareEnix, "", "{\"se_register\":true}");
其他功能
绑定功能
- Unity
- Unreal Engine
INTLAPI::ExtendInvoke(INTLChannel.SquareEnix, "bind", "");
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "bind", "");
有关绑定过程的更多信息,请参见 Binding Docs。
证书转移功能
- Unity
- Unreal Engine
INTLAPI::ExtendInvoke(INTLChannel.SquareEnix, "takeover", "");
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "takeover", "");
有关证书转移过程的更多信息,请参见 证书转移文档。
用户信息采集功能
- Unity
- Unreal Engine
INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "getSeUserInfo", "");
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "getSeUserInfo", "");
返回结果示例:
{
"Channel": "SquareEnix",
"ExtendMethodName": "getSeUserInfo",
"MethodId": 1301,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 1,
"ThirdMsg": "",
"ExtraJson": {
"uuid": "576091342997165636789245472976025261",
"se_user_info": "{\"androidRegistrationId\":null,\"iosDeviceToken\":null,\"channel\":null,\"deviceType\":2,
\"nativeTagName\":\"apr1A6XN7jnGf\",\"nativeUserId\":18235236,\"nickName\":null,\"thumbnailUrl\":null,
\"gameId\":470,\"inviteNativeUserId\":null,\"userId\":null,\"cesaLimitAge\":null,\"sex\":null,
\"fcmRegistrationId\":null,\"tagName\":null,\"birthYearMonth\":null,\"introduction\":null,\"userRank\":0}"
}
}
// Parse "se_user_info" in the ExtraJson field
用户 ID 获取功能
- Unity
- Unreal Engine
INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "getSeUserId", "");
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "getSeUserId", "");
返回结果示例:
{
"Channel": "SquareEnix",
"ExtendMethodName": "getNativeUserID",
"MethodId": 1301,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 1,
"ThirdMsg": "",
"ExtraJson": {
"se_user_id": 18235236
}
}
// Parse "se_user_id"
服务器创建功能
- Unity
- Unreal Engine
string extraJson = "{\"world_id\":\"@self\"}";
INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "createSeWorld", extraJson);
FString extraJson = "{\"world_id\":\"@self\"}";
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "createSeWorld", extraJson);
extraJson
字段应传递所创建世界的 world_id
。要使用默认值,请传 @self
。
返回结果示例(成功):
{
"Channel": "SquareEnix",
"ExtendMethodName": "createSeWorld",
"MethodId": 1301,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 1,
"ThirdMsg": "",
"ExtraJson": {}
}
返回结果示例(失败):
{
"Channel": "SquareEnix",
"ExtendMethodName": "createSeWorld",
"MethodId": 1301,
"RetCode": 5,
"RetMsg": "Server error",
"ThirdCode": 1277,
"ThirdMsg": "world has been created, se response 404: [E2001](67) ModelCode: DAO-493014",
"ExtraJson": {}
}
// ThirdCode is the error code reported
// ThirdMsg is the error reason
渠道 SessionId 获取功能
- Unity
- Unreal Engine
INTLAPI.ExtendInvoke(INTLChannel.SquareEnix,"getSeNativeSessionId", "");
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "getSeNativeSessionId", "");
返回结果示例:
{
"Channel": "SquareEnix",
"ExtendMethodName": "getCachedNativeSessionId",
"MethodId": 1301,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 1,
"ThirdMsg": "",
"ExtraJson": {
"se_session_id": "034991a20e2f150577be4f93b8d471a1"
}
}
// Parse "se_session_id"
获取当前 UUID(同步)
- Unity
- Unreal Engine
string uuid = INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "getCurrentUuid", "");
FString uuid = UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "getCurrentUuid", "");
获取 UUID 早期登录状态信息(同步)
- Unity
- Unreal Engine
string loggedIn = INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "getUuidLoginStatus", "");
FString loggedIn = UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "getUuidLoginStatus", "");
当前 UUID 登录数据删除功能
- Unity
- Unreal Engine
INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "resetUuid", "");
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "resetUuid", "");
更新 SeSession 功能
- Unity
- Unreal Engine
INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "updateSeSession", "");
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelSquareEnix, "updateSeSession", "");
返回结果示例:
{
"OpenId": "xxxxxxxxxxxxxxx",
"Token": "xxxxxxxxxxxxxxx",
"TokenExpire": 1641649788,
"FirstLogin": 0,
"UserName": "",
"Gender": 0,
"Birthdate": "",
"PictureUrl": "",
"Pf": "xxxxxxxxxxxxxxx",
"PfKey": "xxxxxxxxxxxxxxx",
"NeedRealNameAuth": false,
"ChannelID": 32,
"Channel": "SquareEnix",
"ChannelInfo": {
"expire_ts": 1641649788,
"se_sessionid": "xxxxxxxxxxxxxxx",
"is_refresh": 1
},
"ConfirmCode": "",
"BindList": "",
"MethodId": 101,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 0,
"ThirdMsg": "user is logged in.",
"ExtraJson": {}
}
/*
Refreshing the session interface follows the same process as automatic login.
The is_refresh in ChannelInfo is 1, which means that the refresh session interface returns,
and se_sessionid is the corresponding updated session ID.
*/