1, the public key and bank card number and password, such as the Banking Association provided, the private key in accordance with the documentation provided by UnionPay can be, need to explain the application is to use IE, and in the Internet option--> security--> customization level,
Change all disables under active X controls and Plug-ins to Enabled, as shown in the figure:
2, the test site provided by the UnionPay landing, as shown:
3, enter the login information, the first login needs to modify the password, and then login, select the organization management, generate merchant key, as shown:
4, select the generated private key path, save, remember the key point submit button, the private key effective the next day.
5, under the SRC Create config.properties files, which store merchant number, payment gateway application, public and private key storage path, such as:
Merid = xxxxxxxxxxxxxxxx
Merkeyfilepath = e\:\\key\\xxx
Pubkeyfilepath = e\:\\key\\xxx
URL = Http://XXXXXXXXX
6, the application of the servlet:
private static final String Merid = "Merid";
private static final String paymenturl = "url";
private static final String Merkeyfilepath = "Merkeyfilepath";
public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Request.setcharacterencoding ("UTF-8");
String merkeypath = null;
String Merid = null;
String msg= "";
try{
Properties config = config.getinstance (). GetProperties ();
Merkeypath = Config.getproperty (Merkeyfilepath);
Merid = Config.getproperty (Merid);
}catch (Exception e) {
msg= "Private key initialization failed. ";
}
if (msg!= "") {
Request.setattribute ("Errors", msg);
Request.getrequestdispatcher (XXXXX). Forward (request, response);
Return
}
String ordid= "0000000000000001";//The order number can only be submitted once
String transamt= "000000000001";//Amount
String curyid= "156";//Currency
String transdate= "20150601";//Date
String transtype= "0001";//Type
String version= "20070129";//Version
String bgreturl= "Http://XXXXXXXXX";/Background action
String pagereturl= "http://xxxxx.jsp";//Foreground JSP
String gateid= "";
String priv1 = "";
String chkvalue = null;
Boolean flage= false;
Privatekey key = new Privatekey ();
try{
Flage= Key.buildkey (merid, 0, Merkeypath);
}catch (Exception e) {
System.out.print ("Create failed");
}
Signature
String Data=merid+ordid+transamt+curyid+transdate+transtype+priv1;
Securelink SL = new Securelink (key);
Chkvalue = sl. Sign (data);
Display the data to be submitted to the page
Bean cbb=new bean ();
Cbb.setmerid (Merid);
Cbb.setordid (Ordid);
Cbb.settransamt (Transamt);
Cbb.setcuryid (CuryID);
Cbb.settransdate (transdate);
Cbb.settranstype (Transtype);
CBB.SETPRIV1 (PRIV1);
Cbb.setversion (version);
Cbb.setbgreturl (Bgreturl);
Cbb.setpagereturl (Pagereturl);
Cbb.setgateid (Gateid);
Cbb.setchkvalue (Chkvalue);
Request.setattribute ("Cbbinput", CBB);
Request.getrequestdispatcher (XXXXXXXX). Forward (request, response);
Return
}
public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
DoPost (Request,response);
}
7, the above servlet jumps to the following page:
<%@ page language= "java" import= "model.bean.*" pageencoding= "UTF-8"%>
<%@ page import= "java.util.*"%>
<jsp:usebean id= "Cbbinput" scope= "request" class= "model. Bean "/>
<form name= "Corpor" action= "Test commit path" method= "POST"
<input type= "hidden" name= "Merid" XXXXX "/>
<input type=" hidden "name=" Ordid "value=" xxxx "/>
<input type=" hidden "name=" Transamt "value=" xxx/>
<input type= "hidden" name= "CuryID" value= "xxx"/>
<input type= "Hidden" name= "transdate" value= "xxx"/>
<input type= "hidden" name= "Transtype" value= "xxx"/>
& nbsp <input type= "hidden" name= "Version" value= "xxx"/>
<input type= "hidden" name= "Bgreturl" value= "xxx" />
<input type= "hidden" name= "Pagereturl" value= "xxx"/>
<input type= "hidden" name= " Gateid "value=" xxxx/>
<input type= "hidden name=" Priv1 "value=" "/>
<input type=" Hidden "name=" "Chkvalue" value= "xxxx"/>
<input type= "Submit" name= "submit Button" value= "submitted" class= "cmd "/>
</form>
8, click Submit, will go to the Enterprise Network Silver Landing page, as shown:
9, input card number and password landing, will prompt the transaction result, as shown:
10, Pagereturl for the above page jump back to the site page, Bgreturl for the background action, used to verify and save the data, the servlet is as follows:
private static final String url = "url";
private static final String Merkeyfilepath = "Merkeyfilepath";
private static final String Pubkeyfilepath = "Pubkeyfilepath"; public void DoPost (HttpServletRequest request, httpservletresponse response) &NB Sp Throws Servletexception, IOException { request.setcharacterencoding ("UTF-8"); & nbsp / Get server return data */ ST
Ring Status=request.getparameter ("status");
String merid=request.getparameter ("Merid");
String ordno=request.getparameter ("OrderNo");
String transdate=request.getparameter ("TransDate");
String amount=request.getparameter ("Amount"); String currencycode=request.getparameter ("cuRrencycode ");
String transtype=request.getparameter ("Transtype");
String checkvalue=request.getparameter ("CheckValue");
String gateid=request.getparameter ("Gateid");
String priv1=request.getparameter ("Priv1");
// string s=readreqstr (Request); //Here data is stored in the database //Check in String Pubkeypath
= NULL; try { Properties config = config.getinstance (). GETPR
Operties ();
Pubkeypath = Config.getproperty (Pubkeyfilepath); } catch (Exception e) { } Chinapay. Privatekey key=new Chinapay.
Privatekey (); Chinapay.
Securelink T;
Boolean flage=false; &nBsp
Boolean flage1=false;
int int = 0; try{ Flage=key.buildkey ("999999999999999", Int,pubke
Ypath);
}catch (Exception e) { } if (!flage) {
Return } t=new Chinapay.
Securelink (key); Flage1=t.verifytransresponse (Merid,ordno,amount,currencycode,transdate,transtype,
Status,checkvalue); if (!flage1) { system.out.print ("Check Failure");
// return; }else{ if (Status.equals ("1001")) { &nbs P
System.out.print ("payment success"); }else { &NBSP
System.out.print ("Payment failure"); } }
Tell UnionPay you've received the news, or the federation will keep sending messages.
Resp.getwriter (). Write (Json.tojsonstring (cpcyberbankres));
Resp.getwriter (). Flush ();
public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexc eption {doPost (request,response); }
Payment test code Complete ....