// 点击登录
getuserinfo: function (e) {
console.log(wx.getStorageSync("userInfo").id )
if (wx.getStorageSync("userInfo").id == "undefined") {//判断是否登录
this.setData({
popping: true,
})
}
let that = this
wx.getSetting({
success: function (Setting_res) {
if (Setting_res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.showLoading({
title: '登录中...',
mask: true
})
wx.login({
success: function (login_res) {
let code = login_res.code
console.log(2222222)
// console.log(code)
wx.getUserInfo({
withCredentials: true, //是否带上登录状态信息,
success: function (getUserInfo_res) { //获取用户信息
console.log(getUserInfo_res)
wx.setStorageSync("userInfo", getUserInfo_res.userInfo) //存入本地
Post("api/login/login", {
code, //微信
iv: getUserInfo_res.iv,
encryptedData: getUserInfo_res.encryptedData,
}).then(res => {
wx.hideLoading()
if (res.stu == 1) {
wx.showToast({
title: '登录成功'
})
// 控制弹窗
that.setData({
popping: false,
})
wx.setStorageSync("userInfo", res.result) //将信息存到本地
that.setData({
userInfo: res.result
})
console.log(res.result.token)
console.log(res.result.id)
new IMController({
token: res.result.token,
account: res.result.id
})
}
})
}
})
},
fail: function (res) {
},
complete: function (res) { },
})
}
},
fail: function (res) { },
complete: function (res) { },
})
},
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。