微信小程序授權登錄解決方案的代碼實例(含未通過授權解決方案)

這篇文章主要介紹了微信小程序授權登錄解決方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨着小編來一起學習學習吧

本文實例爲大家分享了微信小程序授權登錄解決方案的具體代碼,供大家參考,具體內容如下

getUserInfoF:function(){
  
  var that = this;
  wx.getSetting({
 
   success: (res) => {
    console.info(res.authSetting);
 
 
    wx.getUserInfo({
     success: res => {
      this.globalData.userInfo = res.userInfo
      console.info("一開始同意授權"+res.userInfo.nickName);
 
      if (this.userInfoReadyCallback) {
       this.userInfoReadyCallback(res)
      }
     },
     fail(err) {
      console.info(err.errMsg);
      wx.showModal({
       title: '警告',
       cancelText: '不授權',
       confirmText: '授權',
       confirmColor: '#37C31A',
       content: '若不授權微信登錄,則無法使用XXXXXX;點擊重新獲取授權,則可重新使用;' +
       '若點擊不授權,將無法使用便捷服務。',
 
       success: function (res) {
        if (res.confirm) {
         console.log('用戶點擊確定')
         wx.openSetting({
          success: (res) => {
           if (res.authSetting['scope.userInfo']) {
            wx.getUserInfo({
             success: res => {
              that.globalData.userInfo = res.userInfo
              console.info("再次同意授權" + res.userInfo.nickName);
              if (that.userInfoReadyCallback) {
               that.userInfoReadyCallback(res)
              }
             }
            })
           } else {
            console.info("再次不允許");
            wx.redirectTo({
             url: 'home',
            })
           }
          }
         });
        } else if (res.cancel) {
         console.log('彈出框用戶點擊取消')
         wx.redirectTo({
          url: 'home',
         })
 
        }
       }
      })
 
     }
 
    })
 
   }
  })
 },

以上所述是小編給大家介紹的微信小程序授權登錄解決方案詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回覆大家的。在此也非常感謝大家對神馬文庫網站的支持!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章