getServer:function(){
// console.log(Http.HOST + Http.API_URL.GETSMSCODE)
this.showMaskView = false
//第三方登录
if(this.authId == ''){
plus.oauth.getServices(function(services) {
for (var i in services) {
var service = services[i];
console.log(JSON.stringify(service))
app.auths[service.id] = service;
if (~app.authBtns.indexOf(service.id)) { //取微信对象
app.authId = service.id;
}
}
})
}
},
wechatLogin:function(){
console.log(this.isAg)
if(!this.isAg){
this.showMaskView = true
return
}
var auth = this.auths[this.authId]; //this.authId : weixin
auth.authorize(function(event){ // 1 常登录前需要先调用authorize方法进行授权 authorize
// plus.nativeUI.alert("授权成功:"+JSON.stringify(event));
var authResult = event.target.authResult
app.code = event.code
this.state = event.state
if(!auth){
plus.nativeUI.alert("当前环境不支持微信登录");
return;
}
/**
*authResult":{"access_token":"55_Litb6uf2-*ErQq13dLYVS4baAgwQh9jQpFEkC2V82bYlt8dpZDBAABI1tBDpy8fU8xQ_iVhiy6kCFWDqu9RvM1SDS4QeT47dcy9TDlo7adLo","expires_in":7200,"refresh_to*ken":"55_cn8rI2c_FPXTpAfHioQhDFN1cTXXp-hNAwRiMBLw-*riA2ewV6JiUmNKXqipUPTPoPavNMLt0BrVjcmEjk2ZOFrup6ieG6MQghhK_Ae7SjWw","openid":"oXxH25_odA48vreQzWFPCv67lpzQ","scope":"snsapi_userin*fo","unionid":"opSEG6kuZcPX_uiNX0YZiAKiTpHY"},
**/"
if(!authResult){
auth.login(function(e){ // 2 获取微信登录授权对象后可进行登录认证操作
this.access_token = e.target.authResult.access_token
app.gotShouquan()
// plus.nativeUI.alert("登录认证成功!");
}, function(e){
plus.nativeUI.toast("登录认证失败: "+JSON.stringify(e));
} );
}else{
plus.nativeUI.toast("已经登录认证!");
app.gotShouquan()
// app.gotoMain()
}
}, function(e){
plus.nativeUI.alert("授权失败:"+JSON.stringify(e));
}, {scope:'snsapi_userinfo',appid:'wxfc88b4e9f5f63cc2'});
},
gotShouquan:function(access_token){ //获取授权的接口
Http.post({
api:'https://api.weixin.qq.com/sns/oauth2/access_token',
data:{
appid:'wxfc88b4e9f5f63cc2',
secret:'4fd1e5f71f456970c17b28bdb1a08730',
code:app.code,
grant_type:'authorization_code'
},
success:function(res){
plus.nativeUI.toast('微信授权成功')
app.gotoMain()
},
error:function(e){
plus.nativeUI.toast('请求失败:'+e.message);
}
})
},
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律