//按钮获取用户信息已经在2021-4-18被禁用,之前的老方法只能得到空白头像和微信用户
现在用以下方法获取
<text @click="onGotUserInfo" class="authorization" v-if="showBtn">获取用户信息</text>
// 手动授权方法
onGotUserInfo(e) {
let that = this
uni.getUserProfile({
desc: 'Wexin', // 这个参数是必须的
success: res => {
console.log(res)
let userInfo = res.userInfo
console.log(userInfo)
that.nickName = userInfo.nickName
that.avatarUrl = userInfo.avatarUrl
that.city = userInfo.city
that.genter = userInfo.gender
// if (userInfo.gender == 1) {
// that.genter = '男'
// } else if (userInfo.gender == "2") {
// that.genter = "女"
// }
that.province = userInfo.province
// 成功后进行登录,获取code
uni.login({
provider: 'weixin',
success(res) {
console.log(res);
if (res.code) {
//发起网络请求
uni.request({
// 请求路径
url: that.$serverUrl + 'home/login/login',
// 请求参数code
data: {
code: res.code
},
method: 'GET',
success(res) {
// 请求成功后获取openid和session_key
let openid = res.data.openid
let session_key = res.data.session_key
that.showBtn = false
that.openid = openid
that.session_key = session_key
uni.setStorageSync("globalopenid", openid)
uni.setStorageSync("globalsession_key",
session_key)
// that.getPhoneNumber(e)
uni.request({
url: that.$serverUrl + 'home/login/saveInfo',
data: {
nickName: that.nickName,
avatarUrl: that.avatarUrl,
genter: that.genter,
province: that.province,
city: that.city,
openid:openid,
popenid:''
},
success(res) {
if(res.isok==1){
if(res.is_edit==0){
console.log("已经编辑过资料了")
uni.navigateTo({
url:'../mine/mine'
})
}
console.log(res)
}
}
})
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
fail: err => {
console.log(err)
}
})