跳到主要内容

iOS

本文旨在介绍如何设置 Square Enix 身份验证,让您的游戏可以使用 Player Network 登录鉴权服务通过 Square Enix 渠道登录。

前提条件

1. 设置 Square Enix 应用

联系 Square Enix 团队激活您的应用程序,从 Square Enix Bridge 获取 タイトルID(SE Game ID)、Consumer KeyConsumer Secret

获取应用程序信息

图片:SquareEnix SE 1

图片:SquareEnix SE 2

图片:SquareEnix SE 3

图片:SquareEnix SE 4

  1. 获取 Player Network 控制台登录账号
  2. 为游戏创建新项目,或加入已有项目
  3. 下载 SDK
  4. 接入 SDK
  5. 在 Player Network 控制台添加 Square Enix 为业务的登录鉴权方式

步骤1:为 SquareEnix 登录配置 SDK

打开项目的 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}` 替换为游戏团队提交的应用程序的 SquareEnix 应用程序 ID。
- 将 `{INTL_SQUARE_ENIX_CONSUMER_KEY}` 替换为游戏团队提交的应用程序的 SquareEnix 消费者密钥。
- 将 `{INTL_SQUARE_ENIX_CONSUMER_SECRET}` 替换为游戏团队提交的应用程序的 SquareEnix 消费者密匙。
- `SQUARE_ENIX_TEST`:用于确定是否为 SquareEnix 测试环境; 0:正式环境,1:测试环境; 默认为 0。

步骤2:添加 SquareEnix 登录

首次调用登录 API 时,会自动调用 people.create API 进行注册。
更多信息,请参见 Square Enix Bridge Developer Center 内的 注册登录 文档。

  1. 注册登录相关回调。

    // 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";
    }
    }
  2. 调用 AutoLogin 接口自动登录。

    INTLAPI.AutoLogin();
  3. 在自动登录失败时调用 Login 接口使玩家手动登录。

    INTLAPI.Login(INTLChannel.SquareEnix, "", "");

注销功能

注意

目前,注销功能只退出登录状态,并不清除 UUID。游戏需要使用 resetUuid来清除 UUID。

INTLAPI.Logout(INTLChannel.SquareEnix);

步骤3:验收登录功能

INTLAPI.Login(INTLChannel.SquareEnix, "", "{\"se_login_only\":true}");
  • 如果登录成功,返回的结果与正常登录结果相同。
  • 如果登录不成功,请查看具体的错误代码和错误信息:RetCodeRetMsgThirdCodeThirdMsg`。

返回结果示例(成功):

{
"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": {}
}
说明

如果设备在成功登录后被其他设备重定向,并执行登录或自动登录过程,则将返回一个 ThirdCode1276 的错误代码,表示当前登录状态无效。

这种情况下的登录必须使用以下方法:

INTLAPI.Login(INTLChannel.SquareEnix, "", "{\"se_register\":true}");

其他功能

绑定功能

INTLAPI::ExtendInvoke(INTLChannel.SquareEnix, "bind", "");

有关绑定过程的更多信息,请参见 Binding Docs

证书转移功能

INTLAPI::ExtendInvoke(INTLChannel.SquareEnix, "takeover", "");

有关证书转移过程的更多信息,请参见 证书转移文档

用户信息采集功能

INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "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 获取功能

INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "getSeUserId", "");

返回结果示例:

{
"Channel": "SquareEnix",
"ExtendMethodName": "getNativeUserID",
"MethodId": 1301,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 1,
"ThirdMsg": "",
"ExtraJson": {
"se_user_id": 18235236
}
}
// Parse "se_user_id"

服务器创建功能

string extraJson =  "{\"world_id\":\"@self\"}";
INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "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 获取功能

INTLAPI.ExtendInvoke(INTLChannel.SquareEnix,"getSeNativeSessionId", "");

返回结果示例:

{
"Channel": "SquareEnix",
"ExtendMethodName": "getCachedNativeSessionId",
"MethodId": 1301,
"RetCode": 0,
"RetMsg": "Success",
"ThirdCode": 1,
"ThirdMsg": "",
"ExtraJson": {
"se_session_id": "034991a20e2f150577be4f93b8d471a1"
}
}
// Parse "se_session_id"

获取当前 UUID(同步)

string uuid = INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "getCurrentUuid", "");

获取 UUID 早期登录状态信息(同步)

string loggedIn = INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "getUuidLoginStatus", "");

当前 UUID 登录数据删除功能

INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "resetUuid", "");

更新 SeSession 功能

INTLAPI.ExtendInvoke(INTLChannel.SquareEnix, "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.
*/