NativeScript WeChat login plugin
Using this plugin you will be able implement wechat login feature in your APP. You can read more details from here
Installation
tns plugin add nativescript-wechat-loginIf you are using NativeScript 5.4.X then you can have a look this branch
Android
If installation was successful then wxapi.WXEntryActivity.android.ts file should be create to your src or app (based on nsconfig.json) directory with your APP ID. If it wasn't successfully created then you will have to create that file manually. You can get code of that file from here. In this case you will require to change YOUR_APP_ID to your app's ID.
If you don't have wxapi.WXEntryActivity.android.ts file in your app directory then Android won't receive notification from wechat.
Webpack
You will have to add wxapi.WXEntryActivity.android.ts in your webpack.config.js file so that android runtime can generate appropriate java class. Check the demo webpack.config.js file. You can read here for details.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
resolve(__dirname, "src/wxapi.WXEntryActivity.android.ts") // or resolve(__dirname, "app/wxapi.WXEntryActivity.android.ts") depends on nsconfig.json file's appPath value.
];iOS
Open your Info.plist file from App_Resources/iOS location & add following lines
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>weixin</string>
<key>CFBundleURLSchemes</key>
<array>
<string>WECHAT_APP_ID</string>
</array>
</dict>
</array>Change WECHAT_APP_ID with your Wechat App ID. Check demo project demo/App_Resources/iOS/Info.plist
Usage
For details you can check the demo project.
In your main.ts or app.ts need to import initWechatSdk(WECHAT_APP_ID) method with wechat app id.
....
import { initWechatSdk } from "nativescript-wechat-login";
initWechatSdk("wxd930ea5d5a258f4f");In any other page
....
import { WechatLogin } from "nativescript-wechat-login";
import * as app from "tns-core-modules/application";Now call in a method
let wechat = new WechatLogin();
if (wechat.isWechatInstalled()) {
wechat.doLogin("nativescript_demo");
} else {
console.log("wechat isn't installed")
}You will get response from wxApiResponse event. So, you can register in that event like this:
app.on('wxApiResponse', function(res){
console.dir(res) // you will get wechat notification here.
console.dir(res.object) // information from wechat
}, this);Ref:
https://open.wechat.com/cgi-bin/newreadtemplate?t=overseas_open/docs/mobile/login/guide#login_guide
https://github.com/aaronbruckner/wechatAndroidLoginDemo
License
Apache License Version 2.0, January 2004