收藏
回答

获取手机号/wxa/business/getuserphonenumber时间过长,导致超时

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug 获取手机号 微信安卓客户端 8.0.61 3.8.11
public static HttpResponse doPostOfQRCode(String url, String outStr)  {
    log.info("发送请求");
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost httpost = new HttpPost(url);
    httpost.setEntity(new StringEntity(outStr, "UTF-8"));//使用setEntity方法,将我们传进来的参数放入请求中
    int maxRetries = 3;
    for (int i = 0; i < maxRetries; i++) {
        try {
            long start = System.currentTimeMillis();
            HttpResponse response = client.execute(httpost);
            log.info("请求耗时:{}ms", System.currentTimeMillis() - start);
            log.info("请求数据:"+ "返回:"+JSONObject.toJSONString(response));
            return response;
        }catch (SocketTimeoutException e){
            if (i<maxRetries-1){
                log.info("第"+(i+1)+"次");
                try {
                    Thread.sleep(1000 * (i + 1));
                } catch (InterruptedException ex) {
                    throw new RuntimeException(ex);
                }
            }else{
                log.error("请求超时:{}", e.getMessage());
            }
        }catch (IOException e){
            log.error("网络异常:{}", e.getMessage());
        }
    }
    return null;
}


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

1 个回答

  • 第三方平台小助手
    第三方平台小助手
    2025-07-23

    你好,请优先排查下网络原因,稍后重试接口

    2025-07-23
    有用
    回复
登录 后发表内容