微信的用户授权进行了调整,具体见https://developers.weixin.qq.com/community/develop/doc/000aee01f98fc0cbd4b6ce43b56c01
<button open-type="getUserInfo" bindgetuserinfo="bindgetuserinfo">点击授权</button>调用后会弹出授权信息,由用户自己来确认是否进行授权。
授权后的判断如下:
bindgetuserinfo: function (e) { var that = this; if (e.detail.userInfo) { // 发送 res.code 到后台换取 openId, sessionKey, unionId wx.login({ success: res => { console.log(res.code, e.detail.iv,e.detail.encryptedData) wx.request({ //后台接口地址 url: '', data: { code:res.code, iv:e.detail.iv, encryptedData:e.detail.encryptedData, }, method: 'GET', header: { 'content-type': 'application/json' }, success: function (res) { console.log('请求成功') } }) } }) } else { console.log(333,'执行到这里,说明拒绝了授权') wx.showToast({ title: "为了您更好的体验,请先同意授权", icon: 'none', duration: 2000 }); } }