Skip to main content

Android

This article aims to introduce how to set up WeChat authentication, allowing your game to use Player Network login authentication service to log in via the WeChat channel.

Prerequisites

1. Set up your game on the WeChat Open Platform
1. Create WeChat application

Register an account on the WeChat Open Platform, and create a mobile application in Management Center following the prompts.

Image: Open Platform of WeChat (1)

2. Obtain application information
  1. Log in to the WeChat Open Platform.

  2. In the top navigation bar, click Management Center.

  3. On the Mobile Applications tab, click View in the Actions column of the corresponding app.

    Image: Open Platform of WeChat (2)

  4. On the application details page, check AppID and AppSecret.

    Image: Open Platform of WeChat (3)

3. Apply for business permission to obtain AppName

When configuring a single WeChat channel, AppName is optional.If you plan to add multiple WeChat channels, AppName is required; you must complete the following application process to obtain the AppName:

note

The application requires Tencent internal permissions. If your team does not have Tencent internal members, you may contact the Player Network representative for assistance with the application.

  1. Log in to the WeChat Open Platform internal interface management system.

  2. Refer to the application guide to fill in the application form, ensuring all information is accurate. Image: Open Platform of WeChat (4)

  3. Submit the application and patiently await approval.

  4. After approval, please accurately fill in the Business Name from the application form to the AppName field in the Player Network Console to complete the configuration.

  1. Obtain Player Network Console login account.
  2. Create a new project for your game, or join an existing one.
  3. Download SDK.
  4. Integrate the SDK.
  5. Add WeChat as a login authentication method in Player Network Console.

Step 1: Configure SDK for WeChat login

  1. Open your project's INTLConfig.ini file:

    INTLConfig.ini
    [INTL environment]
    # WARNING: You should change this URL to the production environment when you release your game.
    INTL_URL = https://test.intlgame.com
    GAME_ID = {INTL_GAME_ID}
    SDK_KEY = {INTL_SDK_KEY}
    [INTL Log]
    LOG_LEVEL = 1
    LOG_CONSOLE_OUTPUT_ENABLE = 1
    LOG_FILE_OUTPUT_ENABLE = 1
    LOG_ENCRYPT_ENABLE = 0
    LOG_COMPRESS_ENABLE = 0

    [Android LifeCycle]
    LIFECYCLE = WeChat
    [WeChat]
    WECHAT_APP_ID = {INTL_WECHAT_APP_ID}
    • Set the SDK backend environment to INTL_URL = https://test.intlgame.com.
    • Replace {INTL_GAME_ID} and {INTL_SDK_KEY} with the GAME_ID and SDK_KEY values assigned by the Player Network Console.
    • Set LOG_LEVEL = 1, LOG_CONSOLE_OUTPUT_ENABLE = 1, LOG_FILE_OUTPUT_ENABLE = 1, LOG_ENCRYPT_ENABLE = 0 and LOG_COMPRESS_ENABLE = 0 to output console logs and log files without encrypting or compressing the output without encrypting or compressing the output.
    • Add WeChat in LIFECYCLE.For more information, please see SDK Environment.
    • Replace {INTL_WECHAT_APP_ID} with the AppID assigned by WeChat.

Step 2: Add WeChat login

Pass in the permissions when calling INTLAPI.Login.Known permission list for WeChat iOS/Android is as follows (the official documentation does not explicitly specify permissions):

PermissionsDescription
snsapi_userinfoObtain user information (default permission for Player Network SDK)
snsapi_friendObtain friend list
snsapi_messageSend message
  1. Register login-related callbacks.
// 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";
}
}
  1. Call the AutoLogin interface to log in automatically.
INTLAPI.AutoLogin();
  1. If automatic login fails, call the Login interface to let the player log in manually.
INTLAPI.Login(INTLChannel.WeChat, "", "");
  1. Synchronize client authentication status with the game backend and wait for the final verification result.

Scan code login

Player Network SDK V1.26.00 supports WeChat QR code login on Android and iOS platforms starting from this version.

By default, if the phone has the WeChat app installed, it will directly launch the WeChat app for login; if WeChat app is not installed, it will automatically switch to QR code login.If you need to modify the default behavior, you can specify the qrcode_mode parameter in extraJson:

qrcode_modeExplanation
autoAuto mode (default):
Prioritizes logging in via WeChat app; uses QR code login when the WeChat app is not installed.
force_appForce WeChat app login:
If the WeChat app is not installed, login will result in an error.
force_qrcodeForce QR code login:
No matter whether the WeChat app is installed or not, login will always use QR code.
string permissions = "";
string extraJson = "{\"qrcode_mode\" : \"force_qrcode\"}";
INTLAPI.Login(INTLChannel.WeChat, permissions, extraJson);

Step 3: Acceptance testing for login functionality

Search for the keyword "AuthResult" in the Player Network SDK logs to confirm whether the channel name and OpenID are returned correctly.If correct, it means the integration configuration is successful, and login functionality has been successfully added.

If you encounter problems during the integration process, please refer to Frequently Asked Questions.