//点击微信登录授权手机号
getPhoneNumber(e) {
var that = this;
console.log("微信授权手机号", e.detail)
wx.login({
success: res => {
console.log("login code", res.code);
//是否授权,授权通过进入下单页面,授权拒绝则手机号登录
if (e.detail.errMsg == 'getPhoneNumber:ok') {
wx.request({
url: app.globalData.url + 'api/Account/WxLogin/',
data: {
encryptedData: e.detail.encryptedData, //encodeURIComponent(e.detail.encryptedData),
iv: e.detail.iv,
code: res.code
},
method: 'GET',
header: {
'content-type': 'application/json'
},
success: function(res) {
console.log("success", res)
if (res.data.Code == 200) {
wx.showToast({
title: '授权成功',
})
wx.navigateTo({
url: '../order_company/order_company',
})
} else {
wx.showToast({
title: res.data.Message,
icon: 'none'
})
}
},
fail: function(res) {
console.log("fail", res);
wx.showToast({
title: res.errMsg,
icon: 'none'
})
}
})
} else if (e.detail.errMsg === 'getPhoneNumber:fail user deny') { //拒绝授权
wx.showToast({
title: '您拒绝了授权',
icon: 'none',
duration: 2000
})
wx.navigateTo({
url: '../telLogin/telLogin',
})
} else if (e.detail.errMsg === 'getPhoneNumber:fail 用户未绑定手机,请先在微信客户端进行绑定后重试') {
wx.showToast({
title: '您的微信未绑定手机号',
icon: 'none',
duration: 3000
})
wx.navigateTo({
url: '../telLogin/telLogin',
})
} else {
wx.showToast({
title: '网络繁忙,请稍候再试',
icon: 'none',
})
}
},
fail: function(res) {
wx.showToast({
title: '获取登录态失败,请检查网络',
icon: 'none',
duration: 2000
})
}
});
},