QQ, WeChat, and Weibo only provide SDKs for mobile apps or JS. JS SDKs are most convenient to implement in the cordova project on the surface, but are implemented through Web pages during authorization, its session also needs to be created by entering the user name and password on the webpage. The implementation of android sdk and ios sdk is to call the installed third-party software to complete authorization, obviously, the latter is the method we want.
Recommended plug-ins:
(I used the following plug-ins. I have tried some other plug-ins and are not satisfied with them)
QQ: https://github.com/iVanPan/Cordova_QQ
Https://github.com/xu-li/cordova-plugin-wechat:
Weibo: https://github.com/iVanPan/cordova_weibo
Notes:
1. Preparations: Apply for appid on each open platform and add test accounts.
QQ: Tencent Open platform http://open.qq.com/
WeChat: WeChat open platform https://open.weixin.qq.com/
Weibo: Sina Weibo open platform Co., http://open.weibo.com/
2. Add a plug-in through cordova
Note: The WeChat plug-in will change the root directory config. xml, so we need to forge a config. xml to change it (my approach is to set config from www. copy the xml file to the root directory)
// QQ: (replace YOUR_QQ_APPID with the qq appid applied for in the first step)
Cordova plug in add https://github.com/iVanPan/Cordova_QQ.git -- variable QQ_APP_ID = YOUR_QQ_APPID
// WeChat: (replace YOUR_WECHAT_APPID with the WeChat APPID applied for in the first step)
Cordova plugin add https://github.com/xu-li/cordova-plugin-wechat -- variable wechatappid = YOUR_WECHAT_APPID
// Weibo: (replace YOUR_WEIBO_APPID with the Weibo APPID applied for in the first step)
Cordova plugin add https://github.com/iVanPan/cordova_weibo.git -- variable WEIBO_APP_ID = YOUR_WEIBO_APPID
3. Further settings of the plug-in
Redirecturi needs to be verified on weibo. Therefore, if redirecturi is set on the open platform, add the following attributes to the config. xml file:
// Replace YOUR_REDIRECT_URL with the redirecturi you set on the open platform
<Preference name = "REDIRECTURI" value = "YOUR_REDIRECT_URL"/>
The target address of the so Library is written incorrectly in the microblog plug-in. The solution is as follows:
Find this line
// Find the following line
<Source-file src = "src/android/libs/arm64-v8a/libweibosdkcore. so" target-dir = "libs/arme64-v8a/"/>
// Change the last arme64-v8a to arm64-v8a, as shown below
<Source-file src = "src/android/libs/arm64-v8a/libweibosdkcore. so" target-dir = "libs/arm64-v8a/"/>
4. Check whether the APP is installed.
YCQQ. checkClientInstalled (function (){
QQINSTALLED = true;
}, Function (){
// If installed QQ Client version is not supported sso, also will get this error
QQINSTALLED = false;
});
Wechat. isInstalled (function (installed ){
WEIXININSTALL = installed;
});
YCWeibo O. checkClientInstalled (function (){
WEIBOINSTALL = true;
}, Function (){
WEIBOINSTALL = false;
});
5. Third-party login
// QQ login
Var checkClientIsInstalled = 1; // default is 0, only for iOS
YCQQ. ssoLogin (function (args ){
Alert (args. access_token );
Alert (args. userid );
}, Function (failReason ){
Console. log (failReason );
}, CheckClientIsInstalled );
// Log on to WeChat
Var scope = "snsapi_userinfo ";
Wechat. auth (scope, function (response ){
// You may use response. code to get the access token.
Alert (JSON. stringify (response ));
}, Function (reason ){
Alert ("Failed:" + reason );
});
// Log on to Weibo
YCWeibo O. ssoLogin (function (args ){
Alert (args. access_token );
Alert (args. userid );
}, Function (failReason ){
Console. log (failReason );
});
6. Third-party sharing
// QQ sharing
Var args = {};
Args. url = "";
Args. title = "";
Args. description = "";
Args. imageUrl = "";
Args. appName = "";
YCQQ. shareToQQ (function (){
Console. log ("share success ");
}, Function (failReason ){
Console. log (failReason );
}, Args );
// Share on WeChat
// Wechat. Scene. TIMELINE indicates sharing to the circle of friends
// Wechat. Scene. SESSION indicates sharing with friends
// (1) text
Wechat. share ({
Text: "This is just a plain string ",
Scene: Wechat. Scene. TIMELINE // share to Timeline
}, Function (){
Alert ("Success ");
}, Function (reason ){
Alert ("Failed:" + reason );
});
// (2) media
Wechat. share ({
Message :{
Title: "Hi, there ",
Description: "This is description .",
Thumb: "www/img/thumbnail.png ",
MediaTagName: "TEST-TAG-001 ",
MessageExt: "This is a third-party test field ",
MessageAction: "<action> dotalist </action> ",
Media: "YOUR_MEDIA_OBJECT_HERE"
},
Scene: Wechat. Scene. TIMELINE // share to Timeline
}, Function (){
Alert ("Success ");
}, Function (reason ){
Alert ("Failed:" + reason );
});
// (3) webpage link
Wechat. share ({
Message :{
...
Media :{
Type: Wechat. Type. LINK,
WebpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
}
},
Scene: Wechat. Scene. TIMELINE // share to Timeline
}, Function (){
Alert ("Success ");
}, Function (reason ){
Alert ("Failed:" + reason );
});
// Weibo sharing (this plug-in only supports webpage links)
Var args = {};
Args. url = "http://www.baidu.com ";
Args. title = "Baidu ";
Args. description = "This is Baidu ";
Args. imageUrl = "yun_qi_img/bdlogo.png"; // if you don't have imageUrl, for android yun_qi_img/LOGO_64x64.png will be the defualt one
Args. defaultText = "";
YCWeibo O. shareToWeibo O (function (){
Alert ("share success ");
}, Function (failReason ){
Alert (failReason );
}, Args );
7. Plug-in transformation
(1) when the SESSION is deleted, YC uses the session cache access_token method, which leads to a problem. If other third-party accounts are replaced without being called and logged out, the authorization cannot be re-authorized, due to the special nature of the project, I decided to remove the session. The method is as follows:
Android: YCQQ. java, find mTencent. isSessionValid (), comment out if and else, only keep the code in else
IOS: YCQQ. m. Find self. tencentOAuth. isSessionValid and comment out if and else. Only the code in else is retained.
(2) the Weibo sharing URL is not practical. Only the word "webpage link" can be displayed after sharing, and there are no images and descriptions. It is estimated that the application should be reviewed, but I have not found the portal, so I decided to change the webpage-based sharing to text-based. The following code is used:
(When defining args in js, you also need to write the content to the content)
Android: YCWeibo O. java, find weiboMessage. mediaObject = getWebpageObj (params); that section, changed:
TextObject textObject = new TextObject ();
TextObject. identify = Utility. generateGUID ();
Try {
TextObject. text = params. getString ("content ");
} Catch (JSONException e ){
}
WeiboMessage. mediaObject = textObject;
IOS: YCWeibo O. m, comment on the WBWebpageObject section, and add the code:
Message. text = [params objectForKey: @ "content"];
8. Regenerate the platform. After manually modifying the plug-in, you need to regenerate the platform version. (if you have any file that has been changed elsewhere, please remember to reset it)
Cordova platform rm android
Cordova platform rm ios
Cordova platform add android
Cordova platform add ios
9. xcode must allow bitcode because Sina library does not match
Build settings-> all-> Search for bitcode and change the value to no
10. xcode needs to perform urltype check. If it is missing, supplement it.
Tencentopenapi
URL Schemes: tencent + appid
Weibo
URL Schemes: wb + appid
Weixin
URL Schemes: appid