问题已解决: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1 别自己写sdk, 用微信提供的sdk demo
443 failed to respond,谁有demo吗?事情的经过: 支付查询接口都ok, 退款接口一直报443错误, 重新更新了一下证书,还是不行。 1 没有异常,证书也没有过期。 2 mac环境, 用的绝对路径 3 给自己的系统使用的, 也无所谓服务商模式 哪位大神已经踩过该坑, 给指导一下 java代码: /** * 设置ssl */ SSLConnectionSocketFactory sslsf = null; try{ //注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 KeyStore keyStore = KeyStore.getInstance("PKCS12"); //指向你的证书的绝对路径,带着证书去访问 FileInputStream instream = new FileInputStream(new File(SSL_CERT_PATH));//P12文件目录 try { //下载证书时的密码、默认密码是你的MCHID mch_id keyStore.load(instream, CxpConstants.MCHID.toCharArray());//这里写密码 }catch (Exception e){ e.printStackTrace(); }finally { instream.close(); } //下载证书时的密码、默认密码是你的MCHID mch_id SSLContext sslcontext = SSLContexts.custom() .loadKeyMaterial(keyStore, CxpConstants.MCHID.toCharArray())//这里也是写密码的 .build(); // Allow TLSv1 protocol only sslsf = new SSLConnectionSocketFactory( sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }catch (Exception e){ e.printStackTrace(); logger.error("init httpclient ssl exception", e); } client = HttpClients.custom() .setConnectionManager(cm) .setDefaultRequestConfig(requestConfig) .setRedirectStrategy(defaultRedirectStrategy) //当连接空闲五分钟的时候, 就会被断掉 .evictIdleConnections(5l, TimeUnit.MINUTES) //启动一个后台线程去收集expired的connection .evictExpiredConnections() .setSSLSocketFactory(sslsf) .build(); } public static String sendXmlPost(String url, String paramXml){ logger.info(getTraceId() + "HttpUtil#sendXmlPost param: " + url + " " + paramXml); HttpPost httpPost = new HttpPost(url); httpPost.setHeader(HTTP.CONTENT_TYPE,"application/xml; charset=UTF-8"); StringEntity paramEntity = new StringEntity(paramXml,"UTF-8"); httpPost.setEntity(paramEntity); try { CloseableHttpResponse response = client.execute(httpPost); if (response == null){ logger.error(getTraceId() + "HttpUtil#sendXmlPost response is null================"); return null; } if (response.getStatusLine().getStatusCode() == 200){ String ret = EntityUtils.toString(response.getEntity(),"UTF-8"); logger.info(getTraceId() + "HttpUtil#sendXmlPost response: " + ret); return ret; } logger.info(getTraceId() + " HttpUtil#sendXmlPost statusCode is " + response.getStatusLine().getStatusCode()); } catch (IOException e) { e.printStackTrace(); logger.error(getTraceId() + "HttpUtil#sendXmlPost exception: ",e); } logger.error(getTraceId() + "HttpUtil#sendXmlPost ret null================"); return null; } =========================================Exception==================================== org.apache.http.NoHttpResponseException: api.mch.weixin.qq.com:443 failed to respond at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) at org.apache.…….DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) at com.cxp.server.common.util.HttpUtil.sendXmlPost(HttpUtil.java:120) at com.cxp.server.service.wechat.WeChatPayService.execute(WeChatPayService.java:112) at com.cxp.server.service.wechat.WeChatPayService.refund(WeChatPayService.java:75) at com.cxp.server.control.TestControl.main(TestControl.java:58)
2019-03-28