Online Book Mall 9--payment Module

Source: Internet
Author: User

1. Payment Preparation

Public String Paymentpre (httpservletrequest req, HttpServletResponse resp) throws Servletexception, IOException { Req.setattribute ("Order", Orderservice.load (Req.getparameter ("OID")); return "f:/jsps/order/pay.jsp";}

2. Payment method

Public String Payment (httpservletrequest req, HttpServletResponse resp) throws Servletexception, IOException { Properties props = new properties ();p rops.load (This.getclass (). getClassLoader (). getResourceAsStream (" Payment.properties "));/* * 1. Prepare 13 parameters */string P0_cmd = "Buy";//business type, fixed value buystring P1_merid = Props.getproperty ("P1_merid");//trade name code, unique identifier in ePRO String p2_ Order = Req.getparameter ("oid");//order code String P3_amt = "0.01";//Payment amount of string p4_cur = "CNY";//transaction currency, fixed value cnystring p5_pid = ""; Commodity name string p6_pcat = "";//commodity type string p7_pdesc = "";//Commodity Description String P8_url = Props.getproperty ("P8_url");//After successful payment, ePRO will access this address. String p9_saf = "";//shipping address string pa_mp = "";//Extended information string pd_frpid = Req.getparameter ("YH");//payment channel string pr_needresponse = " 1 "///response mechanism, fixed value 1/* * 2. Calculation of HMAC * requires 13 parameters * requires KeyValue * requires encryption algorithm */string KeyValue = Props.getproperty ("KeyValue");  String HMAC = Paymentutil.buildhmac (P0_cmd, P1_merid, P2_order, P3_amt,p4_cur, P5_pid, P6_pcat, P7_pdesc, P8_Url, P9_SAF, Pa_mp,pd_frpid, Pr_needresponse, KeyValue);* * 3. Redirect to Easy Treasure Payment gateway */stringbuilder SB = new StringBuilder ("Https://www.yeepay.com/app-merchant-proxy/node"); Sb.append ("?"). Append ("p0_cmd="). Append (P0_cmd) sb.append ("&"). Append ("p1_merid="). Append (P1_merid); Sb.append ("&"). Append ("p2_order="). Append (P2_order) sb.append ("&"). Append ("p3_amt="). Append (P3_amt); Sb.append ("&"). Append ("p4_cur="). Append (p4_cur) sb.append ("&"). Append ("p5_pid="). Append (P5_pid); Sb.append ("&"). Append ("p6_pcat="). Append (P6_pcat) sb.append ("&"). Append ("p7_pdesc="). Append (P7_pdesc); Sb.append ("&"). Append ("P8_url="). Append (P8_url) sb.append ("&"). Append ("p9_saf="). Append (P9_saf); Sb.append ("&"). Append ("Pa_ Mp= "). Append (PA_MP), Sb.append (" & "). Append (" pd_frpid= "). Append (Pd_frpid); Sb.append (" & "). Append (" Pr_ Needresponse= "). Append (Pr_needresponse), Sb.append (" & "). Append (" hmac= "). Append (HMAC); Resp.sendredirect ( Sb.tostring ()); return null;}

3. Feedback method

When payment is successful, easy treasure will visit here
Access in two ways:
1. Guide the user's browser redirection (if the user closes the browser, it cannot be accessed here)
2. The server will use point-to-point communication method to access this method. (Must give back to success, otherwise the easy treasure Server will always call this method)

Public String Back (httpservletrequest req, HttpServletResponse resp) throws Servletexception, IOException {/* * 1. Get 12 parameters */string P1_merid = Req.getparameter ("P1_merid"); String r0_cmd = Req.getparameter ("R0_cmd"); String R1_code = Req.getparameter ("R1_code"); String R2_trxid = Req.getparameter ("R2_trxid"); String R3_amt = Req.getparameter ("R3_amt"); String r4_cur = Req.getparameter ("R4_cur"); String r5_pid = Req.getparameter ("R5_pid"); String R6_order = Req.getparameter ("R6_order"); String R7_uid = Req.getparameter ("R7_uid"); String R8_MP = Req.getparameter ("R8_mp"); String R9_btype = Req.getparameter ("R9_btype"); String HMAC = Req.getparameter ("HMAC");/* * 2. Get keyvalue */properties props = new Properties ();p rops.load (This.getclass (). getClassLoader (). getResourceAsStream (" Payment.properties ")); String KeyValue = Props.getproperty ("KeyValue");/* * 3. Call Paymentutil's Checksum method to verify the identity of the caller * > If the checksum fails: Save error message, forward to msg.jsp * > If Check pass: * * Determine whether the method of access is redirected or Point-to-point, if redirected * Modify order Status , save success message, forward to msg.jsp * * If it is a point-to-point: Modify order status, return success */boolean bool = Paymentutil.verifycallback (HMAC, P1_merid, R0_cmd, R1_code, R2_trxid,r3_amt, R4_cur, R5_pid, R6_order, R7_uid, R8_MP, R9_btype,keyvalue), if (!bool) {Req.setattribute ("code", "error"); Req.setattribute ("msg", "Invalid signature, payment failed!") (You are not a good person); return "f:/jsps/msg.jsp";} if (R1_code.equals ("1")) {Orderservice.updatestatus (R6_order, 2), if (R9_btype.equals ("1")) {Req.setattribute ("Code" , "Success"); Req.setattribute ("msg", "Congratulations, Payment succeeded!") "); return" f:/jsps/msg.jsp ";} else if (R9_btype.equals ("2")) {Resp.getwriter (). Print ("Success");}} return null;}

 

4.pay.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "GBK"%><%@ taglib prefix= "C" uri= "/HTTP/ Java.sun.com/jsp/jstl/core "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

  

Payment.properties

p1_merid=10001126856keyvalue=69cl522av6q613ii4w6u8k6xuw8vm1n6bfgyv769220iuye9u37n4y7ri4plp8_url=http\:// Localhost\:8080/goods/orderservlet?method\=back

  

 

  

  

Online Book Mall 9--payment Module

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.