<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
class="yellow-btn btn-text center"
:class="{'activity-btn': _self.$uniApi.getType(roomInfo), 'activity-btn-one': !_self.$uniApi.getType(roomInfo)}"
style="position: fixed; right: 0; background-color: #4CD964;">拨打电话</button>
getPhoneNumber(e) {
var _self = this;
// 弹窗申请获取手机号权限
if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
console.log('用户拒绝提供手机号');
uni.showToast({
title: "无法获取信息,请允许后重试!",
icon: 'none'
})
} else {
console.log('用户同意提供手机号');
uni.request({
url: "https://api.weixin.qq.com/sns/jscode2session",
method: "GET",
data: {
appid: getApp().globalData.wxAppId,
secret: getApp().globalData.wxAppSecret,
js_code: _self.code,
},
success(cts) {
// 请求成功
//解密获得用户手机号
let pc = new WXBizDataCrypt(getApp().globalData.wxAppId, cts.data.session_key);
let data = pc.decryptData(e.detail.encryptedData, e.detail.iv);
// //将用户手机号设置进全局
// getApp().globalData.phoneNumber = data.phoneNumber;
uni.setStorage({
key: 'phoneNumber',
data: data.phoneNumber,
})
_self.phoneNumber = data.phoneNumber;
_self.callPhone();
}
});
}
},
1***@qq.com (作者)
解决了,谢谢大佬,是我自己的问题,哈哈哈
2021-11-26 14:42