收藏
回答

企业微信请求code2Session接口返回40029

上传的code参数{code: "aIjeGwUzRsr67XtSQsEHLy5LG573jaCRLkUF-uQUd9A", errMsg: "qy.login:ok"}
//小程序的调用code2session接口 
 let p = new Promise((resolve, reject) => {
    wx.getSystemInfo({
      success(res){
        if(res.environment=='wxwork'){
          wx.qy.login({
            success:res=>{
              console.log(res)
              wx.request({
                url: "https://api.bb-pco.com/API/sys/wxwork_login.php",
                data:{
                  code:res.code,
                  type:1
                },
                success(res) {
                  //console.log(res)
                  resolve(res);
                }
              })
            }
          })
        }else{
          wx.login({
            success:res=>{
              //console.log(res)
              wx.request({
                url: "https://api.bb-pco.com/API/sys/wxxcx_login.php",
                data:{
                  code:res.code,
                  type:1,
                },
                success(res) {
                  //console.log(res)
                  resolve(res);
                }
              })
            }
          })
        }
      }
    })
  })
  return p
};

//后端接口方法

public function get_wxwork_userid($code,$token){
  $url="https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?access_token=$token&js_code=$code&grant_type=authorization_code";
  $res=get($url);
  $res=json_decode($res,'true');
  return $res;
}

返回的结果

{
  "code": 202,
  "data": {
    "errcode": 40029,
    "errmsg": "invalid code, hint: [1600762993_51_325fa7f2f75904589360afc84be45faf], from ip: 47.98.147.218, more info at https://open.work.weixin.qq.com/devtool/query?e=40029",
    "code": "gLZO0UONp4Rd8UWgMlogAFLTdRhysHpuN1kD14wg81I"
  },
  "err": "获取userid出错"
}
回答关注问题邀请回答
收藏

2 个回答

  • 企业微信运营专员-千夜
    企业微信运营专员-千夜
    09-23

    你好,这个hint对应的日志太多应该是爆了,可以加个debug=1,然后拿hint去查请求原文https://open.work.weixin.qq.com/devtool/query

    09-23
    有用
    回复 8
    • 秦金平
      秦金平
      09-23
      GET /cgi-bin/miniprogram/jscode2session?access_token=zQ1ZKLvY9M1AVHh27FgqoSoMV9JnkOi69XLBAjH-L7bd6SzWrXzjM5aUyN-y5I3FGrgNtkTtExGydswdsacLG2mGPM9k3ROOXqTxULmTxUitBO1QQVrzYTvIdCQqwBLZLo-6ka3NOOs_832QlhXozhgGi_xYt9GEwUfAnyLDmmPEZoCZhvppcsfMDbeky-qkRml8j_v4_5W7qIdzEcUv3Q&js_code=011da7000uGSkK1Lgm200plnsu2da70E&grant_type=authorization_code&debug=1 HTTP/1.1
      X-Forwarded-For: 47.98.147.218
      PROXY_FORWARDED_FOR: DA93622F,0000,0,0,0,0,0,0,0
      WEWORK_PROXY_FORWARDED_FOR: 47.98.147.218
      Connection: Keep-Alive
      Pragma: no-cache
      X-InnerReqId: 156730671.907.1600847064.113802
      Host: qyapi.weixin.qq.com
      Accept: */*
      这个是debug的结果,看这个链接也没有发现那里不对
      09-23
      回复
    • 秦金平
      秦金平
      09-23
      从程序的逻辑来看,没觉得有重复消费的可能性
      09-23
      回复
    • 企业微信运营专员-千夜
      企业微信运营专员-千夜
      09-23回复秦金平
      把重试的hint信息贴下看看
      09-23
      回复
    • 秦金平
      秦金平
      09-23回复企业微信运营专员-千夜
      1600851252_47_e0fbe711085527f26dba36d343181382,刚刚测试的GET /cgi-bin/miniprogram/jscode2session?access_token=zQ1ZKLvY9M1AVHh27FgqoSoMV9JnkOi69XLBAjH-L7bd6SzWrXzjM5aUyN-y5I3FGrgNtkTtExGydswdsacLG2mGPM9k3ROOXqTxULmTxUitBO1QQVrzYTvIdCQqwBLZLo-6ka3NOOs_832QlhXozhgGi_xYt9GEwUfAnyLDmmPEZoCZhvppcsfMDbeky-qkRml8j_v4_5W7qIdzEcUv3Q&js_code=wEZ4JBF20Fflg0B6ebA5SVkRLEJ_L151Oi-hHt_ZlbM&grant_type=authorization_code&debug=1 HTTP/1.1
      X-Forwarded-For: 47.98.147.218
      PROXY_FORWARDED_FOR: DA93622F,0000,0,0,0,0,0,0,0
      WEWORK_PROXY_FORWARDED_FOR: 47.98.147.218
      Connection: Keep-Alive
      Pragma: no-cache
      X-InnerReqId: 156551859.48897.1600851252.126887
      Host: qyapi.weixin.qq.com
      Accept: */*
      09-23
      回复
    • 企业微信运营专员-千夜
      企业微信运营专员-千夜
      09-23回复秦金平
      你这个产生code的小程序和code2seesion登入的小程序不一致,wxd4d2b70cb76a55dd 这个是产生code的小程序,使用的accesstoken登入的小程序是wxbdffd927304a296c 这个
      09-23
      回复
    查看更多(3)
  • 秦金平
    秦金平
    09-22

    不管我怎么处理好像这里返回都是40029,我实在是不清楚错在哪里了,求大神们支招啊,企业微信关联小程序内部开发。

    09-22
    有用
    回复
登录 后发表内容
问题标签