该用户从未签到
|
网上支付是电子支付的一种形式,它是通过第三方提供的与银行之间的支付接口进行的即时支付方式,这种方式的好处在于可以直接把资金从用户的银行卡中转账到网站账户中,汇款马上到账,不需要人工确认。客户和商家之间可采用信用卡、电子钱包、电子支票和电子现金等多种电子支付方式进行网上支付,采用在网上电子支付的方式节省了交易的开销。
+ |6 X9 I- @' ^1 t6 }; Y- package com.cjg.servlet;/ J, O# `% ]9 ^# m, x) l
- 2 E% s- a6 h [3 l. w9 d; j# m( a
- import java.io.IOException;
. T$ u! v. u2 W' u" g& J5 G
! [" A! |3 p. V1 z- import javax.servlet.ServletException;
6 I6 L- v& g5 l s3 j- }0 N - import javax.servlet.http.HttpServlet;
( S2 |, Y2 ?% V# L9 A - import javax.servlet.http.HttpServletRequest;/ k' o* h& P) I
- import javax.servlet.http.HttpServletResponse;: Y: J& x% Z k* J! u
y0 ]$ z( `! m- import com.cjg.tool.ReadConfigInfo;
# H |8 Q0 m+ u$ T* @/ r - import com.cjg.tool.PanyMoneyTool;! a* L5 E# P' Q5 ~- U2 Y' t
8 C" Y8 Y% n" d" E% F! Z1 E- /**# Q5 x: `+ M. ] T6 D. `: I! r- ]; r
- * 响应银行支付结果请求
3 O+ ~$ \9 s* |# H1 e! s _ - * @author科帮网! W% T9 }, o8 N) l
- *
4 j3 a S3 o' ^" n2 b: _. n, \ - */
t( k: [1 Q3 K& X6 | - public class PayMoneyResultResponse extends HttpServlet { d& f6 {; A' p, c, z
5 R0 o4 x1 z1 c' N- public void doGet(HttpServletRequest request, HttpServletResponse response)
$ O9 t0 n, @ y$ G& ] - throws ServletException, IOException {
. j) [$ ?3 Z; j4 O5 J - this.doPost(request, response);
) N* o* I9 c* `' m - }
5 x1 z+ ` z' @$ s0 Q# g
* D3 M% k8 b. a9 h4 t3 f- public void doPost(HttpServletRequest request, HttpServletResponse response)
y% k" Z( P2 A) t: \ - throws ServletException, IOException {
+ h, r& v+ W1 I- e1 F& s - request.setCharacterEncoding("GBK");4 w5 ?/ M% E2 C) y1 }* n
- String merchantID = ReadConfigInfo.getValue("p1_MerId"); // 商家ID! H2 [. {$ O% ]& [+ R
- String keyValue = ReadConfigInfo.getValue("keyValue"); // 商家密钥
1 t% {: Q5 i; K4 D( s - 6 x+ p/ ^, H2 P6 w* m& n2 \2 `0 [6 s
- String sCmd = request.getParameter("r0_Cmd"); //业务类型0 S) t7 F8 Q( ]
- String sResultCode = request.getParameter("r1_Code"); //扣款结果,该字段值为1时表示扣款成功.0 ^; o7 u( I3 r" f9 Y$ O
- String sTrxId = request.getParameter("r2_TrxId"); //YeePay易宝交易订单号
" v/ i. F7 p3 \. Q1 t% e) i - String amount = request.getParameter("r3_Amt");//扣款金额,交易结束后,YeePay易宝交易系统将实际扣款金额返回给商户
! R/ p9 A1 Z$ M0 M9 G- Q2 E - String currency = request.getParameter("r4_Cur");//交易币种,人民币为CNY- }' i5 Z. E: k
- String productId = request.getParameter("r5_Pid");//商品ID
% Q) K9 w- O. E1 \ - String orderId = request.getParameter("r6_Order");//商户订单号
R9 Z8 z' N0 {8 }4 y& ^; _ - String userId = request.getParameter("r7_Uid");//YeePay易宝会员ID
: U$ d; V1 t7 a+ m) K - String mp = request.getParameter("r8_MP");//商户扩展信息,可以任意填写1K 的字符串,交易返回时将原样返回
5 l" u; |1 @, c: s- z9 D - String bType = request.getParameter("r9_BType");//交易结果通知类型,1: 交易成功回调(浏览器重定向)2: 交易成功主动通知(服务器点对点通讯)1 X; _" I2 l0 D8 v. B
- String rb_BankId = request.getParameter("rb_BankId");//支付银行2 R! i$ e6 Z6 ^
- String rp_PayDate = request.getParameter("rp_PayDate");//在银行支付时的时间
2 p D/ J, }/ }3 ` - String hmac = request.getParameter("hmac");//MD5交易签名6 |9 l9 L; H" r6 R) L: H4 b% j
- * B& @4 r0 {8 t- ^/ i
- boolean result = PanyMoneyTool.verifyCallback(hmac, merchantID, sCmd, sResultCode, sTrxId, amount,
! g2 ^# t8 j/ G& @* } - currency, productId, orderId, userId, mp, bType, keyValue);; v' Y3 A% j$ Q, [- t5 @4 Y
- if(result){4 a! O7 c( H5 R: @+ R3 z
- if("1".equals(sResultCode)){
& E h& h6 p3 u" C9 y* m - //你们这个地方应该把数据库中订单的支付状态设置成已经支付.8 j: ]9 h2 h2 E/ F" `8 W5 D
- String message = "订单号为:"+ orderId+ "的订单支付成功了"; r5 C8 U, C- n
- message += ",用户支付了"+ amount +"元";% L# d. k0 L( g. b* H' k
- message +=",交易结果通知类型:";% M0 P7 w2 P' j8 b- T O
- if("1".equals(bType)){
( {8 L. |8 X: b - message += "浏览器重定向";
: }9 S% r' j! T' A5 B - }else if("2".equals(bType)){4 C% X. [% x1 z$ Q5 a
- message += "易宝支付网关后台程序通知";
4 i: I Q( |5 n# H - }
$ \; z9 W2 |/ j - message += ",易宝订单系统中的订单号为:"+ sTrxId;
" g* w1 c! H: P5 ?6 y5 ^6 J+ M1 |5 } - request.setAttribute("message", message);
% O8 l7 E. i, }7 E3 @( F2 x4 V, S - }else{4 B* a b/ C6 p& ]. n( _
- request.setAttribute("message", "用户支付失败");
7 a; n7 B7 b: k& ] - }) z4 I4 D/ j$ f# j2 ]" H. J4 b; o
- }else{! \. {- m1 y: R5 {3 E* n& M( u: h
- request.setAttribute("message", "数据来源不合法");
) t$ q3 `: \) d4 a& F - }
2 M3 ?: e9 s2 B: T* C1 d2 V8 | - request.getRequestDispatcher("/WEB-INF/page/payMoneyResult.jsp").forward(request, response);
0 v# r: {& l2 B - }
. K i# V$ }1 m' D+ ?( W - 3 n- b" F1 D: \( b( c
- }
1 U' S/ E+ L, t
复制代码 资料下载地址:点击下载
3 ]( W5 L- }- Z3 P! Z* d3 T1 T" y/ _" C1 j# u
* f0 C# _8 N T+ t; k
|
|