微信小城后台保存:{"errcode":40163,"errmsg":"code been used, hints: [ req_id: MZVK_a08902046 ]"

微信授权,前端通过code,获取{"session_key":"XhQgng==","openid":"EVIvgJiS_t_ycOU"}

,然后后台端调用上面方法,通过code获取,就报标签这个错误。(代码一样,只有前后端请求不同而已,为啥报错?可能是微信限制)

解决的方法是:

   wx.login({
      success:(res) =>{
        if (res.code) {
             wx.request({
                method: 'GET',
                header: { 'content-type': 'application/json' },
                url: "http://localhost:8080/platform-admin/api/login/getOpenId",
                data: {
                  js_code: js_code,
                  appid,
                  secret,
                  grant_type: 'authorization_code'
                },
                success:(res2)=>{
                  console.log("xxx", JSON.stringify(res2.data));
                  this.setData({
                    wxCode: JSON.stringify(res2.data)  //赋值,重点
                  });
                } 
              });
        }
       }

wxCode: JSON.stringify(res2.data),获取登录后赋值,先保存起来,下面传到后台就可以了

猜你喜欢

转载自blog.csdn.net/linhaibing009/article/details/89354562