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

微信支付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 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决