qqq(){//点击事件
var that= this//有时候括号太多了,this不好用,现在外面定义that
wx.getUserProfile({//微信授权
lang:'zh_CN',
desc:'登录',
success: function(res) {
var userinfo = res.userInfo//获取个人信息
console.log('getUserProfile',userinfo)
wx.login({//微信登录获取到code
provider: 'weixin',
scopes: 'auth_base',
success: function(res) {
var abc = res.code
console.log('code',res);
var abc = res.code
wx.getSetting({//可以不加
success: function(res) {
console.log('121',res)
wx.getUserInfo({//同上
success: function(res) {
console.log('1211',res)
if (res) {
//发起网络请求
wx.request({//调用对方接口,将值传进去
url: 'http://47.93.121.36:9094/das/wx_login/',
data: {
nickname:userinfo.nickName,
headimg:userinfo.avatarUrl,
gender:userinfo.gender,
code:abc,
iv:res.iv,
encrypteData:res.encryptedData
},
method: 'POST',
header: {'content-type': 'application/json'},
success: function(res){
that.login_user=res.data.data
// if(res.data.data.user_type==2){ }
wx.navigateTo({
url: '../index3/index?sha1='+that.login_user.sha1+'&user_type='+that.login_user.user_type
})
console.log('123',that.login_user)
console.log('返回',res)
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
})
// getUserProfile
}})
}})
},
fail: function(){
console.log("启用wx.login函数,失败!");
},
complete:function(){
console.log("已启用wx.login函数");
}
});
},
0条评论