How to get your Java system to use the payment interface

Source: Internet
Author: User
Tags hmac

Yesterday took a long time to learn the payment interface of the teaching, I saw the first 7 episodes, it is enough, we surf the internet to search for a podcast online payment is good.

1. Initially there is a form form

2. This form he helped you write well, there are many banks, the name of the bank is specific

3. This form to be submitted, the tutorial is to use the servlet, I use struts2, the principle is similar, that is, to deal with the transaction after the jump, servlet processing function and the dao+action in struts is similar

4. After submission, to define some properties, some properties if your form is uploaded, then use some means to get it, if you do not assign a value you will be assigned to him.

5. He has an encryption class that you use when assigning values to a property. This property is called Md5hmac,

6. These attributes are then uploaded to another form, which is to jump to the payment interface, which is not to be seen by the user (I use the JS language to set this form autocommit)

7. In the end, you will be redirected to this payment page

Note:

1. This need to have two attributes, such as the first two, is the need for this enterprise to provide to you, my this expired, I use the time to jump to the page, but can not use

2. Encryption class

1  /**2   * @paramAvalue3   * @return4   */5   Public StaticString Digest (String avalue) {6Avalue =Avalue.trim ();7   bytevalue[];8   Try {9Value =avalue.getbytes (encodingcharset);Ten}Catch(unsupportedencodingexception e) { OneValue =avalue.getbytes (); A   } -MessageDigest MD =NULL; -   Try { theMD = Messagedigest.getinstance ("SHA"); -}Catch(nosuchalgorithmexception e) { - e.printstacktrace (); -    return NULL; +   } -   returnTohex (Md.digest (value)); +  A  } at   - //Public static void Main (string[] args) { - //System.out.println (Hmacsign ("Annulcard1000043252120080620160450.0http://localhost/szxpro/callback.asp This -  -4564868265473632445648682654736324511 "," 8upp0ke8sq73zvp370vko7c39403rtk1ywx40td6irh216036h27eb12792t ")); - // } in } ----------------------- tob./payment/src/com/credream/utils/Panymentutil.java +   Packagecom.credream.utils; -  the  Public classPanymentutil { *  /** $ * Generate HMAC methodPanax Notoginseng   * -   * @paramp0_cmd Business Type the   * @paramP1_merid Merchant Number +   * @paramP2_order Merchant Order number A   * @paramP3_amt Payment Amount the   * @paramp4_cur Transaction Currency +   * @paramP5_pid Product Name -   * @paramP6_pcat Product Categories $   * @paramP7_pdesc Product Description $   * @paramP8_url Merchant receives the address of the payment success data -   * @paramP9_SAF Shipping Address -   * @parampa_mp Merchant Extension information the   * @paramPd_frpid Bank Code -   * @parampr_needresponse Response mechanismWuyi   * @paramKeyValue Merchant Key the   * @return -   */ Wu   Public Staticstring Buildhmac (String p0_cmd,string p1_merid, - string P2_order, String P3_amt, String p4_cur,string p5_pid, string p6_pcat, About string p7_pdesc,string p8_url, String p9_saf,string pa_mp,string pd_frpid, $ String pr_needresponse,string KeyValue) { -StringBuffer svalue =NewStringBuffer (); -   //type of Business - svalue.append (p0_cmd); A   //Merchant Number + svalue.append (P1_merid); the   //Merchant Order Number - svalue.append (p2_order); $   //Amount Paid the svalue.append (P3_amt); the   //Currency of transaction the svalue.append (p4_cur); the   //Product Name - svalue.append (p5_pid); in   //Product Type the svalue.append (p6_pcat); the   //Product Description About svalue.append (P7_PDESC); the   //The merchant receives the address of the payment success data the svalue.append (p8_url); the   //Shipping Address + svalue.append (P9_SAF); -   //Merchant Extension Information the svalue.append (PA_MP);Bayi   //Bank Code the svalue.append (pd_frpid); the   //Response mechanism - svalue.append (pr_needresponse); -    theString snewstring =digestutil.hmacsign (svalue.tostring (), keyValue); the   returnsnewstring; the  } the   -  /** the * Return to check the HMAC method the   * the   * @paramThe cryptographic verification code sent by the HMAC payment gateway94   * @paramP1_merid Merchant Number the   * @paramr0_cmd Business Type the   * @paramR1_code Payment Results the   * @paramR2_TRXID epro Payment transaction serial number98   * @paramR3_amt Payment Amount About   * @paramr4_cur Transaction Currency -   * @paramR5_pid Product Name101   * @paramR6_order Merchant Order number102   * @paramR7_uid epro payment member ID103   * @paramr8_mp Merchant Extension information104   * @paramr9_btype Transaction result return type the   * @paramKeyValue Key106   * @return107   */108   Public Static Booleanverifycallback (String HMAC, String P1_merid,109 string R0_cmd, String R1_code, String R2_trxid, String R3_amt, the string r4_cur, String r5_pid, String R6_order, String r7_uid,111 string r8_mp, String R9_btype, String keyValue) { theStringBuffer svalue =NewStringBuffer ();113   //Merchant Number the svalue.append (P1_merid); the   //type of Business the svalue.append (r0_cmd);117   //Payment Results118 svalue.append (r1_code);119   //ePRO Payment transaction serial number - svalue.append (R2_TRXID);121   //Amount Paid122 svalue.append (R3_amt);123   //Currency of transaction124 svalue.append (r4_cur); the   //Product Name126 svalue.append (r5_pid);127   //Merchant Order Number - svalue.append (r6_order);129   //EPRO Payment Member ID the svalue.append (r7_uid);131   //Merchant Extension Information the svalue.append (R8_MP);133   //transaction result return type134 svalue.append (r9_btype);135String snewstring =digestutil.hmacsign (svalue.tostring (), keyValue);136 137   if(Hmac.equals (snewstring)) {138    return true;139   } $   return false;141  }142}

3. Remember that you need to use the enterprise-given test environment to pay the URL when you debug

4. Some of the videos I watch, you try to see

How to get your Java system to use the payment interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.