One, the online payment is divided into two cases, one method is to use direct and bank payment interface, the other way is to use a third-party payment platform and bank docking to complete payment.
1. Direct and bank docking.
2. Use of third-party payment platforms
3. Common third-party payment platforms
Second, the use of ePRO payment interface to implement the Java online payment function (ABC).
1. Full source code:https://github.com/kdyzm/day21_2_pay
2. Timing diagram of the implementation process
3. Technical Highlights
(1) All parameters must be taken with the GET request, parameter names refer to the request parameter list in the developer documentation
(2) Use the Paymentutil class for encryption, which is written by Ebaotech payment Company
(3) After the payment is successful, notify the Merchant button that the URL is local, that is, http://localhost:8080/backServlet (localhost only makes sense locally), why it can be successfully returned here, the principle of the above flowchart. Key point: Redirection technology solves this problem.
4. A few information required.
(1) Merchant account: p1_merid=10001126856
(2) Keyvaue:keyvalue=69cl522av6q613ii4w6u8k6xuw8vm1n6bfgyv769220iuye9u37n4y7ri4pl of the merchant
(3) Paymentutil class.
Packagecom.kdyzm.utils;Importjava.io.UnsupportedEncodingException;Importjava.security.MessageDigest;Importjava.security.NoSuchAlgorithmException;Importjava.util.Arrays; Public classPaymentutil {Private StaticString encodingcharset = "UTF-8"; /*** Generate HMAC method * *@paramp0_cmd Business Type *@paramP1_merid Merchant Number *@paramP2_order Merchant Order number *@paramP3_amt Payment Amount *@paramp4_cur Currency of transaction *@paramp5_pid Product Name *@paramP6_pcat Product Type *@paramP7_pdesc Product Description *@paramP8_url Merchant receives the address of the payment success data *@paramP9_SAF Shipping Address *@paramPA_MP Merchant Extension information *@parampd_frpid Bank Code *@parampr_needresponse response mechanism *@paramkeyValue Merchant Key *@return */ Public Staticstring Buildhmac (String p0_cmd,string P1_merid, String p2_order, String P3_amt, String p4_cur,string p5_pi D, String p6_pcat, String p7_pdesc,string p8_url, String p9_saf,string pa_mp,string pd_frpid, string Pr_needresponse,string keyValue) {StringBuilder svalue=NewStringBuilder (); //type of Businesssvalue.append (P0_cmd); //Merchant Numbersvalue.append (P1_merid); //Merchant Order Numbersvalue.append (P2_order); //Amount Paidsvalue.append (P3_amt); //Currency of transactionsvalue.append (p4_cur); //Product Namesvalue.append (p5_pid); //Product Typesvalue.append (P6_PCAT); //Product Descriptionsvalue.append (P7_PDESC); //The merchant receives the address of the payment success datasvalue.append (P8_url); //Shipping Addresssvalue.append (P9_SAF); //Merchant Extension Informationsvalue.append (PA_MP); //Bank Codesvalue.append (pd_frpid); //Response mechanismsvalue.append (Pr_needresponse); returnpaymentutil.hmacsign (svalue.tostring (), keyValue); } /*** Return to check the HMAC method * *@paramThe cryptographic verification code sent by the HMAC payment gateway *@paramP1_merid Merchant Number *@paramr0_cmd Business Type *@paramR1_code Payment Results *@paramR2_TRXID epro Payment Transaction serial number *@paramR3_amt Payment Amount *@paramr4_cur Currency of transaction *@paramr5_pid Product Name *@paramR6_order Merchant Order number *@paramR7_uid EPRO Payment Member ID *@paramR8_MP Merchant Extension information *@paramr9_btype Transaction result return type *@paramKeyValue Key *@return */ Public Static Booleanverifycallback (String HMAC, String P1_merid, String r0_cmd, String R1_code, String R2_trxid, String R3_amt , string r4_cur, String r5_pid, String R6_order, String r7_uid, String r8_mp, String r9_btype, Strin G keyValue) {StringBuilder svalue=NewStringBuilder (); //Merchant Numbersvalue.append (P1_merid); //type of Businesssvalue.append (R0_cmd); //Payment Resultssvalue.append (R1_code); //ePRO Payment transaction serial numbersvalue.append (R2_TRXID); //Amount Paidsvalue.append (R3_amt); //Currency of transactionsvalue.append (r4_cur); //Product Namesvalue.append (r5_pid); //Merchant Order Numbersvalue.append (R6_order); //EPRO Payment Member IDsvalue.append (R7_UID); //Merchant Extension Informationsvalue.append (R8_MP); //transaction result return typesvalue.append (R9_btype); String snewstring=paymentutil.hmacsign (svalue.tostring (), keyValue); returnsnewstring.equals (HMAC); } /** * @paramAvalue *@paramAkey *@return */ Public Staticstring Hmacsign (String avalue, String akey) {byteK_ipad[] =New byte[64]; byteK_opad[] =New byte[64]; bytekeyb[]; bytevalue[]; Try{keyb=akey.getbytes (Encodingcharset); Value=avalue.getbytes (Encodingcharset); } Catch(unsupportedencodingexception e) {keyb=akey.getbytes (); Value=avalue.getbytes (); } arrays.fill (K_ipad, Keyb.length,64, (byte) 54); Arrays.fill (K_opad, Keyb.length,64, (byte) 92); for(inti = 0; i < keyb.length; i++) {K_ipad[i]= (byte) (Keyb[i] ^ 0x36); K_opad[i]= (byte) (Keyb[i] ^ 0x5c); } messagedigest MD=NULL; Try{MD= Messagedigest.getinstance ("MD5"); } Catch(nosuchalgorithmexception e) {return NULL; } md.update (K_ipad); Md.update (value); byteDg[] =md.digest (); Md.reset (); Md.update (K_opad); Md.update (DG,0, 16); DG=md.digest (); returnTohex (DG); } Public StaticString Tohex (byteinput[]) { if(Input = =NULL) return NULL; StringBuffer Output=NewStringBuffer (Input.length * 2); for(inti = 0; i < input.length; i++) { intCurrent = Input[i] & 0xff; if(Current < 16) Output.append ("0"); Output.append (integer.tostring (Current,16)); } returnoutput.tostring (); } /** * * @paramargs *@paramKey *@return */ Public Staticstring Gethmac (string[] args, string key) {if(args = =NULL|| Args.length = = 0) { return(NULL); } stringbuffer str=NewStringBuffer (); for(inti = 0; i < args.length; i++) {str.append (args[i]); } return(Hmacsign (str.tostring (), key)); } /** * @paramAvalue *@return */ Public StaticString Digest (String avalue) {Avalue=Avalue.trim (); bytevalue[]; Try{Value=avalue.getbytes (Encodingcharset); } Catch(unsupportedencodingexception e) {value=avalue.getbytes (); } messagedigest MD=NULL; Try{MD= Messagedigest.getinstance ("SHA"); } Catch(nosuchalgorithmexception e) {e.printstacktrace (); return NULL; } returnTohex (Md.digest (value)); } //Public static void Main (string[] args) {//System.out.println (Hmacsign ("Annulcard1000043252120080620160450.0http://localhost/szxpro/callback.asp http? 4564868265473632445648682654736324511 "," 8UPP0KE8SQ73ZVP370VKO7C39403RTK1YWX40TD6IRH216036H27EB12792T "));// }}
Paymentutil.java
(4) Note: The Merchant account is a teacher's account of the Wisdom Podcast, when the test will actually hit the money in the past, so in the choice to pay the amount of time to be cautious!!!
5. Payment Process:
(1) Fill in the order information
(2) After clicking the Payment button, redirect to the ABC Payment interface ( If the speed is slow to see the process of epro payment processing).
(3) I'm doing a K-yard payment.
(4) Fill in the appropriate information, after the authentication (SMS), click the OK button (Google Browser does not support the subsequent operation, I changed IE browser)
(5) Payment success, automatically jump to the payment success page
(6) Click the Notify Merchant button to jump to the same page.
Iii. Summary
1, Java implementation of online payment function is not difficult, almost no technical points, the key is too cumbersome, to learn to read the developer documentation.
2. Redirection technology is important here to understand the use of redirects in terms of timing diagrams.
"Java EE Learning on the 21st day using the ePRO payment interface to implement the Java online payment function"