wx.login获取不到code
发布于 5 年前 作者 junhao 13124 次浏览 来自 问答
//调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              var code = res.code;
              that.globalData.userInfo = res.userInfo
              console.log(code);
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }

打印code显示"undefined"

//调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              var code = res.code;
              that.globalData.userInfo = res.userInfo
              console.log(res);
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })

打印res,里面找不到code字段

是接口有变化吗?还是需要配置什么

2 回复

wx.login获取code,wx.getUserInfo获取用户信息,你位置放错了

//调用登录接口
      wx.login({

        success: function (res) {

          var code = res.code;

          console.log(code);

          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              console.log(res);
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
回到顶部