该用户从未签到
|
网上支付是电子支付的一种形式,它是通过第三方提供的与银行之间的支付接口进行的即时支付方式,这种方式的好处在于可以直接把资金从用户的银行卡中转账到网站账户中,汇款马上到账,不需要人工确认。客户和商家之间可采用信用卡、电子钱包、电子支票和电子现金等多种电子支付方式进行网上支付,采用在网上电子支付的方式节省了交易的开销。
3 y$ Z" q* L" s- L2 m' g" {- package com.cjg.servlet;
5 |3 H2 `3 X2 t8 |
5 @/ j/ h. O& ?: s+ p8 |# @2 l2 f' h0 |: u- import java.io.IOException;6 E: e9 e+ Q7 y# m# w& ^0 ~
( _: B+ }( Q, o( N- import javax.servlet.ServletException;- p* v8 k! O- t: F6 m7 J. E
- import javax.servlet.http.HttpServlet;& Z8 _5 ~8 H) `
- import javax.servlet.http.HttpServletRequest;/ w2 r G8 |8 {. ]( f# Q2 V7 d5 Z* i
- import javax.servlet.http.HttpServletResponse;( {6 d" D3 v! ?1 U, o
- ; b0 s+ R4 F5 K6 A- u; ~: I
- import com.cjg.tool.ReadConfigInfo;
1 c |6 F: k7 Q6 J( `( u - import com.cjg.tool.PanyMoneyTool;
! G" \, N* o! t# x6 s8 i3 z# f
. p& E0 W g/ Q9 z5 m; \9 F- /**
: |+ h2 B! I* M3 Z1 M - * 响应银行支付结果请求
8 K" ^ }$ T8 M& d; x4 P7 F - * @author科帮网( M& | B( S% [& {6 U) K
- *0 R3 e) @( T1 D+ K2 r
- */
. G1 d) r, d& R( `' b% o; f - public class PayMoneyResultResponse extends HttpServlet {. F* z' S8 n7 C$ h* b# A$ S
- * T! r, R. N2 V
- public void doGet(HttpServletRequest request, HttpServletResponse response)8 {3 l1 `3 A+ b- e4 I: S
- throws ServletException, IOException {2 L$ P$ U( [* d) J7 s" w. i, _
- this.doPost(request, response);4 {' E5 P/ V: B; {0 _/ h8 r. Z
- }
/ C" l) `2 s- k) } y$ J" M- d - . l4 T& g5 |+ Y& `& z( |' k
- public void doPost(HttpServletRequest request, HttpServletResponse response)$ C; t; X8 y5 c) W
- throws ServletException, IOException {: J0 r7 p4 P( F7 n/ d: r
- request.setCharacterEncoding("GBK");
9 e9 R$ Y: F. U5 b2 X7 d( ^ - String merchantID = ReadConfigInfo.getValue("p1_MerId"); // 商家ID5 c% x6 K$ c8 ~1 a" A- h& r! G
- String keyValue = ReadConfigInfo.getValue("keyValue"); // 商家密钥+ O( s8 @4 g- Y! O9 ^% W
- ; p5 ?1 e: I9 x" Q$ I, Z3 N5 L
- String sCmd = request.getParameter("r0_Cmd"); //业务类型- Z1 M3 L( j5 q) ~' V. G
- String sResultCode = request.getParameter("r1_Code"); //扣款结果,该字段值为1时表示扣款成功.
6 O; G' G4 C6 @. @ - String sTrxId = request.getParameter("r2_TrxId"); //YeePay易宝交易订单号
- S1 k$ a. U, d- Z. P7 b8 h3 I - String amount = request.getParameter("r3_Amt");//扣款金额,交易结束后,YeePay易宝交易系统将实际扣款金额返回给商户% e7 A f3 I; W( ?$ ]
- String currency = request.getParameter("r4_Cur");//交易币种,人民币为CNY/ P- f: |2 ?1 |4 X* Z* S% M
- String productId = request.getParameter("r5_Pid");//商品ID
" F- J) D9 U4 {& _$ _; ? - String orderId = request.getParameter("r6_Order");//商户订单号
$ v$ a: M/ h4 Z - String userId = request.getParameter("r7_Uid");//YeePay易宝会员ID
$ h: K8 T$ s2 r( ~; b3 c - String mp = request.getParameter("r8_MP");//商户扩展信息,可以任意填写1K 的字符串,交易返回时将原样返回
- t0 o9 U$ e$ Y1 V1 L! v/ Y) k x - String bType = request.getParameter("r9_BType");//交易结果通知类型,1: 交易成功回调(浏览器重定向)2: 交易成功主动通知(服务器点对点通讯)! O, o7 }! f- E
- String rb_BankId = request.getParameter("rb_BankId");//支付银行
C' |! w6 t1 ?* @/ z, g" l - String rp_PayDate = request.getParameter("rp_PayDate");//在银行支付时的时间
# |3 Q: G" p l' I. U - String hmac = request.getParameter("hmac");//MD5交易签名
& f4 [) Y: c7 b5 s( i: V- y+ \ -
( z" v& F0 u m - boolean result = PanyMoneyTool.verifyCallback(hmac, merchantID, sCmd, sResultCode, sTrxId, amount,! [' B, u) C( {, a! P5 M; b9 J- W7 u
- currency, productId, orderId, userId, mp, bType, keyValue);
4 V. {0 F- x/ [. F - if(result){* K. Y$ A) T$ W" B' @& R3 K/ h8 ]
- if("1".equals(sResultCode)){) |& z: {. J& U+ Z5 u& r
- //你们这个地方应该把数据库中订单的支付状态设置成已经支付.
- }4 k0 a6 q J* O: K, \ - String message = "订单号为:"+ orderId+ "的订单支付成功了";
% w; }9 J0 C; q - message += ",用户支付了"+ amount +"元";' j4 k, e" A" j8 N
- message +=",交易结果通知类型:";8 n* V- k' E, z; ^
- if("1".equals(bType)){
/ l! I2 I( N" y/ E* s6 C7 i4 v7 { - message += "浏览器重定向";
4 L: u9 a' \: T+ _+ o - }else if("2".equals(bType)){* N3 { L. X( [: f5 ?
- message += "易宝支付网关后台程序通知";
& \, N1 B1 r% i: c/ c7 L( G - }
0 @5 N9 H; S! v& ~2 j/ U - message += ",易宝订单系统中的订单号为:"+ sTrxId;
* W7 C/ ~, ^* Y+ z8 X, p' \ - request.setAttribute("message", message);8 c% H: x0 \4 O/ m; R# g9 G& F1 X& Z
- }else{
3 }: F4 A _& K" m/ b - request.setAttribute("message", "用户支付失败");
* h- r4 N5 E& ^+ G0 L0 N - }; p$ y+ T1 V- j6 k/ s
- }else{) P- Y+ y! ?" i" ^ g3 A p7 F, |) \
- request.setAttribute("message", "数据来源不合法");( J1 \" D; Q' ~. _
- }
' \: k- j" i9 I" a* H2 H7 V - request.getRequestDispatcher("/WEB-INF/page/payMoneyResult.jsp").forward(request, response);
) h2 s9 }4 v2 [7 M - }0 z5 G' U8 N* M( }3 c& e; ?6 T
" x. R( V' ], S0 F2 k- }: [3 L4 W* m* Y: H: X K7 \
复制代码 资料下载地址:点击下载
6 Z$ ]1 b" _5 k+ p" U5 G$ {; E8 L0 }1 l3 G6 A
1 I: {) o% M3 v( C$ i, I0 ] |
|