Login
Unity3D
Outline
Access Guide
Apple login
Universal Link
Detect Universal Link
Authorized login
Guest login
Scan-code login
WeChat video channel authorization
Account inconsistency handling
Get login record
Real name
Third-party platform login
Logout
FAQ
Android
Outline
Access Guide
Authorized login
Scan-code login
WeChat video channel authorization
Account inconsistency handling
Get login record
Real name
Third-party platform login
Logout
FAQ
IOS
Outline
Access Guide
Apple login
Universal Link
Detect Universal Link
Authorized login
Guest login
Scan-code login
WeChat video channel authorization
Account inconsistency handling
Get login record
Real name
Third-party platform login
Logout
FAQ
Others
Data Structure
System Tools
Login / Android / Outline

Outline

MSDK login function is the fastest way for players to login the game: players can use QQ account, WeChat account and guest account(ios provides visitor model. Since Android does not provide visitor model, the game will handle the visitor model on its own as per requirement) to login your game; the function can be used for Android mobile phones and tablet devices.

You can refer to the following diagram to place the login button on the game's login page.

Function 1 QQ login

You can call MSDK interface to launch mobile QQ client to guide the player to grant authorization to the game. The general login workflow is as follows.

1) On the game's login page, click "Play with QQ friends"

2) On mobile QQ's login page, complete authorization

In which every area is described as follows:

Function 1.1:"Authorize login" button. With a Click on the button, you can complete login authorization for the game.

Function 1.2: The list of the user's permissions to authorize the game. It is needed to especially note if there is the "Access your QQ friends's information in app" item in the list. If not, error code "100030" will emerge when you get the user relation chain. It is needed to confirm to call WGPlatform.WGSetPermission (WGQZonePermissions.eOPEN_ALL); in Java code after MSDK is initialized.

Function 1.3: "Return" button. After the user clicks the button, the login will be cancelled, and the game receives login callback and flag is eFlag_QQ_UserCancel.

Function 1.4: "Switch account" button. When the user clicks the button, the user can switch mobile QQ account in mobile QQ and use the switched account to authorize the game.

3) Login succeeds. Return the page to select a zone server for the game or directly play the game

Function 1.5: The game's own "Enter the game" button, which has nothing to do with MSDK functions.

Function 1.6: The game's "Switch account" button. Call MSDK's logout interface, and then return to the game's login page.

Function 2 WeChat login

You can call MSDK interface to launch WeChat client to guide the player to grant authorization to the game. The general login workflow is as follows.

1) On the game's login page, click "Play with WeChat friends"

2) On WeChat login page, complete authorization

Function 2.1: "Authorize login" button. With a Click on the button, you can complete login authorization for the game.

Function 2.2: The list of the user's permissions to authorize the game, where the "Find friends who use the app with you together" items means that the user's relation chain can be gotten. This permission requires premium games to submit application to the collaboration & planning group to open it in the PR2 stage. For details, please consult with the game's person in contact with Tencent.

Function 2.3: "Cancel" button. After the user clicks the button, the login will be cancelled, and the game receives a login callback and flag is eFlag_WX_UserCancel.

Function 2.4: "Retry" button. The user clicks the button and can retry to authorize login in WeChat App.

WeChat scan-code login

On mobile phones or pad products, or TV products without the WeChat App, you are advised to call on the code scanning login interface to achieve better user experience, as detailed below: through another mobile phone that has logged into the WeChat account, use the WeChat’s QR code scanning function to scan the code for login.

MSDK login can create the following experience:

1)Quickly create a game login account MSDK login allows users to quickly and easily create a game login account within the game, without setting a password (which may be forgotten later). This simple and convenient experience can produce a higher user conversion rate.

2)Personalized game operation After logging in MSDK, you can be authorized to get the player's avatar and basic information to facilitate the operation of the game. This can produce a higher user retention rate.

3) Social function After logging in MSDK, the player can share messages among friends, establish the game guild group, etc., to promote the sharing of the in-game experience.

Access Guide

1 Preconditions

1) You have registered games on Tencent open platform and passed the audit, or your staff in contact with Tencent have helped you register games through internal channels.

2) You have completed access configuration by fthe instructions for accessing the configuration module.

3) Make sure that your game login permission has been opened. After the completion of the game registration, the permission has been opened by default. If you call the login interface, it returns "-303, no permission". At this time, please contact MSDK joint debugging support staff.

2 Refer to demos

For mobile QQ login examples, please refer to the login section of MSDKDemo/src/com/example/wegame/MainActivity.java .

For WeChat login examples, please refer to the login section of MSDKDemo/src/com/example/wegame/MainActivity.java .

3 Call this module's other interfaces

After completing Step1-Step2, you have access to this module and can directly call other interfaces of the module without any additional configuration. Every part of the module is described below.

1)Authorized login: Pull Mobile QQ/WeChat client authorization (if mobile QQ client is not installed, the system will remind the user to download qq client, and then mobile QQ back office will automatically handle the follow-up process)

2) Scan-code login: If the user device doesn’t have the WeChat App, the game permits login through code scanning, so as to authorize the account number that has logged into WeChat client in other devices.

3) Account inconsistency handling: mobile QQ/WeChat platform is required to be able to handle account inconsistency scenes where the platform and the game are logged in by the same user with different accounts.

4)Get token: Call this interface at the place where the game requires a token (such as payment) to get the current user's token information.

5) Logout: When the user needs to log off or switch account, he or she can call this interface to clear the user's login token information.

Authorized login

1 Summary

Pull Mobile QQ/WeChat client authorization (if mobile QQ client is not installed, the system will remind the user to download qq client, and then mobile QQ back office will automatically handle the follow-up process). After the user authorizes login, the platform will notify the game through WGPlatformObserver to get LoginRet login information.

2 Registration callback

1)Function description

In order to receive MSDK's login callback, you need to register the callback function for processing. The login result will be notified to you via the callback function.

2)Interface declaration
public static void WGSetObserver(WGPlatformObserver observer);
3)Parameter description
Parameter name Type Description
observer WGPlatformObserver class MSDK callback class, please refer to the demo code
4)Return value

None

5)Demo code
public class MsdkCallback implements WGPlatformObserver {
    public void OnLoginNotify(LoginRet ret) {
        Logger.d("called");
        Logger.d("ret.flag" + ret.flag);
        switch (ret.flag) {
            case CallbackFlag.eFlag_Succ:
                mainActivity.stopWaiting();
                // Login succeeds. Read all kinds of tokens
                String openId = ret.open_id;
                String pf = ret.pf;
                String pfKey = ret.pf_key;
                MainActivity.platform = ret.platform;
                String wxAccessToken = "";
                long wxAccessTokenExpire = 0;
                String wxRefreshToken = "";
                long wxRefreshTokenExpire = 0;
                for (TokenRet tr : ret.token) {
                    switch (tr.type) {
                        case TokenType.eToken_WX_Access:
                            wxAccessToken = tr.value;
                            wxAccessTokenExpire = tr.expiration;
                            break;
                        case TokenType.eToken_WX_Refresh:
                            wxRefreshToken = tr.value;
                            wxRefreshTokenExpire = tr.expiration;
                            break;
                        default:
                            break;
                    }
                }
                mainActivity.letUserLogin();
                break;
            // Game logic; handle the login failure situations, respectively
            case CallbackFlag.eFlag_NotInWhiteList:
                mainActivity.stopWaiting();
                mainActivity.letUserLogout();
                System.out.println("Not in the white list");
                break;
            case CallbackFlag.eFlag_Need_Realname_Auth:
                System.out.println("Require real name authentication");
                // TODO If the game is configured with  MSDK_REAL_NAME_AUTH_SWITCH=0 or 1, cancel the timeout processing for msdk here

                // TODO If the game is configured with MSDK_REAL_NAME_AUTH_SWITCH=2, call the game's self-defined real name authentication page here

                // imitate the user here to fill in the information on the game's self-defined real name authentication page and be ready to submit the info for registration
                if(mainActivity.isCustomUI()){
                    RealNameAuthInfo info = new RealNameAuthInfo();
                    info.name = "Zhang Xia";
                    info.identityType = eIDType.IDCards;
                    info.identityNum = "430455198411262142";
                    info.provinceID = 11;
                    WGPlatform.WGRealNameAuth(info);
                };
                break;
            case CallbackFlag.eFlag_Login_NetworkErr:
            case CallbackFlag.eFlag_WX_UserCancel:
            case CallbackFlag.eFlag_WX_NotInstall:
            case CallbackFlag.eFlag_WX_NotSupportApi:
            case CallbackFlag.eFlag_WX_LoginFail:
            case CallbackFlag.eFlag_QQ_LoginFail:
            case CallbackFlag.eFlag_Local_Invalid:
                Logger.d(ret.desc);
            default:
                // display the login page
                mainActivity.stopWaiting();
                mainActivity.letUserLogout();
                break;
        }
    }
}
6)Special description

V3.3.21 Version starts adding WeChat authorization scope field transmission capability in the authorized login callback, as follows:

In the authorized login callback OnLoginNotify, add WeChat authorization scope field transmission capability. The business side can determine whether the user has an authorized relationship permission based on this field; the scope field is in the extra_json of LoginRet, as shown as follows:

    The scope style of the relationship permission authorized by the user:
    loginRet.extra_json = "{\"scope\":\"snsapi_userinfo,snsapi_friend,snsapi_message\"}";

    The scope style of the relationship permission unauthorized by the user:
    loginRet.extra_json = "{\"scope\":\"snsapi_userinfo,snsapi_message\"}";

Warning:

1.The authorized login scope transmission is limited to WeChat platform, and QQ platform does not support it.

2.When the unauthorized login is made, the personal information and the friend relationship are in the authorization page by default. If a separate authorization page is required for the friend relationship:

  • The WeChat platform needs to apply to the WeChat (Enterprise WeChat wxgame) platform to open it.
  • The QQ platform currently no longer supports this feature's configuration. Please pay attention to subsequent platform version updates.
7)Name interpretation
name description support platform call interfaces
Authorized login through launching the platform's authorization page, the game guides the user to authorize the game to get the token required by login mobile QQ/WeChat WGLogin
Quick login The player's operation causes the platform to passthrough login-related token information when launching the game, thus logging into the game. mobile QQ None
Automatic login When logging in the game, the user does not need to specify any platform parameters and does not need to launch mobile QQ or WeChat but only uses local valid token for authorization. Mobile QQ/WeChat WGLogin (EPlatform.ePlatform_None)
automatic refresh MSDK will automatically handle WeChat bill refreshing MSDK provides functions None
account inconsistency the current login account within the game and the platform's login account are not consistent MSDK provides functions WGSwitchUser

ePlatform definition description

LoginRet definition description

QQ Hall login: QQ Hall login is a login mode that early chess and card games transferred tokens through the QQ Game Hall. Games not accessing the QQ Game Hall don't need to pay attention to it

Recommended login process

3 Call login

1)Function description

You can call the WGLogin interface to specify the platform to launch authorized login or automatic login. The call result will be notified by the callback function to you. The function declaration and the demo code are as follows:

2)Interface declaration
public static void WGLogin(EPlatform platform);
3)Parameter description
Parameter name Type Description
platform EPlatform enumeration The platform type that requires the game to have authorized login
4)Return value

None, login information will be returned to the game through  WGPlatformObserver callback

5)Demo code
WGPlatform.WGLogin (EPlatform.ePlatform_QQ); //QQ login
WGPlatform.WGLogin (EPlatform.ePlatform_Weixin); //WeChat login 
6)Special description

MSDK version 3.3.22 starts to support WeChat video number authorization, call the WGLogin interface, pass in ePlatform.ePlatform_WeixinVideoLive, and obtain tdiAuthBuffer in the callback of MSDK for subsequent live login.

Precautions for authorization of video number:

  • Video account live broadcast authorization currently only supports WeChat channel
  • In the login callback, tdiAuthBuffer exists in the _extra_json field and is returned in Base64 format. It can be obtained through Json parsing. Please use standard Base64 decoding before use
  • MSDK only returns the content of tdiAuthBuffer. For specific usage methods, contact MSDK Assistant for docking
7)Name interpretation

None

4 Call login (used by 3.0.8 and higher versions)

1)Function description

Have the function of preventing repeated clicks and preventing overtime. You can call WGLoginOpt interface to launch authorized login or automatic login for the specified platform. If the interface is called successfully, eFlag_Succ will be returned. eFlag_Logining is returned when you are logging in. The login result will be informed to you via the callback function. The function's declaration and the demo code for calling it are as follows:

2)Interface declaration
public static int WGLoginOpt(EPlatform platform, int overtime);
3)Parameter description
Parameter name Type Description
platform EPlatform enumeration The platform type that requires the game to have authorized login
Overtime int Login timeout; the timeout begins to be calculated from the moment the authorization comes back, in seconds
4)Return value

Return eFlag_Succ if successfully, and return eFlag_Logining if being logged in. The login information is returned to the game via WGPlatformObserver's callback

5)Demo code
int ret = WGPlatform.WGLogin (EPlatform.ePlatform_QQ,20); //QQ login
int ret = WGPlatform.WGLogin (EPlatform.ePlatform_Weixin,20); //WeChat login
6)Special description

None

7)Name interpretation

None

WeChat scan-code login

1)Function description

Launch the login QR code display interface. The player can scan QR code through another mobile phone which has logged on the WeChat/QQ corresponding social account. After authorization according to prompts, the game can get the login token information. This mode is generally used for TV or tablet environment, or mobile phones not installed with the platform client.

Remarks: 3.3.16 version starts to support the QR code scanning-based login for QQ.

2)Interface declaration
void WGQrCodeLogin(ePlatform platform);
3)Parameter description
Parameter name Type Description
platform EPlatform enumeration The platform type that requires the game to have authorized login
4)Return value

None, login information will be returned to the game through WGPlatformObserver callback

5)Demo code
WGPlatform::GetInstance()->WGQrCodeLogin((ePlatform)Platform);
6)Special description

For the scan-code login permission: non-premium games apply for it from WeChat via the game mail, and premium games can get it through the collaboration & planning group.

The drawn QR code image is valid for 5 minutes, and expired scan-code can't login successfully.

7)Name interpretation

None

WeChat video channel authorization (cross-platform)

1)Function description

MSDK encapsulates the video channel authorization interface. After invoking the WGChannelPermissionAuth interface, the current WeChat passes `snsapi_channels_livestream` to it and obtains `tdiAuthBuffer` in MSDK callback for subsequent livestreaming login. 3.3.26 Version starts adding this interface

2)Demo code

Please use the WGChannelPermissionAuth interface and set the parameters to `ePlatform.ePlatform_WeixinVideoLive` and `snsapi_channels_livestream`. The callback is received in the ChannelPermissionAuthEvent interface authorized by the video channel. Invocation example:


// ePlatform_WeixinVideoLive refers to WeChat Video Channel
// snsapi_channels_livestream is also a special mark permission

WGPlatform.Instance.WGChannelPermissionAuth(ePlatform.ePlatform_WeixinVideoLive, "snsapi_channels_livestream");

Callback example:


MsdkEvent.Instance.ChannelPermissionAuthEvent += (LoginRet ret) =>
{
    Debug.Log(ret.ToString());
    message = ret.ToString();
    switch (ret.flag)
    {
        case eFlag.eFlag_Succ:
            // Video channel authorization succeeds
            Debug.Log("Video channel authorization succeeds!");
            break;
        case eFlag.eFlag_WX_UserCancel:
            Debug.Log("Video channel authorization - Cancelled by the user!");
            break;
        case eFlag.eFlag_WX_UserDeny:
            Debug.Log("Video channel authorization - Rejected by the user!");
            break;
        default:
            // Video channel authorization fails
            Debug.Log("Video channel authorization fails!");
            break;
    }
};

Return result:


{
	"_flag": 0,
	"_desc": "",
	"_platform": 8,
	"_open_id": "",
	"_user_id": "",
	"_pf": "",
	"_pf_key": "",
	"_token": [],
	"_prajna_ext": "",
	"_extra_json": "{\"tdiAuthBase64\":\"Cp4BMV9CZ0FBYTRpb3RxYVA3aUgwQ1AzejkzRlZWY0Y4OG55NmZPZlZtaXh3ZUZNVHMwYVdJK0FF\\nVFpQR1c1SnpKbDdySWpnSnV6MEJRL2EyUXlQQlJWMG0xejNlTzRTR25ZN1VvSmt4N01idmxyemVp\\nOGNRU21lSnkxZGt6M0JubTFsNkgxZGJIMWVYRWNMMDdJa3dlYzJQMVZCUmhnPT0SF2lsaW5rYXBw\\nXzA2MDAwMDNiNzhjMTc2\\n\"}"
}
3)Warning
  • Video channel authorization currently only supports WeChat video channel
  • Currently pass in snsapi_channels_livestream; WeChat may change this in the future
  • In the login callback, `tdiAuthBuffer` exists in the `_extra_json` field and is returned in the format of Base64. It is obtained through Json parsing. Please use the standard Base64 to decode it before using it
  • This function does not limit the login channel and the login status, that is, the interface can be invoked across platforms
  • MSDK only returns the content of `tdiAuthBuffer`. As for its usage method, please contact MSDK Assistant for specific usage methods

Third-party platform launches login

MSDK 3.3.21 and above versions need to pay attention to this

In order to resist the Zuhao platform, MSDK 3.3.21 starts to block the quick login capability of the QQ Game Center during the startup of a game. The user will not be able to enter the game successfully from the QQ Game Center without logging into the game at first. Guidelines on the handling of account inconsistency scenes arising from the startup of games in the QQ Game Center (game evaluation processing)::

1) The game is not logged in: stay on the login page or call QQ login to initiate QQ authorization
2) The game is logged in:
    2.1) There is no account inconsistency: wait for the MSDK login callback; the user can enter the game if the user logs into it successfully
    2.2) There is account inconsistency:
        2.2.1) The user selects a local account: wait for the MSDK login callback; the user can enter the game if the user logs into it successfully
        2.2.2) The user chooses to initiate an account: return to the login page or call the QQ login to initiate the QQ authorization page

Warning:

The game which is updated to version 3.3.21 need to contact the QQ Game Center to cancel the accesstoken and paytoken fields carried in scheme when the game is started in the QQ Game Center to avoid affecting the login state of the logged-in user in the game.

1)Function description

Refer to that when the player clicks the sharing message in mobile QQ or WeChat to directly launch and enter the game, the platform will passthrough the login-related token information, thus directly finishing the login to enter the game. In this case, the game is launched and the user can enter the game without authorization any more

Mobile QQ Game Center's quick login configuration

When mobile QQ is clicked and started through the game center, you can directly quickly login the game. But when you enter the game through the game center's details page, this will depend on the game's configuration. The specific configuration method is that the game's operation & collaborative planning PM submits the demand to the mobile QQ game center and the game center's staff-in-charge will then complete the configuration. The configuration is as follows:

  • Support openID:

    Check openID, as shown below

    1

  • Support login with openID、accessToken、PayToken

1. Check the corresponding option

2. Fill in the corresponding versionCode of the version of the game supporting account inconsistency. After this, the code and the above versions can carry tokens to launch games, but earlier versions can only carry openID to launch a game. And this can't affect the game's normal logic.

![2](./res/diff-account-2.png)
  • Precautions

    In the configuration, it is generally only needed to configure the first three items and the latter items do not need to be configured.

2)Interface declaration

None

3)Parameter description

None

4)Return value

None, login information will be returned to the game through WGPlatformObserver callback

5)Demo code

The game needs to configure the following code in the lifecycle of its own main activity

public void onCreate(Bundle savedInstanceState) {
      ... 
      WGPlatform.handleCallback(getIntent());
      ...
}
public void onNewIntent(Intent intent) {
      ... 
      WGPlatform.handleCallback(intent);
      ...
}

Account inconsistency handling

1 General description

The user launches the game from the platform and enters it. Because the account is inconsistent (the platform is inconsistent or the platform is consistent but the account is inconsistent), it needs the game to pop up a box to prompt account inconsistency.As for the detailed description of account inconsistency, please refer toAccount inconsistency specification documentation

2 Registration callback

To receive the callback provided by MSDK for the launch of the game, you need to register WGPlatformObserver callback.

1)Function description

The information generated when the platform launches the game will be passed to the game via WGPlatformObserver.

2)Interface declaration
public static void WGSetObserver(WGPlatformObserver observer);
3)Parameter description
Parameter name Type Description
observer WGPlatformObserver class MSDK callback class, please refer to the demo code
4)Return value

None

5)Demo code
public class MsdkCallback implements WGPlatformObserver {
    public void OnWakeupNotify(WakeupRet ret) {
        Logger.d("called");
        Logger.d(ret.toString() + ":flag:" + ret.flag);
        Logger.d(ret.toString() + "desc:" + ret.desc);
        Logger.d(ret.toString() + "platform:" + ret.platform);
        MainActivity.platform = ret.platform;
        // TODO GAME The game needs to add the logic here to handle account inconsistency
        if (CallbackFlag.eFlag_Succ == ret.flag
                || CallbackFlag.eFlag_AccountRefresh == ret.flag) {
            //eFlag_AccountRefresh represents the success of refreshing WeChat token
            Logger.d("login success flag:" + ret.flag);
            mainActivity.letUserLogin();
        } else if (CallbackFlag.eFlag_UrlLogin == ret.flag) {
            // login the game with the launched account. The login result is called back in OnLoginNotify()
        } else if (ret.flag == CallbackFlag.eFlag_NeedSelectAccount) {
            // In case of account inconsistency, the game needs to pop up a prompt box to let the user select the account with which he needs to log in the game
            Logger.d("diff account");
            mainActivity.showDiffLogin();
        } else if (ret.flag == CallbackFlag.eFlag_NeedLogin) {
            // In case of no valid token, logout of the game to let the user re-login
            Logger.d("need login");
            mainActivity.letUserLogout();
        } else {
            Logger.d("logout");
            mainActivity.letUserLogout();
        }
    }
}
6)Special description

When eFlag.eFlag_NeedSelectAccount is received, this means that there is account inconsistency. At this time, the game needs to pop up a prompt box to let the user select the account that he wants to login and calls the WGSwitchUser interface according to the user's choice, and wait for the WGPlatformObserver callback to get the result of the account switch.

7)Name interpretation

ePlatform definition description

WakeupRet definition description

3 Switch account

1)Function description

When wakeupRet.flag, a flag used to judge if there is account inconsistency, is eFlag_NeedSelectAccount, the game needs to pop up a box to prompt the user to select the local account or the launched account to log in the game, and the game needs to call the interface WGSwitchUser to complete the user's login according to the user's choice.

2)Interface declaration
public static boolean WGSwitchUser(boolean switchToLaunchUser);
3)Parameter description
Parameter name Type Description
switchToLaunchUser bool true: switch to external account; false: continue to use the original account
4)Return value

true: indicate that this account has a token. MSDK will verify the validity of the token and return the verification result in WGPlatformObserver.

false: indicate that the account has no token or the token is invalid. The user can login the game directly, so that the user can re-authorize login.

5)Demo code
if(!WGPlatform.WGSwitchUser(true)){
    letUserLogout();
}
6)Special description

None

7)Name interpretation

None

Get token

1 General description

You can get the login callback token by parsing LoginRet in TokenRet in the login callback. In addition, you can call the following interface to get the current login token. LoginRet token contains the player's openid, pf and pfkey, TokenRet in LoginRet contains pay_token (unique for QQ login), access_token (unique for WeChat login) and other information. You will use such information when you make payment.

WeChat token is automatically refreshed

  1. Starting with MSDK 2.0.0, WeChat token will be verified and refreshed during the game running period. If the token needs to be refreshed, MSDK can automatically refresh it (the interval is 30 minutes) and notify the game of this through OnLoginNotify. "flag" of the versions before 3.0.0 is eFlag_WX_RefreshTokenSucc and eFlag_WX_RefreshTokenFail (already included in the callback of OnLoginNotify); since version 3.0.0, "flag" is eFlag_Succ (already included in the callback of OnLoginNotify)
  2. After the game receives a new token, it is needed to synchronously update the token held by the game client and the token held by the server, so as to ensure that the game can use the new token later to complete the subsequent process.
  3. Prior to MSDK 2.7.0a, if the game does not need the WeChat token automatic refresh function, you just need to set WXTOKEN_REFRESH tofalse in assets\msdkconfig.ini. At this time, the game requires the logic to personally handle the issue that WeChat token expires.
  4. On the basis of supporting the previous versions' login process, MSDK2.7.0a and later versions optimize the new process and refresh the token periodically. Be sure to set WXTOKEN_REFRESH in assets/msdkconfig.ini as follows: WXTOKEN_REFRESH=true or delete it (namely, turn on by default).

WeChat token refresh:

  • WeChat accessToken is only valid for twenty-four hours and refreshToken is valid for 30 days. accessToken can be refreshed with refreshToken as long as refreshToken is not expired. New accessToken and refreshToken will be gotten after refresh. If the game does not use the token automatic refresh interface provided by MSDK, it is needed to use WGRefreshWXToken() interface to renew accessToken.
  • This interface is called to refresh WeChat token when the game calls 'WGGetLoginRecordand the flag received by it is 'eFlag_WX_AccessTokenExpired. The refresh result will be called back to the game via OnLoginNotify callback. eFlag_WX_RefreshTokenSucc indicates to refresh the token successfully. eFlag_WX_RefreshTokenFail means to fail to refresh the token.

2 Registration callback

None

3 Call interfaces

1)Function description

Get the login's callback token

2)Interface declaration
public static int WGGetLoginRecord(LoginRet ret);
3)Parameter description
Parameter name Type Description
ret LoginRet Token information LoginRet
4)Return value

The platform id of the current login token

5)Demo code
LoginRet lr = new LoginRet();
WGPlatform.WGGetLoginRecord(lr);
6)Special description
  1. After a token is obtained through this interface, it is needed to judge LoginRet.flag. If the result is 0 (eFlag_Succ), the token is valid and can be used directly; if it is 5001 (eFlag_Checking_Token), this means that MSDK is verifying the token and the token is invalid. It is needed to try again later. The token obtained through this interface must be passed to the game server. The game server then calls MSDK’s token verification interface to verify if the token is valid. Only when the token is valid can the user enter the game.

  2. The interface can involve querying the local database. Very frequently calling it can hurt the performance, so the interface is not suitable for high-frequency calls. For example, unity games shall not call it frequently in update function

7)Name interpretation

LoginRetDefinition description

Real name

In accordance with the relevant provisions of "Interim Measures for Management of Online Games" issued by the Chinese Ministry of Culture, online game users need to use a valid identity document to make real name registration before they can login any game. In order to reduce the burden of game developers, we have customized the real-name authentication UI and the entire interfaces for games. Through the module, you only need to spend a few minutes to complete the real-name authentication function.

As for the detailed description of the real-name system, please refer to Real name system specification documentation

Logout

1 General description

You can call WGLogout interface to logout and clear the local token

2 Registration callback

None

3 Call interfaces

1)Function description

Get the login's callback token

2)Interface declaration
public static boolean WGLogout();
3)Parameter description

None

4)Return value

Return true. You do not need to process the return value

5)Demo code
WGPlatform.WGLogout();
6)Special description

None

7)Name interpretation

None

MSDK token automatic refresh process

On the basis of supporting the previous versions' login process, MSDK2.6.0i and later versions optimize the new process. The business only needs to pay attention to the two interfaces, that is WGLogin andWGGetLoginRecord, to complete the login and token processing procedures.

  • Call logic in case that the game uses automatic login:

Start the game, directly call WGLogin() interface, and wait for OnLoginNotify() callback. The process is as follows:

  • Call logic in case that the game needs the login token:

Call WGGetLoginRecord() interface; when the return value is flag = 5001, this indicates that the validity of the token is being verified inside MSDK. A few seconds later, you may try again to obtain the token. The process is as follows:

  • MSDK's internal token verification and refresh logic:     

FAQ

Is it needed to check the token when the frontend and backend of the game switch?

The game does not need to check the validity of the token when switching between the frontend and the backed. If the backend in the game lasts too long and then switches to the frontend, MSDK will automatically verify the validity of the token.

Steps for checking the reasons why Android WeChat can't be logged in

Step 1: Check whether there is the following sentence in Log

lauchWXPlatForm wx SendReqRet: true

If there is this sentence in Log, this indicates that the request has been successfully sent to WeChat

If WeChat client can't be launched, please check Step 2, If WeChat client is pulled up, but no callback, check Step 3

Step 2: Check the signature and the package name

Download https://res.wx.qq.com/open/zh_CN/htmledition/res/dev/download/sdk/Gen_Signature_Android2.apk, install this apk into the mobile phone, enter the package name of the game in the input box and click the button to read the game package's signature.

Check the signature

Check whether the signature obtained by the above tool is consistent with the signature of WeChat backend configuration (WeChat background configuration signature information query, please RTX contact MSDK)

Step 3: Check the location where WXEntryActivity.java is placed(this file is in MSDKSample)

This file must be placed under the game+.wxapi. For example, if the package name of the game is: com.tencent.msdkgame, WXEntryActivity.java should be placed under com.tencent.msdkgame.wxapi. At the same time, check if the content of WXEntryActivity is consistent with the following content

/**
 * !!Users can't modify the code logic part of the file. Starting from MSDK 1.7, the parent class name is changed from WXEntryActivity to BaseWXEntryActivity. If this file fails to work correctly, please check this item at first
 */
public class WXEntryActivity extends com.tencent.msdk.weixin.BaseWXEntryActivity { }

If this step has no problem, please see the fourth step

Step 4: Check handleCallback

Check if WGPlatform.handleCallback is called in onCreate and onNewIntent of the game's Launch Activity.

Step 5: Check if the game's global Observer is set correctly

Check if the game calls WGSetObserver correctly (C++ layer and Java layer).

If mobile QQ is not installed, the game is logged in via Web QQ, but the game crashes soon later. How to solve this problem?