'access_token'
发布于 6 年前 作者 chao24 7318 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现

想要不报错,正确的获取openid

  • 复现路径

  • 提供一个最简复现 Demo

//app.js

App({

  onLaunch: function() {

    //获取access_token

    wx.request({

      url: http://api.wss.onlyjune.com/accessToken?client_id=20882088&secret=nGk5R2wrnZqQ02bed29rjzax1QWRIu1O,

      data: {},

      method: ‘post’,

      header: {

        ‘Content-Type’: ‘application/json’

      },

      success: function(res) {

        // console.log(res.data)

        console.log(res.data.access_token)

        wx.login({

          success: function(res) {

            console.log(res.code)

            //发送请求

            wx.request({

              url: http://api.wss.onlyjune.com/login/getWxOpenid.html,

              data: {

                access_token: res.data.access_token,

                code: res.code

              },

              header: {

                ‘content-type’: ‘application/json’ //默认值

              },

              success: function(res) {

                var that = this;

                console.log(res.data)

              }

            })

          }

        })

        // console.log(res.data)

        wx.setStorage({

          key: ‘access_token’,

          data: {

            access_token: res.data.access_token,

            expires: Date.parse(new Date()) + res.data.expires,

          },

          success: function(res) {},

        })

      },

      fail: function() {

      }

    })

  },

  globalData: {

    userInfo: null

  }

})

2 回复

变量覆盖了

两个都是res

回到顶部