html5app微信登陆,基于h5+的微信登陆,hbuilder打包
wxLoginFn() {
let self= this;
getService()//微信受權登陸對象
let aweixin = null;//當前環境支持的全部受權登陸對象
let auths = null;//獲取登陸受權認證服務列表,單獨保存微信登陸受權對象
functiongetService(){
plus.oauth.getServices(function(services){//plus.nativeUI.alert("services:"+JSON.stringify(services));
auths =services;
authLogin()
},function(e){
plus.nativeUI.alert("獲取登陸受權服務列表失敗,請稍后重試");//plus.nativeUI.alert("獲取登陸受權服務列表失敗:"+JSON.stringify(e));
} );
}//獲取微信登陸受權對象后可進行登陸認證操做
functionauthLogin(){for(let i = 0; i < auths.length; i++){if(auths[i].id == 'weixin'){
aweixin=auths[i];break;
}
}if(!aweixin){
plus.nativeUI.alert("當前環境不支持微信登陸");return;
}if(!aweixin.authResult){
aweixin.login(function(e){//plus.nativeUI.alert("登陸認證成功!"+JSON.stringify(e));
authUserInfo()
},function(e){//plus.nativeUI.alert("登陸認證失敗: "+JSON.stringify(e));
} );
}else{
authUserInfo()
console.log("已經登陸認證!");
}
}//獲取微信登陸受權對象后獲取用戶信息操做
functionauthUserInfo(){
Toast.loading({
mask:true,
message:'微信登陸中...'});if(!aweixin){
Toast.clear();
plus.nativeUI.alert("當前環境不支持微信登陸");return;
}if(aweixin.authResult){
aweixin.getUserInfo(function(e){
//登陸成功處理
Toast.clear();//plus.nativeUI.alert("獲取用戶信息成功:"+JSON.stringify(aweixin.userInfo));
let wxUserInfo =aweixin.userInfo;
Storage.set('wxUserInfo', JSON.stringify(wxUserInfo));
authLoginOut();//注銷登陸防止切換帳號獲取到舊信息
}, function(e){
console.log("獲取用戶信息失敗: "+JSON.stringify(e));
} );
}else{
Toast.clear();
plus.nativeUI.alert("未登陸認證!");
}
}//注銷登陸認證
functionauthLoginOut(){if(!aweixin){
plus.nativeUI.alert("當前環境不支持微信登陸");return;
}
aweixin.logout(function(e){//plus.nativeUI.alert("注銷登陸認證成功!"+JSON.stringify(e));
}, function(e){
console.log("注銷登陸認證失敗: "+JSON.stringify(e));
});
}
}
總結
以上是生活随笔為你收集整理的html5app微信登陆,基于h5+的微信登陆,hbuilder打包的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html所有页面根的对象,在django
- 下一篇: html中红色星号,谨慎使用CSS中的星