我拿你们实例真机调试是没有问题,但打包后就不行。
var auths={};
function plusReady(){
// 获取登录认证通道
plus.oauth.getServices(function(services){
var content=document.getElementById('dcontent');
var info=document.getElementById("info");
var txt="登录认证通道信息:";
for(var i in services){
var service=services[i];
console.log(service.id+": "+service.authResult+", "+service.userInfo);
auths[service.id]=service;
txt += "id:"+service.id+", ";
txt += "description:"+service.description+", ";
var de=document.createElement('div');
de.setAttribute('class','button');
de.setAttribute('onclick','login(this.id)');
de.id=service.id;
de.innerText=service.description+"登录";
oauth.appendChild(de);
}
info.innerText=txt;
},function(e){
outLine("获取登录认证失败:"+e.message);
});
}
document.addEventListener('plusready',plusReady,false);
// 登录认证
function login(id){
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;
outLine("登录认证成功:");
outLine(JSON.stringify(auth.authResult));
userinfo(auth);
},function(e){
w&&w.close();w=null;
outLine("登录认证失败:");
outLine("["+e.code+"]:"+e.message);
plus.nativeUI.alert("详情错误信息请参考授权登录(OAuth)规范文档:http://www.html5plus.org/#specification#/specification/OAuth.html",null,"登录失败["+e.code+"]:"+e.message);
});
}else{
outLine("无效的登录认证通道!");
plus.nativeUI.alert("无效的登录认证通道!",null,"登录");
}
}
// 获取用户信息
function userinfo(a){
outLine("----- 获取用户信息 -----");
a.getUserInfo(function(){
outLine("获取用户信息成功:");
outLine(JSON.stringify(a.userInfo));
var nickname=a.userInfo.nickname||a.userInfo.name;
plus.nativeUI.alert("欢迎“"+nickname+"”登录!");
},function(e){
outLine("获取用户信息失败:");
outLine("["+e.code+"]:"+e.message);
plus.nativeUI.alert("获取用户信息失败!",null,"登录");
});
}
// 注销登录
function logoutAll(){
for(var i in auths){
logout(auths[i]);
}
}
function logout(auth){
auth.logout(function(){
outLine("注销\""+auth.description+"\"成功");
},function(e){
outLine("注销\""+auth.description+"\"失败:"+e.message);
});
}
窗边的小豆豆
这个问题解决了吗?
2018-10-25 17:10