流氓式--小程序用戶授權 --- 小程序授權、獲取用戶信息


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

 

1.首先你要有按鈕吧!

代碼:

    <button class="getShowInfo" type="primary" open-type="getUserInfo" bindgetuserinfo="userInfoHandler"> 確認授權 </button>
View Code

 

然后你要有js吧!!

 

 代碼:

  userInfoHandler(data){
    if (data.detail.errMsg == 'getUserInfo:ok') {
      this.set_updateMasterInfo(data.detail.userInfo);
    }else{
      app.getIsShowUserInfo()
    }
  },
View Code

 

剩下關鍵的一步了,用戶拒絕授權的時候調用全局方法!!!

 

 代碼:

  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) {

            }
          }
        })
      }
    });

  },
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM