1.獲取用戶信息:配合button組件使用
使用實(shí)例:
wxml:
<button wx:if="{{canIUse}}" open-type='getUserInfo' bindgetuserinfo='bindGetUserInfo' class='btn'></button>
js:
bindGetUserInfo:function(e){console.log(e.detail)}
encryptedData 解密后為以下 json 結(jié)構(gòu)
{ "openId": "OPENID", "nickName": "NICKNAME", "gender": GENDER, "city": "CITY", "province": "PROVINCE", "country": "COUNTRY", "avatarUrl": "AVATARURL", "unionId": "UNIONID", "watermark": { "Appid":"APPID", "timestamp":TIMESTAMP } }
注:如果進(jìn)行小程序時(shí),沒有使用填寫appid則無法獲取部分用戶信息
2.獲取用戶手機(jī)號(hào):配合button組件使用
wxml:
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" class='btn'> </button>
js:
//獲取用戶手機(jī)號(hào)
getPhoneNumber: function (e) { console.log(e.detail.errMsg) console.log(e.detail.iv) console.log(e.detail.encryptedData) },
encryptedData 解密后為以下 json 結(jié)構(gòu)
{ "phoneNumber": "13580006666", "purePhoneNumber": "13580006666", "countryCode": "86", "watermark": { "appid":"APPID", "timestamp":TIMESTAMP } }
注;如果wx.getSetting中沒有獲取手機(jī)號(hào)權(quán)限則,無法獲取用戶手機(jī)號(hào)信息,如下圖所示: