1、准备工作,分别到各个开放平台申请appid,添加测试账号
QQ:腾讯开放平台 http://open.qq.com/
微信:微信开放平台 https://open.weixin.qq.com/
微博:新浪微博开放平台 http://open.weibo.com/
2、通过cordova添加插件(注意把YOUR_QQ_APPID替换成第一步申请的QQ APPID)
QQ:
cordova plugin add https://github.com/iVanPan/Cordova_QQ.git --variable QQ_APP_ID=YOUR_QQ_APPID
微信:
cordova plugin add https://github.com/xu-li/cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID
微博:
cordova plugin add https://github.com/iVanPan/cordova_weibo.git --variable WEIBO_APP_ID=YOUR_WEIBO_APPID
3、插件的进一步设置
//YOUR_REDIRECT_URL替换为你在开放平台上设置的redirecturi,value值为APPID
<preference name="REDIRECTURI" value="YOUR_REDIRECT_URL" />
4、检查设备是否安装APP代码
//qq
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.checkClientInstalled(function(){
WEIBOINSTALL=true;
},function(){
WEIBOINSTALL=false;
});
5、第三方登录代码
//QQ登录
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);
//微信登录
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);
});
//微博登录
YCWeibo.ssoLogin(function(args){
alert(args.access_token);
alert(args.userid);
},function(failReason){
console.log(failReason);
});
PS:注意确认证书是否正确,APPID是否正确