byte[] date = "<?xml version=\"1.0\" encoding=\"GBK\"?><CMS><eb><pub><TransCode>TEST</TransCode><CIS>400090001604411</CIS><BackCode>671</BackCode><ID>rp.y.4000</ID><TranDate>2017-05-04</TranDate><TranTime>145922111222</TranTime><fSeqno>201705041458123</fSeqno></pub><in><AccNo>4000023029200124946</AccNo><AreaCode>SZFH</AreaCode><MinAmt>1</MinAmt><MaxAmt>100000000</MaxAmt></in></eb></CMS>".getBytes();
ICBC i = ICBC.getICBC();
Enterprise e = Enterprise.getEnterprise();
String version = "0.0.0.1";
String bank_code = e.getBankcode();
String group_code = e.getCis();
byte[] signature = null;
String certificatename = null;
byte[] certificate = null;
String tran_code = "perdis";
String id = "rp.y.0200";//请根据实际修改证书名称
String body = new String(date);
boolean signflag = false;//交易是否需要签名,根据实际交易修改或者配置
byte[] key = null;
try
{
key = TranslationTool.readFile(e.getKey());
}
catch (IOException e2)
{
System.out.println("无法读取企业数据层私钥文件");
return;
}
char[] password = e.getKeypass().toCharArray();
try
{
signature = ReturnValue.sign(date, date.length, key, password);
}
catch (Exception e3)
{
System.out.println("无法生成签名");
return;
}
try
{
certificatename = e.getCerfile();
}
catch (Exception e4)
{
System.out.println("没有配置企业数据层公钥文件");
return;
}
try
{
FileInputStream fii = new FileInputStream(new File(e.getCerfile()));
certificate = new byte[fii.available()];
fii.read(certificate);//私钥
fii.close();
}
catch (IOException e4)
{
manage.DivScreen("","无法读取配置企业数据层公钥文件",80);
return;
}
PostMethod mypost = new PostMethod("/servlet/ICBCCMPAPIReqServlet?userID=rp.y.4000&PackageID=201705041458123&SendTime=145922111222");
mypost.addParameter("Version", version);
mypost.addParameter("GroupCIS", group_code);
mypost.addParameter("BankCode", bank_code);
mypost.addParameter("TransCode", tran_code);
if (signflag){//需要签名做以下操作,否则放明文
String length = String.valueOf(body.length());
if (length.length() <= 10)
length = ("0000000000").substring(0,10-length.length())+ length;//长度补齐10位,左补0
body = length + body + "ICBCCMP" + getrevFromBASE64(signature);
}
mypost.addParameter("reqData", getrevFromBASE64(body.getBytes()));//请根据实际修改上送包xml数据
mypost.addParameter("ID", id);
mypost.addParameter("PackageID", "201705041458123");//要求永远不能重复,可以参考接口文档的说明
mypost.addParameter("Cert", getrevFromBASE64(certificate));
try
{
Protocol myhttps =
new Protocol(
"https",
new AuthSSLProtocolSocketFactory(
null,
null,
new URL("file:" + i.getTruststore()),
null),
443);
HttpConnection myconn =
new HttpConnection(i.getIp(), Integer.parseInt(i.getPort()), myhttps);
myconn.open();
int re_code = mypost.execute(new HttpState(), myconn);
if (re_code==200)
{
manage.DivScreen("","已成功发送一笔 "+"perdis",80);
String repMsg = mypost.getResponseBodyAsString();
String ssspMsg = mypost.getResponseBodyAsString();
manage.DivScreen("","已接收到返回信息 "+ssspMsg,80);
}
else
{
manage.DivScreen("","发送失败,http错误码"+re_code,80);
}
}
catch (MalformedURLException e1)
{
manage.DivScreen("","无法读取工行通讯层证书",80);
}
catch (Exception e1)
{
System.out.println(e1);
manage.DivScreen("","通讯异常",80);
}
}
建立不了连接
每次 跑起来总是报java.net.UnknownHostException: https://cmpgtcg3.dccnet.com.cn错误,到底是问题出在哪里,求解!
还有这个应该怎么做,希望有人教一下。必有重谢