一、授权用户公开信息
// 授权公开信息
authorization() {
uni.getUserProfile({
desc: '授权',
success: (res) => {
console.log('getUserProfile',res)
this.information = true
}
});
},
展示效果:
二、获取手机号授权
// 绑定手机号码
handePhoneNumber(e){
var that = this
console.log(e,'打印')
this.userPhoneInfo = e.detail
if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
uni.showToast({
title: '授权失败,请先确认授权手机号',
icon: 'none',
duration: 2000
});
} else {
this.phoneNumber = true
console.log(this.phoneNumber,'手机号授权状态')
}
}
效果如下:
三、调用后台的登录接口
uni.request({
url: '后台接口',
method: 'POST',
dataType: 'json',
data: {
encryptedData:this.userPhoneInfo.encryptedData,
iv:this.userPhoneInfo.iv,
openId:this.openId,
nickName:this.userInFo.nickName,
unionId:'',
avatarUrl:this.userInFo.avatarUrl
},
success: res => {
console.log(res,'用户注册返回')
}
});