该用户从未签到
|
网上支付是电子支付的一种形式,它是通过第三方提供的与银行之间的支付接口进行的即时支付方式,这种方式的好处在于可以直接把资金从用户的银行卡中转账到网站账户中,汇款马上到账,不需要人工确认。客户和商家之间可采用信用卡、电子钱包、电子支票和电子现金等多种电子支付方式进行网上支付,采用在网上电子支付的方式节省了交易的开销。! w; {; A! u* s9 c6 q; M1 m
- package com.cjg.servlet;
3 g7 Y1 [4 v: z% M' Q ]( |
' w( d" {! S) M" V5 o- F- import java.io.IOException;8 v1 l- }$ t0 R2 ^
( G) u J" e$ x& s [- import javax.servlet.ServletException;8 i0 Q# I& G. B
- import javax.servlet.http.HttpServlet;
' n7 [; X; P0 K4 I1 D; X - import javax.servlet.http.HttpServletRequest;
& [1 k% I0 T+ B0 ~! q P - import javax.servlet.http.HttpServletResponse;8 D5 j4 ]/ k; f0 u, r, d2 l3 ^
" j5 I8 L2 Q9 \8 P1 ]3 \- import com.cjg.tool.ReadConfigInfo;
1 n4 J' A$ O0 y9 S" ? - import com.cjg.tool.PanyMoneyTool;2 A8 i8 o9 D7 m" z/ W) i* ?
- 6 Q0 Q9 A- o" L+ ~0 R k7 h+ p
- /**
1 c% O, ^! k$ P% }1 ^6 L1 `* D - * 响应银行支付结果请求# n3 t5 |: g+ Z2 i0 j
- * @author科帮网5 P, z' E& _2 i9 k
- *( }4 p$ c0 P- X5 ~; G; k
- */3 q9 A8 k' _& s5 I& Y
- public class PayMoneyResultResponse extends HttpServlet {+ ^- ~8 l1 t. q
- 2 O$ R$ l+ Y' \
- public void doGet(HttpServletRequest request, HttpServletResponse response)7 G0 p( u+ `+ n2 k! n0 l# ~0 O
- throws ServletException, IOException {
" w* @+ `9 Z! f4 F: O. R( R - this.doPost(request, response);2 S! t+ e- }+ @6 J
- }
) c& }& g" W$ r - ; L6 M. V5 b4 O G$ M& |
- public void doPost(HttpServletRequest request, HttpServletResponse response)
. ^ m. ?$ |) C3 k9 q. c) j - throws ServletException, IOException {
+ k4 \( ^( ~0 Z& l" l) d3 \ - request.setCharacterEncoding("GBK");
. n+ A% a7 {- U0 u9 G" X3 _ - String merchantID = ReadConfigInfo.getValue("p1_MerId"); // 商家ID
7 I$ K3 p, C0 C+ ^' G - String keyValue = ReadConfigInfo.getValue("keyValue"); // 商家密钥
/ J8 G1 G4 A# {% c( k: v' P7 h -
0 l2 s, u% z3 _6 @& ] - String sCmd = request.getParameter("r0_Cmd"); //业务类型7 j% y2 D0 h. B4 H. s& W
- String sResultCode = request.getParameter("r1_Code"); //扣款结果,该字段值为1时表示扣款成功.
9 F* P- C0 {2 g0 v1 x X/ K0 O - String sTrxId = request.getParameter("r2_TrxId"); //YeePay易宝交易订单号- p3 J0 m6 ?( G1 a f
- String amount = request.getParameter("r3_Amt");//扣款金额,交易结束后,YeePay易宝交易系统将实际扣款金额返回给商户
P9 L2 s3 V% Q0 `1 d9 P! Y" f - String currency = request.getParameter("r4_Cur");//交易币种,人民币为CNY
% ?1 T5 C* a) t8 o8 }2 O1 ?/ N4 D - String productId = request.getParameter("r5_Pid");//商品ID! D. V+ N6 e3 M& {' l& p1 k
- String orderId = request.getParameter("r6_Order");//商户订单号
& C- o7 y* d9 w- M% o - String userId = request.getParameter("r7_Uid");//YeePay易宝会员ID
. U, W' i! V% g - String mp = request.getParameter("r8_MP");//商户扩展信息,可以任意填写1K 的字符串,交易返回时将原样返回
3 L: s+ ?. j- p' L3 _- |" N- g - String bType = request.getParameter("r9_BType");//交易结果通知类型,1: 交易成功回调(浏览器重定向)2: 交易成功主动通知(服务器点对点通讯)" {, U" w' k* Q( h% T
- String rb_BankId = request.getParameter("rb_BankId");//支付银行
4 q) r" g# L# s! L0 R3 B; K9 Q - String rp_PayDate = request.getParameter("rp_PayDate");//在银行支付时的时间
& C. r# [# _' M$ `# l! ?: G) d( x3 v - String hmac = request.getParameter("hmac");//MD5交易签名" d6 I0 A/ `) q7 z0 n' i7 |! w
- 3 z6 `' {/ m: ~4 ~2 C
- boolean result = PanyMoneyTool.verifyCallback(hmac, merchantID, sCmd, sResultCode, sTrxId, amount,
* }& Z2 d1 N8 K! g: |0 e7 c% s+ i - currency, productId, orderId, userId, mp, bType, keyValue);: ^- }5 M. j5 m* ?1 [
- if(result){* y4 y4 N5 O! G( ]7 d
- if("1".equals(sResultCode)){
5 U8 V5 C/ W, j- ~ v - //你们这个地方应该把数据库中订单的支付状态设置成已经支付.
- f) [1 p" Y6 c, m4 H - String message = "订单号为:"+ orderId+ "的订单支付成功了";
7 u. a6 v' |3 P7 u- K! p$ C' ] - message += ",用户支付了"+ amount +"元";4 w2 t1 c" v/ X- j& k, Z! M4 A
- message +=",交易结果通知类型:";+ J0 t1 l. p) |
- if("1".equals(bType)){
! m: G' {" ~1 y7 \ - message += "浏览器重定向";, t) Y2 a, t. }5 {. I. B
- }else if("2".equals(bType)){
8 A, H( K: \7 S - message += "易宝支付网关后台程序通知";/ V/ ?; G" D% F* K
- }
* V* `# l* {9 w+ D- H, Y! X - message += ",易宝订单系统中的订单号为:"+ sTrxId;0 R. Q' N: Y( D; p$ g
- request.setAttribute("message", message);& Q8 A# c$ ^5 F$ x- Z
- }else{
o9 p5 O" `( S# V( K0 V - request.setAttribute("message", "用户支付失败");4 T) F9 ^( m) d3 x) V+ B6 j. ?
- }
# _. s( R% }8 J7 a) w5 o2 E+ d1 G; j6 f - }else{+ e- q2 `- @; W8 j3 R
- request.setAttribute("message", "数据来源不合法");
3 w) y5 G2 O& c3 ?" x - }% X5 J1 E* L' H7 ~1 ]% t
- request.getRequestDispatcher("/WEB-INF/page/payMoneyResult.jsp").forward(request, response);2 h0 S' A: M' v6 k) { D# T
- }7 `# Z1 M, _' Z+ N$ w1 @- A
- 1 ~! ~! [4 F) {! z( U3 `
- }, ~" d6 _2 m; f7 B O
复制代码 资料下载地址:点击下载( ^: ~$ a2 H4 f4 m5 L
3 k. M$ V+ i) c6 s7 T; y& ^8 W z( N" c; V! H6 M
|
|