zoukankan      html  css  js  c++  java
  • 小程序授权怎么写 , 用户点击取消授权 调用 wx.authorize

    点击获取授权

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

    }

    或者

    openSet: function () {
    var _self = this;
    wx.openSetting({
      success: (res) => {
        if (!res.authSetting['scope.userInfo']) {
          wx.showModal({
            title: '提示',
            content: '小程序需要授权',
            showCancel: false,
            success: function (res) {
                 if (res.confirm) {
                    _self.openSet();
                }
            }
          });
        } else {
              _self.wxLogin();
          }
      }
    })
    

    },

  • 相关阅读:
    python入门:字符编码
    python入门:字符串2
    使用keepalived实现高可用
    基于sersync实现实时同步
    kubeadm 的工作原理
    docker-stop不能停止容器
    kubernetes 中的证书工作机制
    docker-hub中python的tag都代表什么意思
    MFS 介绍
    安装sngrep线路抓包工具
  • 原文地址:https://www.cnblogs.com/Zhangqwr/p/8488635.html
Copyright © 2011-2022 走看看