小程序获取用户信息
现在更新后写法js```javascriptif(wx.getUserProfile){wx.getUserProfile({desc
详细介绍可仔细阅览官方文档:
https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html
注:
1.多一个必填参数:desc比之前wx.getUserInfo 多一个必填参数:desc
2.必须在点击事件后才可调用
3.wx.getUserProfile 返回的加密数据中不包含 openId 和 unionId 字段。
使用方法见下面js:
html:
<button bindtap="getUserInfo" class="btn new-modal-btn" ></button>
js:
getUserInfo(){
if (wx.getUserProfile) {
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
//这里可以获取到用户信息
}
});
}
})
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
}
相关文章
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~