— — — — — — — the android
Recommend using the React-native library, githup address: github.com/yorkie/reac… Login, share, Favorites (V1.9.9 +) and payment features, suitable for both iOS and Android platforms. 1. First of all, you need a verified wechat developer account. Wechat development platform to register an account and create a mobile application. (address :open.weixin.qq.com), note: When you create a mobile app, the signature below the Android app needs to be the same as the app you are testing, if you don’t know. You can download the signature generation tool on the official wechat development website to check the app’s signature.
2. Install and configure React-native wechat
NPM install NPM install react-native wechat --save // yarn install yarn add react-native wechatCopy the code
Add the following code to the Android /settings.gradle file:
include ':RCTWeChat'
project(':RCTWeChat').projectDir = new File(rootProject.projectDir, '.. /node_modules/react-native-wechat/android')
Copy the code
Add the following code to the Dependencies section of Android /app/build.gradle:
compile project(':RCTWeChat')
Copy the code
Add the following code to the mainActivity. Java or mainApplication. Java file:
import com.theweflex.react.WeChatPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
...
new WeChatPackage()
);
}
Copy the code
Create a folder named ‘wxAPI’ and create wxentryActivity.java in the folder to obtain authorization and share permissions on wechat.
Wxentryactivity. Java code: package (here is your package name).wxAPI; import android.app.Activity; import android.os.Bundle; import com.theweflex.react.WeChatModule; public class WXEntryActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WeChatModule.handleIntent(getIntent()); finish(); }}Copy the code
Create a wxPayEntryActivity. Java file in this folder for wechat Pay
Wxpayentryactivity.java code package (here is your package name).wxAPI; import android.app.Activity; import android.os.Bundle; import com.theweflex.react.WeChatModule; public class WXPayEntryActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WeChatModule.handleIntent(getIntent()); finish(); }}Copy the code
In the AndroidManifest. XML is added
<manifest>
<application>
<activity
android:name=".wxapi.WXEntryActivity"
android:label="@string/app_name"
android:exported="true"
/>
<activity
android:name=".wxapi.WXPayEntryActivity"
android:label="@string/app_name"
android:exported="true"
/>
</application>
</manifest>
Copy the code
In proguard-rules.pro add:
-keep class com.tencent.mm.sdk.** {
*;
}
Copy the code
The configuration is complete, you can run the project call API to test!! API
RegisterApp (appid) : register APP registerAppWithDescription (appid, appdesc) : register APP (only support iOS) isWXAppInstalled () : Check whether wechat is installed isWXAppSupportApi() getApiVersion() : Get wechat SDK version openWXApp() : Open wechat APP sendAuthRequest([scope[, state]]) : ShareToSession (data) : Share to friends Pay (data) : Share to friends AddListener (eventType, listener[, context]) : once(eventType, listener[, context]) : RemoveAllListeners are removed from the processCopy the code
The problem that may be encountered works fine in the development environment, but the error occurs during packaging
Then repack!! The first time to send, the article format is a little disorderly, please understand!