第三方登录

This commit is contained in:
hubingliang
2018-04-03 09:45:10 +08:00
parent 835c623659
commit 49a281e51d
3 changed files with 52 additions and 20 deletions
+46 -6
View File
@@ -1,16 +1,19 @@
var auths = {}
function plusReady() {
plus.oauth.getServices(function(services) {
alert("111111111111111111111111")
auths = services;
for(var i in services){
var service=services[i];
auths[service.id]=service;
}
}, function(e) {
alert("获取登录服务列表失败:" + e.message + " - " + e.code);
});
}
document.addEventListener('plusready',plusReady,false);
// 登录认证
function webChatLogin(){
var auth=auths['weixin'];
function loginInfo(dest){
var auth=auths[dest];
console.log(JSON.stringify(auth))
if(auth){
var w=null;
if(plus.os.name=="Android"){
@@ -34,6 +37,43 @@ function webChatLogin(){
}
}
function authLogin(type) {
console.log("hhhhhhhhhhhhhhhhhhh")
//wx获取用户信息
function userinfo(a){
a.getUserInfo(function(){
console.log(JSON.stringify(a))
$.showPreloader();
if(a.id=='weixin'){
var nickname=a.userInfo.nickname||a.userInfo.name||a.userInfo.miliaoNick;
var openid = a.authResult.openid;
var accessToken = a.authResult.access_token;
var unionid = a.userInfo.unionid;
var headImg = a.userInfo.headimgurl;
wxlogin(openid,unionid,accessToken,nickname,headImg)
}else if(a.id=='qq'){
var nickname=a.userInfo.nickname;
var openid = a.authResult.openid;
var accessToken = a.authResult.access_token;
var headImg = a.userInfo.headimgurl;
}else{
//微博信息获取
}
},function(e){
$.toast("获取微信用户信息失败:["+e.code+"]:"+e.message);
});
}
function wxlogin(openid, unionid, accessToken, nickname, headImg) {
axios.post("/rest/user/wxLogin", {openid:openid, unionid:unionid, accessToken: accessToken, nickname:nickname,headImg:headImg})
.then(function (response) {
$.hidePreloader();
if(response.data.status){
console.log(JSON.stringify(response.data))
//跳转页面
}else{
//登录失败
$.toast(response.data.data)
}
})
}