記得微信剛改授權方式的時候,自己心中一萬個動物才沸騰,你逼着老子改代碼,我真不想改,但是沒有微信爸爸牛逼啊! 下面我吧代碼貼出來僅供大家參考
1.首先你要有按鈕吧!
代碼:

<button class="getShowInfo" type="primary" open-type="getUserInfo" bindgetuserinfo="userInfoHandler"> 確認授權 </button>
然后你要有js吧!!
代碼:

userInfoHandler(data){ if (data.detail.errMsg == 'getUserInfo:ok') { this.set_updateMasterInfo(data.detail.userInfo); }else{ app.getIsShowUserInfo() } },
剩下關鍵的一步了,用戶拒絕授權的時候調用全局方法!!!
代碼:

getIsShowUserInfo: function () { wx.openSetting({ success: (resopen) => { // 判斷是否是第一次授權,非第一次授權且授權失敗則進行提醒 wx.getSetting({ success: function success(res) { let authSetting = res.authSetting; // 沒有授權的提醒 if (authSetting["scope.userInfo"] === false) { wx.showModal({ title: "用戶未授權", content: "如需正常使用該小程序功能,請按確定並在授權管理中選中“用戶信息”,然后點按確定。最后再重新進入小程序即可正常使用。", showCancel: false, success: (res) => { if (res.confirm) { wx.openSetting({ success: (resopen) => { } }); } } }) } else if (authSetting["scope.userInfo"] === true) { } } }) } }); },