国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術(shù)及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - javaweb在線支付功能實現(xiàn)代碼

javaweb在線支付功能實現(xiàn)代碼

2020-09-08 10:37第九種格調(diào)的人生 Java教程

這篇文章主要為大家詳細介紹了javaweb在線支付功能的實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了javaweb在線支付功能的具體實現(xiàn)代碼,供大家參考,具體內(nèi)容如下

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.learning.web.servlet;
 
import java.io.IOException;
import java.util.ResourceBundle;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.learning.utils.PaymentUtil;
 
@WebServlet("/payOnline")
public class PayOnline extends HttpServlet {
  private static final long serialVersionUID = 1L;
    
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      doPost(request, response);
  }
 
 
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
    String orderid = request.getParameter("orderid");
    String money = request.getParameter("money");
    
        // 銀行
        String pd_FrpId = request.getParameter("pd_FrpId");
 
        // 發(fā)給支付公司需要哪些數(shù)據(jù)
        String p0_Cmd = "Buy";
        String p1_MerId = ResourceBundle.getBundle("/WEB-INF/classes/merchantInfo").getString(
            "p1_MerId");
        String p2_Order = orderid;
        String p3_Amt = money;
        String p4_Cur = "CNY";
        String p5_Pid = "";
        String p6_Pcat = "";
        String p7_Pdesc = "";
        // 支付成功回調(diào)地址 ---- 第三方支付公司會訪問、用戶訪問
        // 第三方支付可以訪問網(wǎng)址(本項目網(wǎng)址)
        String p8_Url = "http://115.170.37.189/day19pay/callback";
        String p9_SAF = "";
        String pa_MP = "";
        String pr_NeedResponse = "1";
        // 加密hmac 需要密鑰
        String keyValue = ResourceBundle.getBundle("merchantInfo").getString(
            "keyValue");
        String hmac = PaymentUtil.buildHmac(p0_Cmd, p1_MerId, p2_Order, p3_Amt,
            p4_Cur, p5_Pid, p6_Pcat, p7_Pdesc, p8_Url, p9_SAF, pa_MP,
            pd_FrpId, pr_NeedResponse, keyValue);
        // 生成url --- url?
        request.setAttribute("pd_FrpId", pd_FrpId);
        request.setAttribute("p0_Cmd", p0_Cmd);
        request.setAttribute("p1_MerId", p1_MerId);
        request.setAttribute("p2_Order", p2_Order);
        request.setAttribute("p3_Amt", p3_Amt);
        request.setAttribute("p4_Cur", p4_Cur);
        request.setAttribute("p5_Pid", p5_Pid);
        request.setAttribute("p6_Pcat", p6_Pcat);
        request.setAttribute("p7_Pdesc", p7_Pdesc);
        request.setAttribute("p8_Url", p8_Url);
        request.setAttribute("p9_SAF", p9_SAF);
        request.setAttribute("pa_MP", pa_MP);
        request.setAttribute("pr_NeedResponse", pr_NeedResponse);
        request.setAttribute("hmac", hmac);
 
        request.getRequestDispatcher("/confirm.jsp").forward(request, response);
    
    
  }
 
}

2.用戶確認提交的信息(confirm.jsp) 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
 
<%@taglib prefix="p" uri="http://www.itcast.cn/tag"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
  <p:user />
  <!-- 確認支付form -->
  <form action="https://www.yeepay.com/app-merchant-proxy/node"
    method="get">
    <h3>訂單號:${p2_Order},付款金額 :${p3_Amt }</h3>
    <input type="hidden" name="pd_FrpId" value="${pd_FrpId }" /> <input
      type="hidden" name="p0_Cmd" value="${p0_Cmd }" /> <input
      type="hidden" name="p1_MerId" value="${p1_MerId }" /> <input
      type="hidden" name="p2_Order" value="${p2_Order }" /> <input
      type="hidden" name="p3_Amt" value="${p3_Amt }" /> <input
      type="hidden" name="p4_Cur" value="${p4_Cur }" /> <input
      type="hidden" name="p5_Pid" value="${p5_Pid }" /> <input
      type="hidden" name="p6_Pcat" value="${p6_Pcat }" /> <input
      type="hidden" name="p7_Pdesc" value="${p7_Pdesc }" /> <input
      type="hidden" name="p8_Url" value="${p8_Url }" /> <input
      type="hidden" name="p9_SAF" value="${p9_SAF }" /> <input
      type="hidden" name="pa_MP" value="${pa_MP }" /> <input type="hidden"
      name="pr_NeedResponse" value="${pr_NeedResponse }" /> <input
      type="hidden" name="hmac" value="${hmac }" /> <input type="submit"
      value="確認支付" />
  </form>
</body>
</html>

3.網(wǎng)站獲得第三方支付的信息

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.learning.web.servlet;
 
import java.io.IOException;
import java.util.ResourceBundle;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.learning.service.OrderService;
import com.learning.utils.PaymentUtil;
 
 
/**
 * 該Servlet會在支付成功后 進行調(diào)用----- 支付公司 、客戶
 *
 * @author seawind
 *
 */
public class CallbackServlet extends HttpServlet {
 
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // 獲得回調(diào)所有數(shù)據(jù)
    String p1_MerId = request.getParameter("p1_MerId");
    String r0_Cmd = request.getParameter("r0_Cmd");
    String r1_Code = request.getParameter("r1_Code");
    String r2_TrxId = request.getParameter("r2_TrxId");
    String r3_Amt = request.getParameter("r3_Amt");
    String r4_Cur = request.getParameter("r4_Cur");
    String r5_Pid = request.getParameter("r5_Pid");
    String r6_Order = request.getParameter("r6_Order");
    String r7_Uid = request.getParameter("r7_Uid");
    String r8_MP = request.getParameter("r8_MP");
    String r9_BType = request.getParameter("r9_BType");
    String rb_BankId = request.getParameter("rb_BankId");
    String ro_BankOrderId = request.getParameter("ro_BankOrderId");
    String rp_PayDate = request.getParameter("rp_PayDate");
    String rq_CardNo = request.getParameter("rq_CardNo");
    String ru_Trxtime = request.getParameter("ru_Trxtime");
    // 身份校驗 --- 判斷是不是支付公司通知你
    String hmac = request.getParameter("hmac");
    String keyValue = ResourceBundle.getBundle("merchantInfo").getString(
        "keyValue");
 
    // 自己對上面數(shù)據(jù)進行加密 --- 比較支付公司發(fā)過來hamc
    boolean isValid = PaymentUtil.verifyCallback(hmac, p1_MerId, r0_Cmd,
        r1_Code, r2_TrxId, r3_Amt, r4_Cur, r5_Pid, r6_Order, r7_Uid,
        r8_MP, r9_BType, keyValue);
    if (isValid) {
      // 響應數(shù)據(jù)有效
      if (r9_BType.equals("1")) {
        // 瀏覽器重定向
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println("<h1>付款成功!等待商城進一步操作!等待收貨...</h1>");
      } else if (r9_BType.equals("2")) {
        // 服務器點對點 --- 支付公司通知你
        System.out.println("付款成功!");
        // 修改訂單狀態(tài) 為已付款
        OrderService orderService=new OrderService();
        orderService.modifyOrderState(p1_MerId);
        
        // 回復支付公司
        response.getWriter().print("success");
      }
    } else {
      // 數(shù)據(jù)無效
      System.out.println("數(shù)據(jù)被篡改!");
    }
  }
 
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);
  }
 
}

文件:

merchantInfo.properties

p1_MerId=10001126856
keyValue=69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl
responseURL=http://localhost:8080/onlinepay/servlet/PaymentResponse

工具類:PaymentUtil

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package com.learning.utils;
 
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
 
public class PaymentUtil {
 
  private static String encodingCharset = "UTF-8";
  
  /**
   * 生成hmac方法
   *
   * @param p0_Cmd 業(yè)務類型
   * @param p1_MerId 商戶編號
   * @param p2_Order 商戶訂單號
   * @param p3_Amt 支付金額
   * @param p4_Cur 交易幣種
   * @param p5_Pid 商品名稱
   * @param p6_Pcat 商品種類
   * @param p7_Pdesc 商品描述
   * @param p8_Url 商戶接收支付成功數(shù)據(jù)的地址
   * @param p9_SAF 送貨地址
   * @param pa_MP 商戶擴展信息
   * @param pd_FrpId 銀行編碼
   * @param pr_NeedResponse 應答機制
   * @param keyValue 商戶密鑰
   * @return
   */
  public static String buildHmac(String p0_Cmd,String p1_MerId,
      String p2_Order, String p3_Amt, String p4_Cur,String p5_Pid, String p6_Pcat,
      String p7_Pdesc,String p8_Url, String p9_SAF,String pa_MP,String pd_FrpId,
      String pr_NeedResponse,String keyValue) {
    StringBuilder sValue = new StringBuilder();
    // 業(yè)務類型
    sValue.append(p0_Cmd);
    // 商戶編號
    sValue.append(p1_MerId);
    // 商戶訂單號
    sValue.append(p2_Order);
    // 支付金額
    sValue.append(p3_Amt);
    // 交易幣種
    sValue.append(p4_Cur);
    // 商品名稱
    sValue.append(p5_Pid);
    // 商品種類
    sValue.append(p6_Pcat);
    // 商品描述
    sValue.append(p7_Pdesc);
    // 商戶接收支付成功數(shù)據(jù)的地址
    sValue.append(p8_Url);
    // 送貨地址
    sValue.append(p9_SAF);
    // 商戶擴展信息
    sValue.append(pa_MP);
    // 銀行編碼
    sValue.append(pd_FrpId);
    // 應答機制
    sValue.append(pr_NeedResponse);
    
    return PaymentUtil.hmacSign(sValue.toString(), keyValue);
  }
  
  /**
   * 返回校驗hmac方法
   *
   * @param hmac 支付網(wǎng)關(guān)發(fā)來的加密驗證碼
   * @param p1_MerId 商戶編號
   * @param r0_Cmd 業(yè)務類型
   * @param r1_Code 支付結(jié)果
   * @param r2_TrxId 易寶支付交易流水號
   * @param r3_Amt 支付金額
   * @param r4_Cur 交易幣種
   * @param r5_Pid 商品名稱
   * @param r6_Order 商戶訂單號
   * @param r7_Uid 易寶支付會員ID
   * @param r8_MP 商戶擴展信息
   * @param r9_BType 交易結(jié)果返回類型
   * @param keyValue 密鑰
   * @return
   */
  public static boolean verifyCallback(String hmac, String p1_MerId,
      String r0_Cmd, String r1_Code, String r2_TrxId, String r3_Amt,
      String r4_Cur, String r5_Pid, String r6_Order, String r7_Uid,
      String r8_MP, String r9_BType, String keyValue) {
    StringBuilder sValue = new StringBuilder();
    // 商戶編號
    sValue.append(p1_MerId);
    // 業(yè)務類型
    sValue.append(r0_Cmd);
    // 支付結(jié)果
    sValue.append(r1_Code);
    // 易寶支付交易流水號
    sValue.append(r2_TrxId);
    // 支付金額
    sValue.append(r3_Amt);
    // 交易幣種
    sValue.append(r4_Cur);
    // 商品名稱
    sValue.append(r5_Pid);
    // 商戶訂單號
    sValue.append(r6_Order);
    // 易寶支付會員ID
    sValue.append(r7_Uid);
    // 商戶擴展信息
    sValue.append(r8_MP);
    // 交易結(jié)果返回類型
    sValue.append(r9_BType);
    String sNewString = PaymentUtil.hmacSign(sValue.toString(), keyValue);
    return sNewString.equals(hmac);
  }
  
  /**
   * @param aValue
   * @param aKey
   * @return
   */
  public static String hmacSign(String aValue, String aKey) {
    byte k_ipad[] = new byte[64];
    byte k_opad[] = new byte[64];
    byte keyb[];
    byte value[];
    try {
      keyb = aKey.getBytes(encodingCharset);
      value = aValue.getBytes(encodingCharset);
    } catch (UnsupportedEncodingException e) {
      keyb = aKey.getBytes();
      value = aValue.getBytes();
    }
 
    Arrays.fill(k_ipad, keyb.length, 64, (byte) 54);
    Arrays.fill(k_opad, keyb.length, 64, (byte) 92);
    for (int i = 0; i < keyb.length; i++) {
      k_ipad[i] = (byte) (keyb[i] ^ 0x36);
      k_opad[i] = (byte) (keyb[i] ^ 0x5c);
    }
 
    MessageDigest md = null;
    try {
      md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
 
      return null;
    }
    md.update(k_ipad);
    md.update(value);
    byte dg[] = md.digest();
    md.reset();
    md.update(k_opad);
    md.update(dg, 0, 16);
    dg = md.digest();
    return toHex(dg);
  }
 
  public static String toHex(byte input[]) {
    if (input == null)
      return null;
    StringBuffer output = new StringBuffer(input.length * 2);
    for (int i = 0; i < input.length; i++) {
      int current = input[i] & 0xff;
      if (current < 16)
        output.append("0");
      output.append(Integer.toString(current, 16));
    }
 
    return output.toString();
  }
 
  /**
   *
   * @param args
   * @param key
   * @return
   */
  public static String getHmac(String[] args, String key) {
    if (args == null || args.length == 0) {
      return (null);
    }
    StringBuffer str = new StringBuffer();
    for (int i = 0; i < args.length; i++) {
      str.append(args[i]);
    }
    return (hmacSign(str.toString(), key));
  }
 
  /**
   * @param aValue
   * @return
   */
  public static String digest(String aValue) {
    aValue = aValue.trim();
    byte value[];
    try {
      value = aValue.getBytes(encodingCharset);
    } catch (UnsupportedEncodingException e) {
      value = aValue.getBytes();
    }
    MessageDigest md = null;
    try {
      md = MessageDigest.getInstance("SHA");
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      return null;
    }
    return toHex(md.digest(value));
 
  }
  
//  public static void main(String[] args) {
//    System.out.println(hmacSign("AnnulCard1000043252120080620160450.0http://localhost/SZXpro/callback.asp榪?4564868265473632445648682654736324511","8UPp0KE8sq73zVP370vko7C39403rtK1YwX40Td6irH216036H27Eb12792t"));
//  }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 亚洲精品一区在线观看 | 成人影音 | 午夜精品久久久久久 | 免费国产视频 | 精品一区二区不卡 | 高清国产一区二区三区四区五区 | 久久久久久久久99精品 | 免费一级在线视频 | 亚洲一区观看 | 激情视频网 | 欧美精品乱码久久久久久按摩 | 欧美一区二区三区在线视频 | 亚洲精品久久久久久一区二区 | 成人免费xxxxx在线观看 | 五月婷婷色网 | 欧美视频精品 | 人人人射 | 在线观看中文字幕亚洲 | 欧美日韩一区精品 | 日日搞夜夜操 | 成人高清视频在线观看 | 亚洲一级黄色 | 精品国产髙清在线看国产毛片 | 操操av| 综合久久网 | 日本福利网站 | 亚洲午夜在线 | 欧美黄色片免费观看 | 亚洲一区在线免费观看 | 亚洲第一成年人视频 | 久久夜色精品国产 | 国产精品一二三 | 一区二区日韩 | 日韩免费一区 | 中文字幕1区 | 国产精品污www一区二区三区 | 亚洲综合在线视频 | 久久夜色精品国产 | 国产成人精品一区二 | 日韩在线二区 | 亚洲综合在线视频 |