ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

企微实战排查之“获取用户信息失败” - 排除后端因素

企微实战排查之“获取用户信息失败” - 排除后端因素 前言1. 企业微信调试工具快捷键Ctrl Alt Shift D / Command Shift Control D2. 不使用开发者工具排查问题。通过 进程-接口-网络-secret-日志 五步定位一、定位问题1.1 确认进程和端口预期端口处于LISTEN# 进程 ps -ef | grep -i jfxx | grep -v grep # PID查找具体进程 ls -l /proc/$PID/cwd # 端口会误匹配进程名、PID等 netstat -tlnp 2/dev/null | grep 端口 || ss -tlnp 2/dev/null | grep 端口 # 精确端口 sudo ss -tlnp | grep :端口1.2 应用层确认接口本身能通预期{code:500, msg:无法获取到access_token}# 接口是否响应:最大运行时间10s curl -s --max-time 10 http://域名和端口/interface/getUserDetails -H Content-Type: application/json -d {code:test123}1.3 网络层确定服务器到微信外网预期超时 / 连不上 / 443 不通 → 服务器到微信外网被防火墙/安全组拦了这是网络问提# 连接微信服务器 curl -s -o /dev/null -w HTTP %{http_code},耗时 %{time_total}s\n --max-time 10 https://qyapi.weixin.qq.com/cgi-bin/gettoken # DNS 解析 nslookup qyapi.weixin.qq.com # 443端口 TCP 连通 向 qyapi.weixin.qq.com 的 443 端口发送一个空消息 timeout 5 bash -c echo /dev/tcp/qyapi.weixin.qq.com/443 2/dev/null echo 443端口 通 || echo 443端口 不通1.4 server上测试secret# 查看打包文件中的具体值 01 echo; echo 3. 线上 jar 里内嵌的 corpsecret JAR$(ls *.jar 2/dev/null | head -1) echo 检查的jar: $JAR unzip -p $JAR 2/dev/null | grep -a -o corpsecret[A-Za-z0-9_-]* | sort -u # 查看打包文件中的具体值 02 unzip -p $JAR 2/dev/null | grep -a -o corpsecret[A-Za-z0-9_-]* | sort -u # 有效secret获取access_token 01 curl https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpidyyycorpsecretxxx # 有效secret获取access_token 02 curl -s --max-time 10 https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpidyyycorpsecretxxx | head -c 200如果获取到多个secret逐个使用gettoken测试判断哪个有效。1.5 查看日志预期确认内部调微信失败的步骤确认顺序如下先拿到 access_token (code是否有效不影响)再对code进行校验最后获取用户信息查看获取access_token附近的日志# 第一次接口 curl -s http://域名和端口/interface/getUserDetails -H Content-Type: application/json -d {code:test123} # 查看日志 tail -50 /data/service/jfxx-web-test/logs/*.log 2/dev/null测试是否获取到access_token如果接收code参数之后没有任何日志说明当前程序只有进入方法时才打日志gettoken附近无日志输出。可直接使用 curl https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpidyyycorpsecretxxx 判断secret二、验证修复结果通过浏览器验证的预期获取code浏览器可跳转到http://域名:端口/?codeXXXXXXXXstate#/Home无守卫时# 浏览器中发出请求获取Code https://open.weixin.qq.com/connect/oauth2/authorize?appidyyyredirect_urihttp%3A%2F%2F域名%3A端口%2F%23%2FHomeresponse_typecodescopesnsapi_baseagentid应用ID#wechat_redirect # 方式一微信官方API只测试code获取用户信息 curl https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token你的tokencode刚拿的code # 方式二测试后台将code传过去获取用户信息 curl http://域名和端口/interface/getUserDetails -H Content-Type: application/json -d {code:刚拿到的code}通过非浏览器验证的预期前提是非OAuth登录流程可绕过微信校验# 排查 secret 是否修复 curl -s http://127.0.0.1:端口/interface/getUserDetails -H Content-Type: application/json -d {userId:xxx}
返回列表