A Capacitor-compatible Cordova plugin, a JS version of Wechat SDK
- check wechat client is installed;
- open wechat auth;
-
Run the following in the appropriate Capacitor directory:
yarn add cordova-plugin-wechat@github:quanticedu/cordova-plugin-wechat
-
Configure appropriate variables in
capacitor.config.json:{ ... "cordova": { "preferences": { ... "WECHATAPPID": "<your_wechat-app_id>", "UNIVERSALLINK": "<your_universal_link>", ... } }, ... } -
Run
yarn cap syncin the appopriate Capacitor directory
-
If using a version of Capacitor less than v6.1, the
capacitor:sync:beforehook that executes./scripts/android-install.jsin this plugin won't get executed automatically. For this reason, we export anandroid-installexecutable in this project'spackage.json. -
In your Capacitor project's
package.jsonfile, you'll want to manually add acapacitor:sync:beforehook that executesandroid-install, like so:{ ... "scripts": { ... "capacitor:sync:before": "android-install", ... } ... }- You can choose to commit the resultant
android/app/src/main/java/com/package/name/wxapi/WXEntryActivity.javato version control, or not.
- You can choose to commit the resultant
Wechat.isInstalled(function (installed) {
alert("Wechat installed: " + (installed ? "Yes" : "No"));
}, function (reason) {
alert("Failed: " + reason);
});var scope = "snsapi_userinfo",
state = "_" + (+new Date());
Wechat.auth(scope, state, function (response) {
// you may use response.code to get the access token.
alert(JSON.stringify(response));
}, function (reason) {
alert("Failed: " + reason);
});