自从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]
求大神指导啊,天天异常处理的快疯了, 求大神指导谢谢了,跪谢