WeChat⼩程序如何获取⽤户的个⼈信息头像昵称、性别
亚冠分组
与地区)?
由于WeChat⼩程序发布了新的规范,获取⽤户的个⼈信息将使⽤新的⽅法。重阳节最漂亮手抄报
如何做?
在⼩程序的UI(.wxml⽂件)添加⼀个button(代码如下),让⽤户授权后才能获得⽤户的个⼈信息;这个button绑定了⼀个⽅法:getUserProfile,这个⽅法是我们⾃定义。
<button bindtap="getUserProfile">获取头像昵称...</button>
在⼩程序的后端(.js⽂件)添加 getUserProfile ⽅法。
// 获取头像昵称...
getUserProfile(e) {
// 推荐使⽤wx.getUserProfile获取⽤户信息,开发者每次通过该接⼝获取⽤户个⼈信息均需⽤户确认
// 开发者妥善保管⽤户快速填写的头像昵称,避免重复弹窗
desc: '⽤于完善会员资料', // 声明获取⽤户个⼈信息后的⽤途,后续会展⽰在弹窗中,请谨慎填写
success: (res) => {
console.log(res.userInfo);
app.globalData.wxUserProfile.avatarUrl = res.userInfo.avatarUrl;
app.globalData.wxUserProfile.city = res.userInfo.city;
科目四题型
app.untry = untry;
投资效益
中秋节的神话故事app.der = der;
app.globalData.wxUserProfile.language = res.userInfo.language;
款待英语app.globalData.wxUserProfile.nickName = res.userInfo.nickName;
app.globalData.wxUserProfile.province = res.userInfo.province;
}
})
}