wx.getSetting({
success: (res) => {
if (!res.authSetting["scope.userLocation"]) {
wx.authorize({
scope: "scope.userLocation",
success: () => {
},
fail: () => {
wx.showModal({
title: "提示",
content: "授权提示语",
showCancel: false,
success: (sss) => {
if (sss.confirm) {
wx.openSetting();
}
},
});
},
});
} else {
}
},
});
- wx.getUserInfo 方法获取用户信息,必须是在用户已经授权的情况下调用
wx.getSetting({
success: (res) => {
if (res.authSetting["scope.userInfo"]) {
wx.getUserInfo({
success: (sss) => {
console.log(sss.userInfo);
},
});
}
},
});
<button open-type="getUserInfo" bindgetuserinfo="getAuth" class="btn-wrap">
授权
</button>
getAuth(e) {
let { detail } = e
}
{
"openId": "OPENID",
"nickName": "NICKNAME",
"gender": GENDER,
"city": "CITY",
"province": "PROVINCE",
"country": "COUNTRY",
"avatarUrl": "AVATARURL",
"unionId": "UNIONID",
"watermark": {
"appid": "APPID",
"timestamp": TIMESTAMP
}
}