收藏
回答

wx.getSetting包裹getUserProfile是不会获取授权弹窗吗?要怎么处理?

getUserProfile(e) {
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
          wx.getUserProfile({
            desc'用于获取用户个人信息'// 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
            success: function (detail) {
              wx.login({
                success: ress => {
                  var code = ress.code; //登录凭证
                  console.log(">>>>>>>>>>code:", code)
                  console.log("encryptedData:", detail.encryptedData)
                  console.log("iv:", detail.iv)
                  wx.request({
                    url: api.getUnionId, //自己的服务接口地址
                    method'post',
                    header: {
                      'content-type''application/x-www-form-urlencoded'
                    },
                    data: {
                      encryptedData: detail.encryptedData,
                      iv: detail.iv,
                      code: code,
                    },
                    success: (res) => {
                      console.log("res:", res.data)
                      if (res.data.code == 'C00000') {
                        util.setToken(res.data.msg);
                        util.setStorageSync("userInfo", res.data.obj);
                        wx.redirectTo({
                          url'/pages/breakpage/breakpage',
                        })
                      }
                    },
                    fail: function () {
                      console.log('系统错误')
                    }
                  })
                }
              });
            }
          });
        }
      }
    })
  },

请问wx.getSetting不能用,要用什么替代?原先使用getuserinfo是可以正常授权的,直接换成getUserProfile点击没反应啊,去掉wx.getSetting后会提示unionid为空,我是新手,请大佬回答下怎么改呢?

回答关注问题邀请回答
收藏

4 个回答

登录 后发表内容
问题标签