var auths = {} function plusReady() { plus.oauth.getServices(function(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 loginInfo(dest){ var auth=auths[dest]; console.log(JSON.stringify(auth)) if(auth){ var w=null; if(plus.os.name=="Android"){ w=plus.nativeUI.showWaiting(); } document.addEventListener("pause",function(){ setTimeout(function(){ w&&w.close();w=null; },2000); }, false ); auth.login(function(){ w&&w.close();w=null; userinfo(auth); },function(e){ w&&w.close();w=null; $.toast("登录认证失败:["+e.code+"]:"+e.message); }); }else{ $.toast("无效的登录认证通道!"); $.toast("无效的登录认证通道!",null,"登录"); } } //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) } }) }