收藏
回答

调用小程序授权接口很慢,在小程序上获取了code,调用授权接口,返回openid,可以怎么提速?

$code_url = 'https://api.weixin.qq.com/sns/jscode2session?appid=appid&secret=secret&js_code='.$code.'&grant_type=authorization_code';
$result = curl_get($code_url);
if (!isset($result['openid']) || $result['openid'] == ''){
            return ['code' => "0", 'msg' => '用户信息获取失败,请重新获取'];
        } else {
            return $result;
        }

调用接口如上,返回时间"wechat_ms":5.378,域名及ip已经配置了,使用政务云服务器,host指定了api.weixin.qq.com host

服务器

curl -o /dev/null -s -w "time_total: %{time_total}\n" \
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxx&secret=xxx"

curl很快,也就0.3秒,有没有办法提速?或者出现这种情况的原因是什么呢?

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

2 个回答

  • momo
    momo
    2025-12-26

    Start: 2025-12-26T14:42:32+0800

    HOST: 1.novalocal       Loss%   Snt   Last   Avg  Best  Wrst StDev

      1.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

      2.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

      3.|-- ???          0.0%    10    1.8   1.9   1.7   2.3   0.2

      4.|-- ???          0.0%    10    0.8   1.0   0.8   1.9   0.3

      5.|-- ???         0.0%    10    0.3   0.4   0.3   0.7   0.1

      6.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

      7.|-- ???       0.0%    10    3.5   5.9   2.2  21.5   5.7

      8.|-- ???    90.0%    10    1.7   1.7   1.7   1.7   0.0

      9.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     10.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     11.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     12.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     13.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     14.|-- 120.240.114.74    50.0%    10   28.3  28.4  28.2  28.7   0.2

     15.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     16.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     17.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     18.|-- ???               100.0    10    0.0   0.0   0.0   0.0   0.0

     19.|-- api.weixin.qq.com  0.0%     9   33.0  33.1  32.9  33.2   0.1

    2025-12-26
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    2025-12-26
    有用
    回复 2
    • momo
      momo
      2025-12-26
      curl --connect-timeout 1 \
      > --max-time 3 \
      > -o /dev/null -s \
      > -w "
      > DNS: %{time_namelookup}s
      > Connect: %{time_connect}s
      > TLS: %{time_appconnect}s
      > Total: %{time_total}s
      > \n" \
      > https://api.weixin.qq.com/...
      DNS: 0.000575s
      Connect: 0.029727s
      TLS: 0.098327s
      Total: 0.135714s
      2025-12-26
      回复
    • momo
      momo
      2025-12-26
      Start: 2025-12-26T14:42:32+0800
      HOST: 1.novalocal Loss% Snt Last Avg Best Wrst StDev
        1.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
        2.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
        3.|-- ??? 0.0% 10 1.8 1.9 1.7 2.3 0.2
        4.|-- ??? 0.0% 10 0.8 1.0 0.8 1.9 0.3
        5.|-- ??? 0.0% 10 0.3 0.4 0.3 0.7 0.1
        6.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
        7.|-- ??? 0.0% 10 3.5 5.9 2.2 21.5 5.7
        8.|-- ??? 90.0% 10 1.7 1.7 1.7 1.7 0.0
        9.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       10.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       11.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       12.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       13.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       14.|-- 120.240.114.74 50.0% 10 28.3 28.4 28.2 28.7 0.2
       15.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       16.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       17.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       18.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
       19.|-- api.weixin.qq.com 0.0% 9 33.0 33.1 32.9 33.2 0.1
      2025-12-26
      回复
登录 后发表内容