微信小程序开发(6)---用户拒绝授权,重新调起授权

来源:互联网 发布:淘宝卖家后台官网 编辑:程序博客网 时间:2024/06/04 19:08


 onLoad: function (options) {

    console.log("onLoad=====");
    var that=this;
    wx.getUserInfo({
      success:function(res){
        var userInfo = res.userInfo;
        that.setData({
          nickName: userInfo.nickName,
          avatarUrl: userInfo.avatarUrl,
        })
      },fail:function(){
        wx.showModal({
          title: '警告',
          content: '您点击了拒绝授权,将无法正常显示个人信息,点击确定重新获取授权。',
          success:function(res){
            if (res.confirm){
              wx.openSetting({
                success: (res) => {
                  if (res.authSetting["scope.userInfo"]){////如果用户重新同意了授权登录
                    wx.getUserInfo({
                      success:function(res){
                        var userInfo = res.userInfo;
                        that.setData({
                          nickName:userInfo.nickName,
                          avatarUrl:userInfo.avatarUrl,
                        })
                      }
                    })
                  }
                },fail:function(res){
                 
                }
              }) 
             
            }
          }
        })
      }, complete: function (res){


      }
    })
  }



































阅读全文
0 0