该用户从未签到
|
网上支付是电子支付的一种形式,它是通过第三方提供的与银行之间的支付接口进行的即时支付方式,这种方式的好处在于可以直接把资金从用户的银行卡中转账到网站账户中,汇款马上到账,不需要人工确认。客户和商家之间可采用信用卡、电子钱包、电子支票和电子现金等多种电子支付方式进行网上支付,采用在网上电子支付的方式节省了交易的开销。
- N. J# X4 C% V- K1 k* }' s$ I5 \9 {4 L- package com.cjg.servlet;
/ Y% }% I4 K) r) V: i4 R- m - % d% m8 m3 f. o5 w8 d" ?
- import java.io.IOException;
8 z' H ?$ x3 F+ G& c - 9 |/ ~7 d/ f! ]; R$ X' h
- import javax.servlet.ServletException;! a- p, D+ F9 ?/ I
- import javax.servlet.http.HttpServlet;1 w+ \5 z. P y& C4 A( E V' M
- import javax.servlet.http.HttpServletRequest;# I9 w5 r& o; H# M1 }& z- \
- import javax.servlet.http.HttpServletResponse;
/ V. ~5 d: T G+ W
' O. @# d( ?8 \6 `, f+ A4 B O- import com.cjg.tool.ReadConfigInfo;4 r9 J$ a' k8 q8 p, N' o. q
- import com.cjg.tool.PanyMoneyTool;
7 f h6 Z8 A( r, ` - * k4 o" d! ?, U! I
- /**0 F! W/ ~8 r7 s2 _( D( n4 ?& e; C* U
- * 响应银行支付结果请求* G$ Y9 N: J3 x* H7 |+ m7 C
- * @author科帮网
7 h5 C7 |: Z- p7 r; O6 x - *
. H; ^. V$ S$ `1 E% b - */% B+ R" T/ Y3 P
- public class PayMoneyResultResponse extends HttpServlet {
# f) i5 @4 p' ?4 s4 O" E$ k, L- K - ; Z" `5 I! ?; o$ _" d( @
- public void doGet(HttpServletRequest request, HttpServletResponse response)
8 f6 t, Q+ J7 j9 H, m - throws ServletException, IOException {
; C" |" J4 M, v0 N {; D% M - this.doPost(request, response);( b6 V* U3 x. E
- }
6 @# J. U# U" u6 H
7 H9 j$ T# [) ?/ R" R8 y- public void doPost(HttpServletRequest request, HttpServletResponse response)
% v0 I ?# s. D - throws ServletException, IOException {
+ {4 ~. w, T! ?! s4 h. ~; Q - request.setCharacterEncoding("GBK");* w9 C( t4 _+ j! s% H* N& R& U
- String merchantID = ReadConfigInfo.getValue("p1_MerId"); // 商家ID
- C3 l! A" N7 S) o, S* S - String keyValue = ReadConfigInfo.getValue("keyValue"); // 商家密钥: [+ i3 i9 v1 r0 O. k8 I
- 7 O/ \ Y4 Z$ W! d7 M% w' X
- String sCmd = request.getParameter("r0_Cmd"); //业务类型
- r# H1 [% V. j: A/ s& \. \" t - String sResultCode = request.getParameter("r1_Code"); //扣款结果,该字段值为1时表示扣款成功.
# V1 a/ G) i1 t) \+ ` - String sTrxId = request.getParameter("r2_TrxId"); //YeePay易宝交易订单号; @: g0 r2 a+ j0 J
- String amount = request.getParameter("r3_Amt");//扣款金额,交易结束后,YeePay易宝交易系统将实际扣款金额返回给商户- x/ L- \" l7 ]
- String currency = request.getParameter("r4_Cur");//交易币种,人民币为CNY$ T$ Y$ L$ E) b& n& u. @, l2 `
- String productId = request.getParameter("r5_Pid");//商品ID. K! k3 W/ ~8 ~8 x3 [( z2 a; C$ {7 D) i
- String orderId = request.getParameter("r6_Order");//商户订单号
9 _1 |8 ?: S2 @, b - String userId = request.getParameter("r7_Uid");//YeePay易宝会员ID4 ?' A% P, C1 a) e, a
- String mp = request.getParameter("r8_MP");//商户扩展信息,可以任意填写1K 的字符串,交易返回时将原样返回& Y; k0 K& b t; j" m
- String bType = request.getParameter("r9_BType");//交易结果通知类型,1: 交易成功回调(浏览器重定向)2: 交易成功主动通知(服务器点对点通讯): v1 w4 a. J+ k a
- String rb_BankId = request.getParameter("rb_BankId");//支付银行4 l3 E! ?( a6 v
- String rp_PayDate = request.getParameter("rp_PayDate");//在银行支付时的时间
, T5 P8 i5 W4 B* Z - String hmac = request.getParameter("hmac");//MD5交易签名) h6 P; l D+ W2 t4 `
- 5 S# M; W0 d5 M( _5 B7 s
- boolean result = PanyMoneyTool.verifyCallback(hmac, merchantID, sCmd, sResultCode, sTrxId, amount,+ k6 Y q4 d7 X3 A# e% P- }
- currency, productId, orderId, userId, mp, bType, keyValue);0 {- K, d8 D+ X; Q- }$ C' d
- if(result){
( E# e: v: i4 ^7 x - if("1".equals(sResultCode)){0 ^7 ^. N+ x3 A3 g. T V
- //你们这个地方应该把数据库中订单的支付状态设置成已经支付.
' f5 C4 {8 g: ~/ ?0 f- q - String message = "订单号为:"+ orderId+ "的订单支付成功了";
; ]: u( Q2 e2 q' S0 L6 s - message += ",用户支付了"+ amount +"元";
. m! x5 |0 b& M! O! Z2 w, S+ A - message +=",交易结果通知类型:";3 H+ u5 W1 i( ^1 B6 W! |2 _( B
- if("1".equals(bType)){* s# M1 e8 A3 n \% h4 [' P) f# o$ H
- message += "浏览器重定向";
* ]$ s% W; @" U4 k' o3 {% I - }else if("2".equals(bType)){
+ J d: H9 N1 t+ R( d* w( k- [ - message += "易宝支付网关后台程序通知";3 U4 L# E5 ~5 S- l8 W
- }( o8 s$ A' U4 y. k9 n3 d
- message += ",易宝订单系统中的订单号为:"+ sTrxId;
1 g6 E4 W* N; X/ Z - request.setAttribute("message", message);+ m$ G4 z! M) d4 A
- }else{/ K) O7 g3 f% _8 V1 S8 X
- request.setAttribute("message", "用户支付失败");( V- m R5 R9 m) ^+ ~4 X+ p; Q" h
- }% i q, T% l7 \% v
- }else{
8 S* u1 e' _0 B+ d - request.setAttribute("message", "数据来源不合法");& X% l8 W! G& E2 n6 ]# O
- }2 ], l; A! q N o% p6 g0 f% R/ R
- request.getRequestDispatcher("/WEB-INF/page/payMoneyResult.jsp").forward(request, response);
% Q) D9 A! t% t - }
3 [" Q% @. m2 e( _; _0 s+ o) s
) C# W3 a& @" ?" u0 s, k- }& i$ m0 L9 l) _( m7 G; n$ H6 d
复制代码 资料下载地址:点击下载 {# o# L5 w, ^- f T# Y
/ w+ N, @0 l9 W- s$ j
# ]/ ~+ L/ |- b' j |
|