激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

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

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

服務器之家 - 編程語言 - Java教程 - java實現在SSM下使用支付寶掃碼支付功能

java實現在SSM下使用支付寶掃碼支付功能

2021-04-06 11:49wei_aiwan Java教程

這篇文章主要為大家詳細介紹了java實現在SSM下使用支付寶掃碼支付功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java使用支付寶掃碼支付的具體代碼,供大家參考,具體內容如下

準備工作

首先開通支付寶沙箱的測試賬號,里面會有消費者賬戶和收款方賬戶

java實現在SSM下使用支付寶掃碼支付功能

手機掃碼下載手機端app

java實現在SSM下使用支付寶掃碼支付功能

基礎配置

所需jar包

java實現在SSM下使用支付寶掃碼支付功能

alipayconfig

?
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
package com.alipay.config;
 
import java.io.filewriter;
import java.io.ioexception;
import java.util.resourcebundle;
 
/* *
 *類名:alipayconfig
 *功能:基礎配置類
 *詳細:設置帳戶有關信息及返回路徑
 *修改日期:2017-04-05
 *說明:
 *以下代碼只是為了方便商戶測試而提供的樣例代碼,商戶可以根據自己網站的需要,按照技術文檔編寫,并非一定要使用該代碼。
 *該代碼僅供學習和研究支付寶接口使用,只是提供一個參考。
 */
public class alipayconfig {
  //↓↓↓↓↓↓↓↓↓↓請在這里配置您的基本信息
    // 應用id,您的appid,收款賬號既是您的appid對應支付寶賬號
    public static string app_id = "2016080403162340";
 
    // 商戶私鑰,您的pkcs8格式rsa2私鑰
    public static string merchant_private_key = "miievaid2tulssmawg5+f4nzbexpnxi8nkqjpzeeaa==";
 
    // 支付寶公鑰,查看地址:https://openhome.alipay.com/platform/keymanage.htm 對應appid下的支付寶公鑰。
    public static string alipay_public_key = "miibijt26tltkar8s1erdwi25vibcmz7plmxvvumhf5tdbwfbmhus3qidaqab";
 
    // 服務器異步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義參數,必須外網可以正常訪問
    public static string notify_url = "http://localhost:8080/alipay.trade.page.pay-java-utf-8/notify_url.jsp";
 
    // 頁面跳轉同步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義參數,必須外網可以正常訪問
    public static string return_url = "http://localhost:8080/exam/index/goumai";
    // 簽名方式
    public static string sign_type = "rsa2";
 
    // 字符編碼格式
    public static string charset = "utf-8";
 
    // 支付寶網關
    public static string gatewayurl = "https://openapi.alipaydev.com/gateway.do";
 
    // 支付寶網關
    public static string log_path = "e:\\";
 
  //↑↑↑↑↑↑↑↑↑↑請在這里配置您的基本信息
    /**
     * 寫日志,方便測試(看網站需求,也可以改成把記錄存入數據庫)
     * @param sword 要寫入日志里的文本內容
     */
    public static void logresult(string sword ) {
      filewriter writer = null;
      try {
        writer = new filewriter(log_path + "alipay_log_" + system.currenttimemillis()+".txt");
        writer.write(sword);
      } catch (exception e) {
        e.printstacktrace();
      } finally {
        if (writer != null) {
          try {
            writer.close();
          } catch (ioexception e) {
            e.printstacktrace();
          }
        }
      }
    }
}

controller

?
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
//生成有二維碼,可供掃碼支付的頁面
  @requestmapping(value = "alipay")
  public string alipay(httpservletresponse response,modelmap map,string chapterid,httpservletrequest request,
      string widout_trade_no,string widtotal_amount,string widsubject,string widbody) throws ioexception, alipayapiexception{
//   string a,string urlname,string couname....+"&a="+a+"&urlname="+urlname+"&couname="+couname
    //獲得初始化的alipayclient
    alipayclient alipayclient = new defaultalipayclient(alipayconfig.gatewayurl, alipayconfig.app_id, alipayconfig.merchant_private_key, "json", alipayconfig.charset, alipayconfig.alipay_public_key, alipayconfig.sign_type);
 
    //設置請求參數
    alipaytradepagepayrequest alipayrequest = new alipaytradepagepayrequest();
    alipayrequest.setreturnurl(alipayconfig.return_url+"?chapterid="+chapterid);
    alipayrequest.setnotifyurl(alipayconfig.notify_url);
    //付款id,必填
    string out_trade_no = widout_trade_no;
    //付款金額,必填
    string total_amount = widtotal_amount;
    total_amount=urldecoder.decode(total_amount,"utf-8");//轉碼
    //訂單名稱,必填
    string subject = widsubject;
    subject=urldecoder.decode(subject,"utf-8");
    //商品描述,可空
    string body = widbody;
 
    alipayrequest.setbizcontent("{\"out_trade_no\":\""+ out_trade_no +"\","
        + "\"total_amount\":\""+ total_amount +"\","
        + "\"subject\":\""+ subject +"\","
        + "\"body\":\""+ body +"\","
        + "\"timeout_express\":\"1m\","
        + "\"product_code\":\"fast_instant_trade_pay\"}");
    //請求
    string result = alipayclient.pageexecute(alipayrequest).getbody();
     response.setcontenttype("text/html; charset=utf-8");
      printwriter out = response.getwriter(); 
      out.println(result); 
      return null;
  }

支付成功的放回頁面(return_url)

成功后的返回路徑,走controller,詳見alipayconfig中的配置

?
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
//點擊購買,將課程存入購買表中
  @requestmapping(value="goumai")
  @responsebody
  public modelandview goumai(string chapterid,httpservletrequest req,string a,string urlname,string couname,modelmap map){
    modelandview mav = new modelandview();
    map<string,string> mapp1 = new hashmap<string,string>();
//   sysusertab login_user = sysuserservice.getsysuserbyid(userid);
    httpsession session = req.getsession();
    sysusertab login_user1 = (sysusertab) session.getattribute("login_user");
    string userid = login_user1.getuserid();
//   session.setattribute("login_user", login_user);
 
    mapp1.put("userid", userid);
    mapp1.put("chapterid", chapterid);
    int num = sysbuyservice.getbuycount(mapp1);
    if(num==0){
      mapp1.put("buyid", uuid.randomuuid().tostring().replace("-", ""));
      sysbuyservice.insertbuy(mapp1);
    }
 
    //查詢課程內容
//   string fanhui = showfh(req,chapterid,urlname,couname,map, a);
    mav.setviewname("jsp/pay/paysuccess");
    return mav;
  }

支付成功后,頁面跳轉至paysuccess.jsp頁面。

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

原文鏈接:http://blog.csdn.net/han_xiaoxue/article/details/78528825

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久亚洲一区二区三区成人国产 | 91 久久| 中文在线日韩 | 日韩视频一二三 | h色视频网站| vidz 98hd | 久久新地址 | 久久蜜桃精品一区二区三区综合网 | 国内xxxx乱子另类 | 国产精品亚洲激情 | 狠狠婷婷综合久久久久久妖精 | 91久久国产露脸精品免费 | 国产一级淫片免费看 | 成人免费自拍视频 | 欧美一区二区三区久久久久久桃花 | 成人黄色网战 | 亚洲精品在线观看网站 | 亚洲日本高清 | 特级黄色影院 | 国产一级毛片高清视频完整版 | 亚洲精品wwww| 日韩av片网站| 国产亚洲精品久久久闺蜜 | 性片网站 | 一本一本久久a久久精品综合小说 | 92看片淫黄大片欧美看国产片 | av国产免费 | 欧美激情精品久久久久久黑人 | 日本a级一区 | 成年人免费高清视频 | 成人视屏在线 | 色视频在线 | 久久黄色影院 | 日韩高清影视 | 国产精品免费小视频 | 亚洲欧美日韩精品久久亚洲区色播 | 免费观看黄色一级视频 | 日韩免费黄色 | 国产一级做a爰片在线看 | www.54271.com | 欧美成年性h版影视中文字幕 |