探秘小程序(5):用户信息

1.获取用户信息:配合button组件使用
使用实例:
wxml:
<button wx:if="{{canIUse}}" open-type='getUserInfo' bindgetuserinfo='bindGetUserInfo' class='btn'></button>
js:
bindGetUserInfo:function(e){console.log(e.detail)}
encryptedData 解密后为以下 json 结构
 {
"openId": "OPENID",
"nickName": "NICKNAME",
"gender": GENDER,
"city": "CITY",
"province": "PROVINCE",
"country": "COUNTRY",
"avatarUrl": "AVATARURL",
"unionId": "UNIONID",
"watermark":
{
"appid":"APPID",
"timestamp":TIMESTAMP
}
}
注:如果进行小程序时,没有使用填写appid则无法获取部分用户信息
2.获取用户手机号:配合button组件使用
wxml:
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" class='btn'> </button>
js:
//获取用户手机号
getPhoneNumber: function (e) {
  console.log(e.detail.errMsg)
  console.log(e.detail.iv)
  console.log(e.detail.encryptedData)
},
encryptedData 解密后为以下 json 结构
{
"phoneNumber": "13580006666",
"purePhoneNumber": "13580006666",
"countryCode": "86",
"watermark":
{
"appid":"APPID",
"timestamp":TIMESTAMP
}
}
注;如果wx.getSetting中没有获取手机号权限则,无法获取用户手机号信息,如下图所示:
 
详情请参看:

猜你喜欢

转载自www.cnblogs.com/codeww/p/9033881.html