小程序绑定手机号,头像昵称
获取用户信息,头像昵称
样式
<button open-type="getUserInfo" bindgetuserinfo="getUserInfo" >
使用微信信息
</button>
方法
getUserInfo: function(e) {
let that = this;
if (e.detail.errMsg == "getUserInfo:ok") {
util.getData("userInit", {
openid: app.globalData.openid,
nickname: e.detail.userInfo.nickName,
avatar: e.detail.userInfo.avatarUrl,
method: "POST"
},
function(data) {
if (!data.errno) {
that.init()
} else {
tips.showModel('提示', data.errdesc);
}
})
}
}
绑定手机号
样式
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">绑定手机号码</button>
方法
getPhoneNumber: function(e) {
let that = this;
if (e.detail.errMsg == 'getPhoneNumber:ok') {
util.getData('decryptData', {
iv: e.detail.iv,
encryptedData: e.detail.encryptedData,
session_key: app.globalData.session_key,
method: "POST"
},
function(dataDed) {
let telephone = dataDed.data.phoneNumber;
util.getData('bindTel', {
openid: app.globalData.openid,
telephone: telephone,
method: 'POST'
},
function(dataTel) {
that.init()
})
})
}
}