05/15/2024 15:19:45

WeChat Channel Function Description

Developers who use Xcode13.0 and above versions to compile App need to refer to 3.5 Instructions about adaptation to WeChat OpenSDK iOS15 System to adapt to WeChat OpenSDK to ensure the normal use of WeChat OpenSDK.

I. Android Project Configuration

I. Android Project Configuration

1.1 Permission Configuration

In the root node of AndroidManifest.xml, add permission

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android: name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android: name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- [optional]for mta statistics -->
<uses-permission android: name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android: name="android.permission.READ_PHONE_STATE"/>
<uses-permission android: name="android.permission.ACCESS_NETWORK_STATE"/>

1.2 Entry Activity Configuration

In AndroidManifest.xml, add the following configuration

Under Android Studio environment, {applicationId} doesn't need to be manually changed to package name

Under Unity, UnrealEngine, Cocos2D and other environments, it is needed to manually change {applicationId} to package name

<activity
    android: name="com.tencent.gcloud.msdk.WeChatAgentActivity"
    android: exported="true"
    android: launchMode="singleTask"
    android: configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android: theme="@android: style/Theme.Translucent.NoTitleBar"/>

<activity-alias
    android: name="${applicationId}.wxapi.WXEntryActivity"
    android: enabled="true"
    android:exported="true"
    android: launchMode="singleTask"
    android: excludeFromRecents="true"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android: targetActivity="com.tencent.gcloud.msdk.WeChatAgentActivity"/>

<activity
    android: name="com.tencent.gcloud.msdk.qrcode.WXQrCodeActivity"
    android:excludeFromRecents="true"
    android:exported="true"
    android: label="WXQrCodeActivity"
    android:launchMode="singleTask"
    android: taskAffinity="com.tencent.gcloud.msdk.qrcode.diff"
    android: configChanges="orientation|screenSize|keyboardHidden"
    android: theme="@android: style/Theme.Light.NoTitleBar"
    android: screenOrientation="portrait">
</activity>

1.3 App ID Configuration

In the project's assets/MSDKConfig.ini file, add the following configuration

WECHAT_APP_ID = {YOUR_WECHAT_APP_ID}

[info] Replace {YOUR_WECHAT_APP_ID} with APP_ID applied for by the app

III. iOSProject Configuration

II. iOS Project Configuration

2.1 MSDKConfig Configuration File

In the project, find MSDKAppSetting.bundle/MSDKConfig.ini file, and add the following configuration

WECHAT_APP_ID = {YOUR_WECHAT_APP_ID}

[info] Replace {YOUR_WECHAT_APP_ID} with APP_ID applied for by the app

2.2 Xcode Project Configuration File info.plist

Find or create the following nodes:

 <key>CFBundleURLTypes</key>
     <array>
     <dict>
         <key>CFBundleURLSchemes</key>
         <array>
             <string>{your wechat app id}</string>
         </array>
     </dict>
 </array>
 <key>LSApplicationQueriesSchemes</key>
 <array>
     <string>wechat</string>
     <string>weixin</string>
     <string>weixinURLParamsAPI</string> 
 </array>
 <key>NSAppTransportSecurity</key>
     <dict>
     <key>NSAllowsArbitraryLoads</key>
     <true/>
 </dict>

Where, {your wechat app id} needs to be modified into WeChat App ID applied for by the game. In addition, it is recommended that the above LSApplicationQueriesSchemes be configured within the top 50. For details, please refer to iOS Developer Documentation

2.3 Unity XUPoter's xx.projmods File's Configuration

When Unity exports XCode project, it needs to configure projmods file, so as to make the exported XCode project get the configuration of 2.2

{
    "group": "MSDKWeChat", 
    "libs": [],
    "frameworks": [],
    "files": [],
    "folders": [],
    "excludes": [],
    "headerpaths":[],
    "build_settings": {},
    "system_capabilities": {},
    "Info.plist":{
        "LSApplicationQueriesSchemes":
        [
            "weixin",
            "wechat"
        ],
        "CFBundleURLTypes" :
        [
            {
                "CFBundleTypeRole":"Editor",
                "CFBundleURLSchemes":["{WX_APPID}"]
            }
        ]
    }, 
}

Where, {WX_APPID} needs to be modified into WeChat AppID applied for by the game

Please refer to the description of Universal Link for details

III. Function Description

III. Function Description

3.1 Login Function

Use WeChat's authorization login. For details, please refer to Login Module

When calling MSDKLogin.Login, pass in permission. The known permission list of WeChat iOS/Android is shown as follows (the official documentation has no specific permission description):

Permission Description
snsapi_userinfo Get user data (MSDK default permission)
snsapi_friend Get friend list
snsapi_message Send message. Deprecated since V5.25

Login with WeChat QR Code
Judge whether WeChat App is installed. If WeChat APP is not installed, you can use the QR code login function, invoke MSDKLogin.Login to add QRCode configuration in the extraJson and then open the QR code login UI.

3.2 Friend Function

Send message to WeChat friends, and share images or videos to Wechat Moment. For details, please refer to Friend Module

Sharing videos to WeChat Moment requires WeChat version to be 6.5.8 or higher; WeChat 6.7.2 starts to cancel the callback of sharing cancellation or failure. No matter whether the sharing is successful, failed or cancelled, WeChat will return "Success", so as to prevent the game from inducing too much sharing, The specific performance depends on WeChat's strategy;

3.2.1 Sending function support type

No. Function Required field
0 Send text - pop-up box type, desc (description)
1 Send link - pop-up box type, link
2 Send image - pop-up box type, imagePath (image address)
3 Send music - pop-up box type, link
4 app invitation - pop-up box type
5 Send miniApp - pop-up box type, link, extraJson (in extended fields, it is needed to carry information with a key as weapp_id)
6 Launch miniApp - pop-up box type, link, extraJson (in extended fields, it is needed to carry information with a key as weapp_id)
7 Launch business - pop-up box type, extraJson (in extended fields, it is needed to carry information with a key as business_type)
8 Send message to WeChat Video Channel - popup box type (type), mediaPath (multimedia address)
9 Send message to WeChat state type (type), title (title), imagePath (image address), link (link), extraJson (in the extended field; the information carrying a key of stateId is needed)

3.2.2 share function support type

No. Function Required field
0 Share text - pop-up box type, desc (description)
1 Share link - pop-up box type, link
2 Share image - pop-up box type, imagePath (image address)
3 Share music - pop-up box type, link, imagePath (image address)
4 Share video - pop-up box type, mediaPath ( multimedia address)
5 Share images to WeChat Game Circle type, imagePath (image address)

[info] Precaution

  1. Other send/share types are not supported
  2. Other fields that are not commonly used are all written into the field extraJson, as shown as follows
MSDKFriendReqInfo reqInfo = new MSDKFriendReqInfo();
reqInfo.extraJson = "{\"media_tag_name\": \"MSG_INVITE\", \"message_action\": \"WECHAT_SNS_JUMP_URL\", \"message_ext\": \"12345\", \"weapp_id\": \"wx4a0a73ec028e47d7\"}";

Where, the gameextra field is the field appended to URL when opening the connection of the WeChat Game Circle. For example, the above extraJson will append &gameextra=shareWXGameLinePic to URL.

3.3 Group Functions

WeChat group functions include: create a group, join the existing group, get group state, get group relations, unbind a group, and send group messages

For details, please refer to Group Module

[info] The union information on the WeChat side can be created and filled in by yourself. UnionID should be kept in mind, because it is the unique identifier of the function of the subsequent module.
Special note: WeChat can only create one WeChat group within 24 hours

3.4 WeChat launches a game

Launch a game from WeChat. Currently, such launch includes the following two types of launch

  • The user clicks on the invitation message to launch the game

  • The game is launched from the Game Center

For both types of launches, MSDK can respond to them and pass the parameters from WeChat to the 'params' field of extraJson, and the game can get the field from it.

The format of the passed data is as follows:

{
    "extraJson":"{\"params\":\"{\\\"_wxappextendobject_extInfo\\\":\\\"MSDK\\\",\\\"_wxapi_basereq_transaction\\\":\\\"da5119749b8f66db36cb9ca6002e7ef0\\\",\\\"_wxobject_sdkVer\\\":620954368,\\\"_wxobject_description\\\":\\\"\\\",\\\"_mmessage_appPackage\\\":\\\"com.tencent.mm\\\",\\\"THIRD_REQ_RESULT\\\":0,\\\"openid\\\":\\\"oHlap1URnIobL4489JUYTXH9_PJ4\\\",\\\"_wxobject_message_ext\\\":\\\"iTOP\\\",\\\"_wxapi_command_type\\\":4,\\\"_wxobject_title\\\":\\\"sendMessage10003\\\",\\\"_wxapi_basereq_openid\\\":\\\"oHlap1URnIobL4489JUYTXH9_PJ4\\\",\\\"_mmessage_checksum\\\":\\\"B@282cb08\\\",\\\"wx_token_key\\\":\\\"com.tencent.mm.openapi.token\\\",\\\"_mmessage_sdkVersion\\\":620954368,\\\"_wxapi_showmessage_req_country\\\":\\\"CN\\\",\\\"_wxobject_identifier_\\\":\\\"com.tencent.mm.sdk.openapi.WXAppExtendObject\\\",\\\"platform\\\":\\\"WeChat\\\",\\\"_wxapi_showmessage_req_lang\\\":\\\"zh_CN\\\",\\\"platformId\\\":\\\"wechat\\\"}\",\"game_data\":\"MSDK\"}",
    "methodNameID":119,
    "retCode":0,
    "retMsg":"Success",
    "ret":-1,
    "msg":""
}

Note: The corresponding names and contents of the parameters in the 'params' field in extraJson are passed by WeChat. The 'game_data' field in extraJson brings back the original invitation content filled when the game player sends an invitation to friends. If the game is launched by the Game Center, the field will be parsed accordingly.

game_data field's transparent transmission

var reqInfo = new MSDKFriendReqInfo ();
reqInfo.Link = "http://www.qq.com";
reqInfo.ExtraJson = "{\"game_data\":\"iOS Game Data\"}";

The game launches WeChat-app through the invitation message delivery interface to send messages to WeChat friends. When a WeChat friend of the user clicks on the message, the link will jump back to the game

The game_data field added to ExtraJson in MSDKFriendReqInfo when the message is sent will be transparently transmitted to the game when the message is clicked to launch the game. The returned data is in game_data in ExtraJson of MSDKBaseRet.

{
  "methodNameID": 0,
  "channelID": 1,
  "channel": "WeChat",
  "pluginData": "",
  "channelOpenID": "oHlap1Q1mqIQLpAqsuwty635gH0U",
  "seqID": "11-2B4C94EE-0CC8-4433-A313-1678F57272FA-1585295116-47",
  "extraJson": {
    "params": {
      "language": "zh_CN",
      "openId": "oHlap1Q1mqIQLpAqsuwty635gH0U",
      "mediaTagName": "",
      "country": "CN",
      "messageExt": "iOS Game Data"
    },
    "game_data": "iOS Game Data"
  }
}

3.5 Instructions about the adaptation of WeChat OpenSDK For iOS15

App compiled by Xcode13.0 and above versions is limited to have the number of URL Scheme queries at 50 in iOS15.0 and above systems. For App with more than 50 schemes configured by LSApplicationQueriesSchemes in plist, the following problem may occur. Developers who use Xcode version 13.0 and above versions to compile App need to adapt to WeChat OpenSDK to ensure the normal use of WeChat OpenSDK.

  • Some interfaces of WeChat OpenSDK return wrong results;
  • Unable to use Universal Link to initiate WeChat. After the message is shared to WeChat, the application name was added with "Unverified Application".

1) Background

Starting from iOS9, iOS supports configuring LSApplicationQueriesSchemes in the project's plist.

After configuring the scheme of other apps in LSApplicationQueriesScheme, you can use the following code to judge whether to skip to the corresponding App through scheme.

BOOL ret = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @"weixin: //"]];

When accessing WeChat OpenSDK, WeChat Official-Access Documentation requires adding "weixin" and "weixinULAPI" to LSApplicationQueriesScheme (as shown above) Shown).

2) iOS15 system related changes

WeChat confirms with Apple that the number of LSApplicationQueriesSchemes for Apps compiled with Xcode13 on the iOS15 system will be limited to 50. The scheme configuration after the 50th scheme will not take effect, and the following code will return NO.

BOOL ret = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @"
otherAppScheme: //"]];

3) Suggestions about adaptation to WeChat OpenSDK

If the number of schemes configured by LSApplicationQueriesSchemes is less than 50 or the two schemes "weixin" and "weixinULAPI" are in the top 50, it is not needed to adapt to WeChat OpenSDK. Apps compiled with Xcode12 and below versions do not currently need to adapt to WeChat OpenSDK.

The accessing party needs to ensure that "weixin" and "weixinULAPI" are configured in the top 50 of LSApplicationQueriesSchemes. Otherwise, the following interface may return incorrect results or behave abnormally in the iOS15 system:

  1. [WXApi isWXAppInstalled]: If WeChat is installed, it also returns NO;
  2. [WXApi isWXAppSupportApi]: If it is supported, it also returns NO;
  3. [WXApi isWXAppSupportStateAPI]: If it is supported, it also returns NO;
  4. [WXApi sendAuthReq: viewController: delegatecompletion]: It will judge that WeChat is not installed, and then initiate webpage authorization.

All interfaces cannot use Universal Link to initiate WeChat, and have to downgrade to use scheme to initiate WeChat, leading to the "Unverified Application" problem.

IV.FAQs

IV.FAQs

4.1 WeChat can be launched, but authorization return has no callback

  • Check if MSDK.Init has been initialized
  • Check if the callback has been configured
  • For Android, check if you have modified configuration in AndroidManifest.xml to change {applicationId} in android: name="${applicationId}.wxapi.WXEntryActivity" into your app's own package name
  • For iOS, check if you add configuration in info.plist

4.2 Video can't be shared

  • Videos have format restrictions

4.3 Android WeChat fails to share images to Session/Wechat Moment

  • Error stack example
    2020-03-10 11:05:28.079 20294-20294/? E/Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory

    java.lang.Throwable
          at android.app.Instrumentation.getFactory(Instrumentation.java:1233)
          at android.app.Instrumentation.newActivity(Instrumentation.java:1224)
          at com.tencent.mm.splash.k.newActivity(SourceFile:61)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3340)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
          at android.os.Handler.dispatchMessage(Handler.java:112)
          at android.os.Looper.loop(Looper.java:216)
          at android.app.ActivityThread.main(ActivityThread.java:7625)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
    
  • Check whether WeChat code obfuscation is added to the 'proguard-project.txt' file in the WeChat plugin directory. If not, please add the following code obfuscation rule:

  -keep class com.tencent.mm.opensdk.** {*;}
  -keep class com.tencent.wxop.** {*;}
  -keep class com.tencent.mm.sdk.** {*;}

4.4 gradle packaging error: Could not find com.tencent.mm.opensdk: wechat-sdk-android-without-mta: x.x.xx.

Need to add warehouse: mavenCentral ().



Copyright © 2024 MSDK.
All rights reserved.

results matching ""

    No results matching ""