该用户从未签到
|
网上支付是电子支付的一种形式,它是通过第三方提供的与银行之间的支付接口进行的即时支付方式,这种方式的好处在于可以直接把资金从用户的银行卡中转账到网站账户中,汇款马上到账,不需要人工确认。客户和商家之间可采用信用卡、电子钱包、电子支票和电子现金等多种电子支付方式进行网上支付,采用在网上电子支付的方式节省了交易的开销。& e' F4 x8 n3 k1 i( w3 W& Y! w
- package com.cjg.servlet;
( f0 I3 D- B( W3 @
% D) z: v: ~3 ]9 ` W- import java.io.IOException;, {+ f9 `+ g& L, c9 W
- ) _% d/ H5 \5 f! v; @4 N
- import javax.servlet.ServletException;
+ O2 q) W; x- d: V1 F9 J. \ - import javax.servlet.http.HttpServlet;
2 H8 n( f5 B) v3 ` - import javax.servlet.http.HttpServletRequest;2 Y5 x# B6 q9 Y$ Y' V6 Z
- import javax.servlet.http.HttpServletResponse;4 l+ m5 i1 Z" G* s% q
- + P3 @! q$ ]$ M* [& U
- import com.cjg.tool.ReadConfigInfo;2 V R7 L' E. [6 P2 O1 M
- import com.cjg.tool.PanyMoneyTool;' \, x9 [. o1 d% Z; ^+ U" A
6 D0 H) u" x: G+ e3 `# W. ~- /**
+ o. g$ s1 M. W, [ - * 响应银行支付结果请求
. d, z; m# g" ]% d5 I& s* S - * @author科帮网9 z3 w/ V/ v N0 K& X2 |8 D2 g, _
- *
" j* a# k9 c5 e2 Z& f9 P' f - */
; c9 l- B( }* w, } - public class PayMoneyResultResponse extends HttpServlet {# P- d0 @: {- c$ ?
- 1 }% N) M/ U. n: Z; ]6 O
- public void doGet(HttpServletRequest request, HttpServletResponse response)
! ]7 D2 J/ C: ^" R4 n* a9 b - throws ServletException, IOException {
1 Q$ K$ F$ o/ f/ |6 s d - this.doPost(request, response);9 H& U0 K H* G) e- j0 G8 W; Z
- }
. v) C! q5 X5 B - ) L4 k/ \- R/ h/ C4 X& {% n
- public void doPost(HttpServletRequest request, HttpServletResponse response)( V: z. A* u4 n% A* f0 a9 G# w
- throws ServletException, IOException {+ K. \7 X! y" f7 u3 k3 p; y
- request.setCharacterEncoding("GBK");
& P W; Z$ r# ?1 [ - String merchantID = ReadConfigInfo.getValue("p1_MerId"); // 商家ID
3 ?! g7 P$ \6 v1 s; B' L/ r: x - String keyValue = ReadConfigInfo.getValue("keyValue"); // 商家密钥
2 [; r$ M+ c ~0 L6 o4 o7 K -
9 h% i7 G8 Z% T; s* G$ Z - String sCmd = request.getParameter("r0_Cmd"); //业务类型
1 T% c6 S. I- U( P - String sResultCode = request.getParameter("r1_Code"); //扣款结果,该字段值为1时表示扣款成功. L3 s) ?) a" T$ d
- String sTrxId = request.getParameter("r2_TrxId"); //YeePay易宝交易订单号2 J) d) R7 t* r* m
- String amount = request.getParameter("r3_Amt");//扣款金额,交易结束后,YeePay易宝交易系统将实际扣款金额返回给商户
( L2 ]/ W8 k# a5 ^ - String currency = request.getParameter("r4_Cur");//交易币种,人民币为CNY
5 d) \8 h# B6 V4 w - String productId = request.getParameter("r5_Pid");//商品ID
3 ]. [$ G( g0 v& r4 \6 O2 Z- h - String orderId = request.getParameter("r6_Order");//商户订单号$ z; `, _7 @$ G1 w5 N
- String userId = request.getParameter("r7_Uid");//YeePay易宝会员ID
$ U/ V* J: u7 O! X" o0 v& z* N" T - String mp = request.getParameter("r8_MP");//商户扩展信息,可以任意填写1K 的字符串,交易返回时将原样返回
8 H! k3 b9 N- q% U( s$ X: R - String bType = request.getParameter("r9_BType");//交易结果通知类型,1: 交易成功回调(浏览器重定向)2: 交易成功主动通知(服务器点对点通讯)
/ O/ _0 z5 I# w4 | - String rb_BankId = request.getParameter("rb_BankId");//支付银行
/ i; {; g& o5 o0 T0 z, ^- O4 K- Q - String rp_PayDate = request.getParameter("rp_PayDate");//在银行支付时的时间
" p/ [' i" \* N1 U( O( u+ r5 i - String hmac = request.getParameter("hmac");//MD5交易签名0 v) `, Y6 c. @, l3 }/ L0 N1 H2 b
-
1 c* _1 a5 {% t7 s* ]) w - boolean result = PanyMoneyTool.verifyCallback(hmac, merchantID, sCmd, sResultCode, sTrxId, amount,: s+ J* B9 M$ O/ z8 b# S
- currency, productId, orderId, userId, mp, bType, keyValue);0 C# a' |* i8 A" y
- if(result){' A. z' Z6 I0 x6 y% p& D
- if("1".equals(sResultCode)){/ i, L! k! b9 c2 _* Y/ j8 C
- //你们这个地方应该把数据库中订单的支付状态设置成已经支付." Q# X9 r0 i' |5 Y$ f' Y& x; @
- String message = "订单号为:"+ orderId+ "的订单支付成功了";
/ Q; W( k b: e7 k1 X2 j; J - message += ",用户支付了"+ amount +"元";
0 b+ x9 n; J+ I5 B; B f - message +=",交易结果通知类型:";" r- }+ [) M5 w& F8 Q3 K5 b9 g
- if("1".equals(bType)){, o4 w! J: w" ?$ Z$ R8 h& ]
- message += "浏览器重定向";$ ~/ b+ M; b8 e9 d: H R* K/ a1 B" [
- }else if("2".equals(bType)){: l) q, q+ J) ?- g2 @; k
- message += "易宝支付网关后台程序通知";
$ H/ z7 R1 ~3 r6 |; M4 a4 f - }
- S. A# R7 G4 r5 D - message += ",易宝订单系统中的订单号为:"+ sTrxId;
, v+ T% s8 x/ A - request.setAttribute("message", message);7 {0 W% i. Q( s$ y
- }else{6 V. f6 x7 a. m3 W, V. w
- request.setAttribute("message", "用户支付失败");5 ?% I: t- z% E) Y4 x) @7 Q
- }
- Z8 C2 @4 K& Q7 ~0 u, G+ h# l% u P" Z - }else{
+ c: E @4 E' `6 G# e - request.setAttribute("message", "数据来源不合法");5 s+ G" H: b$ ^; @
- }
2 l* A; E0 o! J! e8 R2 Q - request.getRequestDispatcher("/WEB-INF/page/payMoneyResult.jsp").forward(request, response); X( m1 |. }. a3 W; N
- }, z% a7 W$ i/ a4 }4 N- [
% G8 R* {3 b& u; k6 _; d- }# q# i8 O6 F) |* R
复制代码 资料下载地址:点击下载- I7 \: Y1 T; b7 A5 G' x& h
7 \' ]) U; \3 f
; J+ R: Z Z4 }5 z' y. b |
|