前端
<button class="show" type="primary" lang="zh_CN" open-type='getPhoneNumber' bindgetphonenumber="getPhoneNumber">登录</button>
js
//获取手机号授权
getPhoneNumber: function(e) {
let that = this;
// 用户拒绝授权
if(e.detail.errMsg == "getPhoneNumber:fail user deny") {
wx.showToast({
icon: "none",
title: '请允许获取手机号,否则功能不可用!',
})
return
}
// 1.获取临时登录凭证code
let code = '';
wx.login({
success: (res) => {
code = res.code;
this.getSessionKey(res.code, e.detail.encryptedData, e.detail.iv);
},
});
},
// 2.访问登录凭证校验接口获取session_key(后续改成后台实现)
getSessionKey: function(js_code, encryptedData, iv) {
util.request(api.GetSessionKey, {
code: js_code
}, 'POST').then(function (res) {
console.log(encryptedData);
console.log(iv);
console.log(res);
})
}
后端
/**
* 微信小程序获取session_key
*/
@RequestMapping(value = {"getSessionKey"}, method = {RequestMethod.P