itlaowang 2016-10-18 03:56 采纳率: 0%
浏览 7645
已结题

微信支付HttpHostConnectException:443问题

自从14号微信服务器升级后,我们后台就开始时不时的出现该错误,百度了也没有相关解决办法,我们之前是http请求,现在改成了https请求还是有这个错误
下面是https请求的代码

 KeyStore keyStore = KeyStore.getInstance("PKCS12");
        FileInputStream instream = new FileInputStream(new File(keyPath + 
                "apiclient_cert.p12"));//加载本地的证书进行https加密传输
        try {
            keyStore.load(instream, password.toCharArray());//设置证书密码
        } finally {
            instream.close();
        }

        // Trust own CA and all self-signed certs
        SSLContext sslcontext = SSLContexts.custom()
                .loadKeyMaterial(keyStore, password.toCharArray())
                .build();
        // Allow TLSv1 protocol only
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                sslcontext,
                new String[]{"TLSv1"},
                null,
                SSLConnectionSocketFactory.
                                BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);

        String result = null;

        HttpPost httpPost = new HttpPost(url);

        //得指明使用UTF-8编码,否则到API服务器XML的中文不能被成功识别
        StringEntity postEntity = new StringEntity(postDataXML, "UTF-8");
        httpPost.addHeader("Content-Type", "text/xml");
        httpPost.setEntity(postEntity);
        RequestConfig   requestConfig = RequestConfig.custom()
                .setConnectionRequestTimeout(socketTimeout)
                .setSocketTimeout(socketTimeout)
                .setConnectTimeout(connectTimeout).build();
        //设置请求器的配置
        httpPost.setConfig(requestConfig);

        LOGGER.info("executing request" + httpPost.getRequestLine());

        try {
            CloseableHttpClient httpClient =  HttpClients.custom()
                    .setSSLSocketFactory(sslsf).build();

            HttpResponse response = httpClient.execute(httpPost);

            HttpEntity entity = response.getEntity();

            result = EntityUtils.toString(entity, "UTF-8");

        } finally {
            httpPost.abort();
        }

        return result;

下面是错误

  ERROR com.wfj.pay.pp.service.impl.WeChatPayServiceImpl [DubboServerHandler-10.6.3.78:20902-thread-199] org.apache.http.conn.HttpHostConnectException: Connect to api.mch.weixin.qq.com:443 [api.mch.weixin.qq.com/123.151.71.149, api.mch.weixin.qq.com/123.151.79.109] failed: Connection refused
org.apache.http.conn.HttpHostConnectException: Connect to api.mch.weixin.qq.com:443 [api.mch.weixin.qq.com/123.151.71.149, api.mch.weixin.qq.com/123.151.79.109] failed: Connection refused
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.3.jar:4.3]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) ~[httpclient-4.3.jar:4.3]
        at com.wfj.pay.pp.util.wechatpay.WeChatPayUtils.sendPost(WeChatPayUtils.java:94) ~[pp-service-impl.jar:na]
        at com.wfj.pay.pp.service.impl.WeChatPayServiceImpl.doWeChatPay(WeChatPayServiceImpl.java:335) [pp-service-impl.jar:na]
        at com.wfj.pay.pp.service.impl.WeChatPayServiceImpl$2.buildHtmlForm(WeChatPayServiceImpl.java:279) [pp-service-impl.jar:na]
        at com.wfj.pay.pp.service.AbstractPayService.prepareToPay(AbstractPayService.java:253) [pp-service-impl.jar:na]
        at com.wfj.pay.pp.service.impl.WeChatPayServiceImpl.doMobileWeChatPay(WeChatPayServiceImpl.java:263) [pp-service-impl.jar:na]
        at com.wfj.pay.pp.service.impl.WeChatPayServiceImpl$$FastClassByCGLIB$$a8040c40.invoke(<generated>) [spring-core-3.2.3.RELEASE.jar:na]
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) [spring-aop-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.2.3.RELEASE.jar:3.2.3.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) [spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]

求大神指导啊,天天异常处理的快疯了, 求大神指导谢谢了,跪谢

  • 写回答

3条回答 默认 最新

  • zqbnqsdsmd 2016-10-20 03:24
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示