Skip to main content

iOS

This document introduces how to set up WeChat authentication, allowing your game to use Player Network's login authentication service to sign in via the WeChat channel.

Prerequisites

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

Register an account on the WeChat Open Platform and follow the instructions in the Management Center to create a mobile application.

Image: Open Platform of WeChat (1)

2. Obtain Application Information
  1. Log in to the WeChat Open Platform.

  2. Click Management Center in the top navigation bar.

  3. In the Mobile Applications tab, under the Actions column for the relevant application, click View.

    Image: Open Platform of WeChat (2)

  4. On the application details page, check the 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 planning to add multiple WeChat channels, AppName is required. Please complete the following application process to obtain AppName:

note

The application requires internal Tencent permissions. If no one on your team has Tencent internal access, please contact your Player Network liaison for assistance.

  1. Log in to the WeChat Open Platform Internal Interface Management System.

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

  3. Submit the application and wait patiently for approval.

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

  1. Obtain a Player Network Console login account.
  2. Create a new project for the game, or join an existing project.
  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 [WeChat Channel] WECHAT_APAPPORT_ENABLE = 1 LOG_ENCRYPT_ENABLE = 0 LOG_COMPRESS_ENABLE = 0 0
    [WeChat Channel]
    WECHAT_APP_ID = {INTL_WECHAT_APP_ID}
    WECHAT_UNIVERSAL_LINK_IOS = {WECHAT_UNIVERSAL_LINK_IOS}
    • Set the SDK backend environment to INTL_URL = https://test.intlgame.com.
    • Replace {INTL_GAME_ID} and {INTL_SDK_KEY} with the values for GAME_ID and SDK_KEY 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.
    • Replace {INTL_WECHAT_APP_ID} with the AppID assigned by WeChat.
    • Replace {WECHAT_UNIVERSAL_LINK_IOS} with the UNIVERSAL_LINK set on the WeChat Open Platform.
  2. Add WeChat configuration.

Open INTLCoreKit.projmods and replace {INTL_WECHAT_APP_ID} with the WeChat AppID before exporting the Xcode project from Unity.

{
"group": "INTL",
"libs": [

],
"frameworks": [

],
"files": [
],
"folders": [],
"excludes": [
"^.*.meta$",
"^.*.mdown$",
"^.*.pdf$"
],
"headerpaths":[],
"build_settings":
{
"OTHER_LDFLAGS": ["-ObjC"],
"ENABLE_BITCODE": "NO"
},
"system_capabilities": {
},
"Info.plist":{
"LSApplicationQueriesSchemes":
[
"weixin",
"weixinULAPI"
],
"NSAppTransportSecurity":
{
"NSAllowsArbitraryLoads": true
},
"CFBundleURLTypes" :
[
{
"CFBundleTypeRole":"Editor",
"CFBundleURLName":"wechat",
"CFBundleURLSchemes":["{INTL_WECHAT_APP_ID}"]
}
]
}
}

Replace {INTL_WECHAT_APP_ID} with the WeChat App ID you applied for for your service.

Step 2: Add WeChat Login

Pass the permissions when calling INTLAPI.Login.The list of known WeChat iOS/Android permissions is as follows (the official documentation does not clearly specify permissions):

PermissionsDescription
snsapi_userinfoGet user info (Default permission for Player Network SDK)
snsapi_friendGet 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

Starting from Player Network SDK V1.26.00, WeChat QR code login is supported on Android and iOS platforms.

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

qrcode_modeExplanation
autoAuto mode (default):
Prefer using WeChat app for login. If the app is not installed, use QR code login.
force_appForce WeChat app login:
Login will return an error if the WeChat app is not installed.
force_qrcodeForce QR code login:
QR code login will be used regardless of whether the WeChat app is installed.
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 issues during integration, see FAQs.