1.获取手机号函数
//获取手机号码
getPhoneNumber: function (e) {
var self = this;
wx.showLoading({
title: '获取中'
})
wx.login({
success: function (msg) {
app.init(function () {
var post_data = {
iv: e.detail.iv,
appid: app.globalData.sys_config.appid,
secret: app.globalData.sys_config.secret,
encryptedData: e.detail.encryptedData,
logincode: msg.code
};
app.ajax({
url: '/index.php?m=minWechat&c=index&a=encryptedData',
data: post_data,
success: function (msg) {
wx.hideLoading()
if (msg.phoneNumber == undefined) {
wx.showToast({
title: '网络开小差了~',
icon: 'loading',
duration: 1000
})
return;
}
self.setData({
phone: msg.phoneNumber
});
}
})
});
}
})
},
2.需要给button添加 open-type
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"> </button>