apiClould微信三方登录,qq三方登录
三方登录需要在config.xml文件中配置一下,res文件下需要新建一个key.xml文件中也需要配置,请点击链接查看详情
微信:https://docs.apicloud.com/Client-API/Open-SDK/wx
QQ:https://docs.apicloud.com/Client-API/Open-SDK/qq
微博:https://docs.apicloud.com/Client-API/Open-SDK/weibo
微信三方登录:
wxlogin: function() { var this_obj = this; var wx = api.require('wx'); wx.isInstalled(function(ret, err) { if (ret.installed) { wx.auth({}, function(coderet, err) { if (coderet.status) { wx.getToken({ code: coderet.code, }, function(tokenret, err) { if (tokenret.status) { wx.getUserInfo({ accessToken: tokenret.accessToken, openId: tokenret.openId, }, function(userret, err) { if (userret.status) { var user_info = { nickname: userret.nickname, headimgurl: userret.headimgurl, sex: userret.sex } var data = { open_id: userret.openid, user_info: JSON.stringify(user_info), unionid: userret.unionid, type: '微信', source: 'APP' } var u_url = "/LoginBak/login"; common_ajax(u_url, data, function(ret) { this_obj.token = ret.info.token; this_obj.binding_status = ret.info.binding_status; this_obj.user_code = ret.info.user_code; if (this_obj.binding_status == false) { this_obj.show_bind = true; } else { setToken(ret.info.token); after_login(); huanxin_loding(ret.info.token) } }, function(ret) { api.toast({ msg: res.info }); }); } else { api.toast({ msg: '获取个人用户信息失败!' }); } }); } else { api.toast({ msg: '获取accesstoken失败!' }); } }); } else { api.toast({ msg: '获取code失败!' }); } }); } else { api.toast({ msg: '您还未未安装微信客户端!' }); } }); },
QQ三方登录
qqlogin: function() { var this_obj = this; var qq = api.require('qq'); qq.installed(function(ret, err) { if (ret.status) { qq.login(function(tokenret, err) { if (tokenret.status) { qq.getUserInfo(function(userret, err) { if (userret.status) { var user_info = { nickname: userret.info.nickname, headimgurl: userret.info.figureurl_qq_2, sex: userret.info.gender } var data = { open_id: tokenret.openId, user_info: JSON.stringify(user_info), type: 'qq', source: 'APP' } var u_url = "/LoginBak/login"; common_ajax(u_url, data, function(ret) { this_obj.token = ret.info.token; this_obj.binding_status = ret.info.binding_status; this_obj.user_code = ret.info.user_code; if (this_obj.binding_status == false) { this_obj.show_bind = true; } else { setToken(ret.info.token); after_login(); huanxin_loding(ret.info.token) } }, function(ret) { api.toast({ msg: res.info }); }); } }); } }); } else { api.toast({ msg: '您还没有没有安装qq客户端' }); } }); },
微博三方登录
sinalogin: function() { var this_obj = this; var weibo = api.require('weibo'); weibo.isInstalled( function(ret) { if (ret.status) { weibo.auth({ apiKey: 659936984, registUrl: 'http://apicloud.com' }, function(tokenret, err) { alert(JSON.stringify(tokenret)) if (tokenret.status) { weibo.getUserInfo({ token: tokenret.token, userId: tokenret.userId }, function(userret, err) { if (userret.status) { var user_info = { nickname: userret.userInfo.screen_name, headimgurl: userret.userInfo.profile_image_url } var data = { user_info: JSON.stringify(user_info), open_id: userret.userInfo.id, type: '微博', source: 'APP' } var u_url = "/LoginBak/login"; common_ajax(u_url, data, function(ret) { // alert(222) this_obj.token = ret.info.token; this_obj.binding_status = ret.info.binding_status; this_obj.user_code = ret.info.user_code; if (this_obj.binding_status == false) { this_obj.show_bind = true; } else { setToken(ret.info.token); after_login(); huanxin_loding(ret.info.token) } }, function(ret) { api.toast({ msg: res.info }); }); } }); } else { api.toast({ msg: "获取token失败" }); } }); } else { api.toast({ msg: "您尚未安装新浪微博客户端" }); } } ); }