收藏
回答

openid获取失败?data: {errcode: 40066, errmsg: "invalid

前端发送code到后端

    wx.login({

      success: (res) => {

        const usercode=res.code

        myrequest({url:'/getopenid',data: {usercode:usercode},method: 'POST'}).then(res1=>{

            console.log(res1)

        })

后端正常接收

[Object: null prototype] {

  usercode: '0e3p9p1w3uYLA03L3k4w3wiXaF3p9p1J'

}

后端代码

exports.getopenid=async (req,res)=>{

    const code=req.body

    console.log(code)

    var params = {

        grant_type:'authorization_code',

        appid: '正确在详情里复制',

        //secret 更新时间20230504

        secret: '已经于20230504重置并更新',

        js_code:code

    }

    params=JSON.stringify(params)


    axios({

        method:'GET',

        url:'https://api.weixin.qq.com/sns/jscode2session'+params

    }).then(res2=>{

        res.send(res2.data)

    })

}

前端收到的返回信息

  1. {data: {…}, header: {…}, statusCode: 200, cookies: Array(0), errMsg: "request:ok"}
  2. cookies: []
  3. data: {errcode40066errmsg"invalid url, rid: 6453aca1-0ab89620-2cd6e1ce"}
  4. errMsg"request:ok"
  5. header: {X-Powered-By"Express"Access-Control-Allow-Origin"*"Content-Type"application/json; charset=utf-8"Content-Length"73"ETag"W/"49-BmpGmYt4SlV421N/g74TFXpWHNA"", …}
  6. statusCode200
  7. __proto__: Object

请求大师指点,不想开云

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

1 个回答

登录 后发表内容