工行API查询接口 JAVA
最近调个工行的API查询,工行提供了个JKS证书,同时提供了4个JAVA类,我运行JAVA类里面的main方法,但是报了个错Untrusted Server Certificate Chain(证书不被信任),然后我在浏览器上装了相关证书,用form表单提交,就能够收到返回信息,但是通过main方法运行还是不行。工行的联调人员也说不出个所以然。求哪位大神做过工行的API查询的进来下,帮忙看看.
FROM提交,只要装上工行提供的PFX,CRT证书就可以查询
<Form id=form1 action="https://corporbank3.dccnet.com.cn/servlet/ICBCINBSEBusinessServlet" method=post>
<input type=hidden name="APIName" value="EAPI">
<input type=hidden name="APIVersion" value="001.001.001.001">
<input type=hidden name="MerReqData" value="<?xml version='1.0' encoding='GBK' standalone='no'?><ICBCAPI><in><orderNum>2013041237549012</orderNum><tranDate>20130502</tranDate><ShopCode>1202EC13482192</ShopCode><ShopAccount>1202020419900157535</ShopAccount></in></ICBCAPI>">
<input type="submit" value="查询">
</Form>
main方法也是工行提供
public static void main(String[] args) throws Exception {
String path = "file:"
+ ICBCUtil.class.getClassLoader().getResource("icbc/my.jks")
.getPath();
Protocol authhttps = new Protocol("https",
new AuthSSLProtocolSocketFactory(new URL(path), "12345678",
new URL(path), "12345678"), 8443);
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost("corporbank3.dccnet.com.cn", 443,
authhttps);
PostMethod httpget = new PostMethod("/servlet/ICBCINBSEBusinessServlet");
httpget.setParameter("APIName", "EAPI");
httpget.setParameter("APIVersion", "001.001.001.001");
httpget
.setParameter(
"MerReqData",
"<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\" ?><ICBCAPI><in><orderNum>2013041237549012</orderNum><tranDate>20130502</tranDate><ShopCode>1202EC13482192</ShopCode><ShopAccount>1202020419900157535</ShopAccount></in></ICBCAPI>");
client.executeMethod(httpget);
String str = java.net.URLDecoder.decode(httpget
.getResponseBodyAsString(), "GB2312");
System.out.println("server responding code :"
+ httpget.getStatusLine().toString());
System.out.println("server responding body :"
+ httpget.getResponseBodyAsString());
System.out.println("server responding body :" + str);
}
}
但是报错
Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Untrusted Server Certificate Chain
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1591)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1035)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:124)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:623)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:502)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at com.ai.tss.util.icbc.SSLSendAndRec.main(SSLSendAndRec.java:52)
Caused by: java.security.cert.CertificateException: Untrusted Server Certificate Chain
at com.sun.net.ssl.X509TrustManagerJavaxWrapper.checkServerTrusted(SSLSecurity.java:600)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1027)
... 17 more