ssm_支付宝沙箱

Posted hong999

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ssm_支付宝沙箱相关的知识,希望对你有一定的参考价值。

支付宝配置:

技术图片
package alipay;

import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by Administrator on 2019/7/6.
 */
public class AlipayConfig 

    // ↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

    // 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号
    public static String app_id = "2016100100636987";//例:2016082600317257

    // 商户私钥,您的PKCS8格式RSA2私钥
    public static String merchant_private_key ="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCQ4JdtPp86OXH26BFAlfoQF/zk66lsTzUrRBOm7HqCwfxLTFvRffhS/UHBwpETySYbpiuAxfnKgsnP+AdrfPetpsAPhQf7IYfQTcdAoWJLP3j3+2emAYGRmUCcyehR3oCmQNeXg8el6kD8bMiG+sgVYCMsUcd0T49kfd85NBaMV1rtW+cPQEAp77Njxw4BQS1a5vbkXbCBBJiHe35N8w5g6EGRDA9x46JfOMNaxwzbdv4jpeRwSQjtM7eZNw0LL0mIhjmJGJzLmMfa7w8SANF5hewzu7XTl+VkZ6jGhBc/C6nmuENEOssc/RKyWXShsUCwpHOpOOhHKtm//X7iE531AgMBAAECggEBAIxAsLe0mQcP17E0pocE6gmsf0nKjsDoyUsyY2gEpPFzBGCM8pKTRdRpksAWMMabw4Wez5yhjBmtldv8fIpld40n0eT0X26R3l4c/dkmova/4scHHidKa/ndB/0BRiQDqD3KpivrClsntXPpiBOMMijnYgWkwddqsiGR7Yj+URnYfh3e4XbYtkzOIeHkhZdDrqkS23Njs2QIxIuErN+PABrqsOwHSmLdbToq2g8TpjoHYt5e01uzR819+zrT1v3u5yEars2ZKEYhWd29KyUcll0QL67S0KGDbADVz+XDChoE5CUCpgs0/oEmW3z3nfSlOk+DLid2onMllYbNkfZ06B0CgYEAy4wcutC2ixJLDOMt1sHFJC9fE53AcTL/4QE2QlVYNmdCLB5h9/RFCeesqVX7bcLzlV81HgPZujw7swMXwwLrBWsZtzSeLcpbQBsFTTWbWoMVztiGka+BAMZnCkAfQMOORetFdsIYFc43dz/z+HCYL88o5DAKAC1+JiM39bYFw+8CgYEAtjYOZYGFp9n5gvU/mtMI8zqPHtPIJfAWVNHDpRkK68FK+W4YkGkidnYzAxzEuXUohHfyR3sK/MchPpovZ9oO8YO9aToofdUQEGLdt6KXluexHpEVtfbXQEZnTHmjuUTQ0kdyxTjDXdlD9NMbTmCgFcGQW66BqR52yZG6OxEQiFsCgYEAuyE+DHXzTJnty5RUQRr1vlWayDMAiFGFsvtlQciqh6GY0WzBTq8QhZGrSCbXN0rCm/HiqIyLr87OZ74RK2TUYq/a/XZvcdOW3rG4xwngoG7hLsAbv3YlWGwOsPrQgL8IXrl0rEC22d0zWvu9tQr2rwV6J4cOuqkYT8GTId9NH5sCgYAummDQQXJn3e5dOlDMTpGJdD7Kyav1WBS+GPCLN359kfCVHz2VIe64kb62WxNNw9NbHjqPYb8Lq/qqwlDBpRoRV3qIgWF93ZLAPikrIKDY7eV1RfJhmgKv49Hj03C2oA0w2ylVnBEL3dfttFjVkQ0gw2Mir91l3e7P2z/gf5rU5QKBgHnm6h6ay1wuSkE1aC/7tksoVQqKly7NKk015r6aukFyLsv8gz4rSULu9JyCTR50QyJiCYqNynDMeyY1BkQ06OvWCHzSbm2Y6wMKdiZ27PjjJg2BUXZttGFzGyGn8pxHGvJXsnHcuZzn+k9xGNJYc2BHlmz9s3eNN/DTrsbMDB8z";

    // 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm
    // 对应APPID下的支付宝公钥。
    public static String alipay_public_key ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiIrzY5TloPGev3rFfD15SZ1eZVDFah9pefGniUBQFLWHqjgOK+j+1d5FSZD/TOqVaknuNx8pUuYbFmta7e9JyZtNl1Db5pHau1AawPuIrDLJ7SLc2s/oPONaMlz/mfucJtNGmpdrRg9VRk/yi0aQNmWwrS8RJRbB8wQuQRBdSu3z7+1USjDmgC2FC5CkB+rLjKcfkyVUKfIVJ33ymMGfEmaASltiw3UhITmctQr9vLn1C60WbXjxDq6g3DXUkhU0F2wFbhGeagPhEWp3fl40CSEXKxg2quj2uXawk0jayTDTgo8eILwTsiEffI2IHyl8Ye25kiQBRZEeZ7O33/fNtwIDAQAB";

    // 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    /**
     * 返回的时候此页面不会返回到用户页面,只会执行你写到控制器里的地址
     */
    public static String notify_url = "http://localhost:8080/notify_url.jsp";
    // 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    /**
     * 此页面是同步返回用户页面,也就是用户支付后看到的页面,上面的notify_url是异步返回商家操作,谢谢
     * 要是看不懂就找度娘,或者多读几遍,或者去看支付宝第三方接口API,不看API直接拿去就用,遇坑不怪别人
     */
    public static String return_url = "http://localhost:8080/return_url.jsp";
    // 签名方式
    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 = "D:\\";
    // ↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    /**
     * 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
     *
     * @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();
                
            
        
    

AlipayConfig
支付跳转页面:*.jsp
技术图片
<!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>交易关闭</title>
</head>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<%@ page import="com.alipay.api.*"%>
<%@ page import="com.alipay.api.request.*"%>
<%@ page import="alipay.AlipayConfig" %>
<%
    //获得初始化的AlipayClient
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
    
    //设置请求参数
    AlipayTradeCloseRequest alipayRequest = new AlipayTradeCloseRequest();
    //商户订单号,商户网站订单系统中唯一订单号
    String out_trade_no = new String(request.getParameter("WIDTCout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
    //支付宝交易号
    String trade_no = new String(request.getParameter("WIDTCtrade_no").getBytes("ISO-8859-1"),"UTF-8");
    //请二选一设置
    
    alipayRequest.setBizContent("\"out_trade_no\":\""+ out_trade_no +"\"," +"\"trade_no\":\""+ trade_no +"\"");
    
    //请求
    String result = alipayClient.execute(alipayRequest).getBody();
    
    //输出
    out.println(result);
%>
<body>
</body>
</html>
alipay.trade.close.jsp
技术图片
<!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>退款查询</title>
</head>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<%@ page import="com.alipay.api.*"%>
<%@ page import="com.alipay.api.request.*"%>
<%@ page import="alipay.AlipayConfig" %>
<%
    //获得初始化的AlipayClient
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
    
    //设置请求参数
    AlipayTradeFastpayRefundQueryRequest alipayRequest = new AlipayTradeFastpayRefundQueryRequest();
    
    //商户订单号,商户网站订单系统中唯一订单号
    String out_trade_no = new String(request.getParameter("WIDRQout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
    //支付宝交易号
    String trade_no = new String(request.getParameter("WIDRQtrade_no").getBytes("ISO-8859-1"),"UTF-8");
    //请二选一设置
    //请求退款接口时,传入的退款请求号,如果在退款请求时未传入,则该值为创建交易时的外部交易号,必填
    String out_request_no = new String(request.getParameter("WIDRQout_request_no").getBytes("ISO-8859-1"),"UTF-8");
    
    alipayRequest.setBizContent("\"out_trade_no\":\""+ out_trade_no +"\"," 
            +"\"trade_no\":\""+ trade_no +"\","
            +"\"out_request_no\":\""+ out_request_no +"\"");
    
    //请求
    String result = alipayClient.execute(alipayRequest).getBody();
    
    //输出
    out.println(result);
%>
<body>
</body>
</html>
alipay.trade.fastpay.refund.query.jsp
技术图片
<!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>付款</title>
</head>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="com.alipay.api.*"%>
<%@ page import="com.alipay.api.request.*"%>
<%@ page import="alipay.AlipayConfig" %>
<%
    //获得初始化的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);
    alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
    
    //商户订单号,商户网站订单系统中唯一订单号,必填
    String out_trade_no = new String(request.getParameter("WIDout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
    //付款金额,必填
    String total_amount = new String(request.getParameter("WIDtotal_amount").getBytes("ISO-8859-1"),"UTF-8");
    //订单名称,必填
    String subject = new String(request.getParameter("WIDsubject").getBytes("ISO-8859-1"),"UTF-8");
    //商品描述,可空
    String body = new String(request.getParameter("WIDbody").getBytes("ISO-8859-1"),"UTF-8");
    
    alipayRequest.setBizContent("\"out_trade_no\":\""+ out_trade_no +"\"," 
            + "\"total_amount\":\""+ total_amount +"\"," 
            + "\"subject\":\""+ subject +"\"," 
            + "\"body\":\""+ body +"\"," 
            + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"");
    
    //若想给BizContent增加其他可选请求参数,以增加自定义超时时间参数timeout_express来举例说明
    //alipayRequest.setBizContent("\"out_trade_no\":\""+ out_trade_no +"\"," 
    //        + "\"total_amount\":\""+ total_amount +"\"," 
    //        + "\"subject\":\""+ subject +"\"," 
    //        + "\"body\":\""+ body +"\"," 
    //        + "\"timeout_express\":\"10m\"," 
    //        + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"");
    //请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节
    
    //请求
    String result = alipayClient.pageExecute(alipayRequest).getBody();
    
    //输出
    out.println(result);
%>
<body>
</body>
</html>
alipay.trade.page.pay.jsp
技术图片
<!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>交易查询</title>
</head>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<%@ page import="com.alipay.api.*"%>
<%@ page import="com.alipay.api.request.*"%>
<%@ page import="alipay.AlipayConfig" %>
<%
    //获得初始化的AlipayClient
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
    
    //设置请求参数
    AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest();
    
    //商户订单号,商户网站订单系统中唯一订单号
    String out_trade_no = new String(request.getParameter("WIDTQout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
    //支付宝交易号
    String trade_no = new String(request.getParameter("WIDTQtrade_no").getBytes("ISO-8859-1"),"UTF-8");
    //请二选一设置
    
    alipayRequest.setBizContent("\"out_trade_no\":\""+ out_trade_no +"\","+"\"trade_no\":\""+ trade_no +"\"");
    
    //请求
    String result = alipayClient.execute(alipayRequest).getBody();
    
    //输出
    out.println(result);
%>
<body>
</body>
</html>
alipay.trade.query.jsp
技术图片
<!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>退款</title>
</head>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="com.alipay.api.*"%>
<%@ page import="com.alipay.api.request.*"%>
<%@ page import="alipay.AlipayConfig" %>
<%
    //获得初始化的AlipayClient
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
    
    //设置请求参数
    AlipayTradeRefundRequest alipayRequest = new AlipayTradeRefundRequest();
    
    //商户订单号,商户网站订单系统中唯一订单号
    String out_trade_no = new String(request.getParameter("WIDTRout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
    //支付宝交易号
    String trade_no = new String(request.getParameter("WIDTRtrade_no").getBytes("ISO-8859-1"),"UTF-8");
    //请二选一设置
    //需要退款的金额,该金额不能大于订单金额,必填
    String refund_amount = new String(request.getParameter("WIDTRrefund_amount").getBytes("ISO-8859-1"),"UTF-8");
    //退款的原因说明
    String refund_reason = new String(request.getParameter("WIDTRrefund_reason").getBytes("ISO-8859-1"),"UTF-8");
    //标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传
    String out_request_no = new String(request.getParameter("WIDTRout_request_no").getBytes("ISO-8859-1"),"UTF-8");
    
    alipayRequest.setBizContent("\"out_trade_no\":\""+ out_trade_no +"\"," 
            + "\"trade_no\":\""+ trade_no +"\"," 
            + "\"refund_amount\":\""+ refund_amount +"\"," 
            + "\"refund_reason\":\""+ refund_reason +"\"," 
            + "\"out_request_no\":\""+ out_request_no +"\"");
    
    //请求
    String result = alipayClient.execute(alipayRequest).getBody();
    
    //输出
    out.println(result);
%>
<body>
</body>
</html>
alipay.trade.refund.jsp
技术图片
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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>支付宝电脑网站支付</title>
<style>
* 
    margin: 0;
    padding: 0;


ul, ol 
    list-style: none;


body 
    font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande",
        sans-serif;


.tab-head 
    margin-left: 120px;
    margin-bottom: 10px;


.tab-content 
    clear: left;
    display: none;


h2 
    border-bottom: solid #02aaf1 2px;
    width: 200px;
    height: 25px;
    margin: 0;
    float: left;
    text-align: center;
    font-size: 16px;


.selected 
    color: #FFFFFF;
    background-color: #02aaf1;


.show 
    clear: left;
    display: block;


.hidden 
    display: none;


.new-btn-login-sp 
    padding: 1px;
    display: inline-block;
    width: 75%;


.new-btn-login 
    background-color: #02aaf1;
    color: #FFFFFF;
    font-weight: bold;
    border: none;
    width: 100%;
    height: 30px;
    border-radius: 5px;
    font-size: 16px;


#main 
    width: 100%;
    margin: 0 auto;
    font-size: 14px;


.red-star 
    color: #f00;
    width: 10px;
    display: inline-block;


.null-star 
    color: #fff;


.content 
    margin-top: 5px;


.content dt 
    width: 100px;
    display: inline-block;
    float: left;
    margin-left: 20px;
    color: #666;
    font-size: 13px;
    margin-top: 8px;


.content dd 
    margin-left: 120px;
    margin-bottom: 5px;


.content dd input 
    width: 85%;
    height: 28px;
    border: 0;
    -webkit-border-radius: 0;
    -webkit-appearance: none;


#foot 
    margin-top: 10px;
    position: absolute;
    bottom: 15px;
    width: 100%;


.foot-ul 
    width: 100%;


.foot-ul li 
    width: 100%;
    text-align: center;
    color: #666;


.note-help 
    color: #999999;
    font-size: 12px;
    line-height: 130%;
    margin-top: 5px;
    width: 100%;
    display: block;


#btn-dd 
    margin: 20px;
    text-align: center;


.foot-ul 
    width: 100%;


.one_line 
    display: block;
    height: 1px;
    border: 0;
    border-top: 1px solid #eeeeee;
    width: 100%;
    margin-left: 20px;


.am-header 
    display: -webkit-box;
    display: -ms-flexbox;

    width: 100%;
    position: relative;
    padding: 7px 0;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
    background: #1D222D;
    height: 50px;
    text-align: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    box-pack: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    box-align: center;


.am-header h1 
    -webkit-box-flex: 1;
    -ms-flex: 1;
    box-flex: 1;
    line-height: 18px;
    text-align: center;
    font-size: 18px;
    font-weight: 300;
    color: #fff;

</style>
</head>
<body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
    <header class="am-header">
    <h1>支付宝电脑网站支付体验入口页</h1>
    </header>
    <div id="main">
        <div id="tabhead" class="tab-head">
            <h2 id="tab1" class="selected" name="tab">付 款</h2>
            <h2 id="tab2" name="tab">交 易 查 询</h2>
            <h2 id="tab3" name="tab">退 款</h2>
            <h2 id="tab4" name="tab">退 款 查 询</h2>
            <h2 id="tab5" name="tab">交 易 关 闭</h2>
        </div>
        <form name=alipayment action=alipay.trade.page.pay.jsp method=post
            target="_blank">
            <div id="body1" class="show" name="divcontent">
                <dl class="content">
                    <dt>商户订单号 :</dt>
                    <dd>
                        <input id="WIDout_trade_no" name="WIDout_trade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt>订单名称 :</dt>
                    <dd>
                        <input id="WIDsubject" name="WIDsubject" />
                    </dd>
                    <hr class="one_line">
                    <dt>付款金额 :</dt>
                    <dd>
                        <input id="WIDtotal_amount" name="WIDtotal_amount" />
                    </dd>
                    <hr class="one_line">
                    <dt>商品描述:</dt>
                    <dd>
                        <input id="WIDbody" name="WIDbody" />
                    </dd>
                    <hr class="one_line">
                    <dt></dt>
                    <dd id="btn-dd">
                        <span class="new-btn-login-sp">
                            <button class="new-btn-login" type="submit"
                                style="text-align: center;">付 款</button>
                        </span> <span class="note-help">如果您点击“付款”按钮,即表示您同意该次的执行操作。</span>
                    </dd>
                </dl>
            </div>
        </form>
        <form name=tradequery action=alipay.trade.query.jsp method=post
            target="_blank">
            <div id="body2" class="tab-content" name="divcontent">
                <dl class="content">
                    <dt>商户订单号 :</dt>
                    <dd>
                        <input id="WIDTQout_trade_no" name="WIDTQout_trade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt>支付宝交易号 :</dt>
                    <dd>
                        <input id="WIDTQtrade_no" name="WIDTQtrade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt></dt>
                    <dd id="btn-dd">
                        <span class="new-btn-login-sp">
                            <button class="new-btn-login" type="submit"
                                style="text-align: center;">交 易 查 询</button>
                        </span> <span class="note-help">商户订单号与支付宝交易号二选一,如果您点击“交易查询”按钮,即表示您同意该次的执行操作。</span>
                    </dd>
                </dl>
            </div>
        </form>
        <form name=traderefund action=alipay.trade.refund.jsp method=post
            target="_blank">
            <div id="body3" class="tab-content" name="divcontent">
                <dl class="content">
                    <dt>商户订单号 :</dt>
                    <dd>
                        <input id="WIDTRout_trade_no" name="WIDTRout_trade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt>支付宝交易号 :</dt>
                    <dd>
                        <input id="WIDTRtrade_no" name="WIDTRtrade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt>退款金额 :</dt>
                    <dd>
                        <input id="WIDTRrefund_amount" name="WIDTRrefund_amount" />
                    </dd>
                    <hr class="one_line">
                    <dt>退款原因 :</dt>
                    <dd>
                        <input id="WIDTRrefund_reason" name="WIDTRrefund_reason" />
                    </dd>
                    <hr class="one_line">
                    <dt>退款请求号 :</dt>
                    <dd>
                        <input id="WIDTRout_request_no" name="WIDTRout_request_no" />
                    </dd>
                    <hr class="one_line">
                    <dt></dt>
                    <dd id="btn-dd">
                        <span class="new-btn-login-sp">
                            <button class="new-btn-login" type="submit"
                                style="text-align: center;">退 款</button>
                        </span> <span class="note-help">商户订单号与支付宝交易号二选一,如果您点击“退款”按钮,即表示您同意该次的执行操作。</span>
                    </dd>
                </dl>
            </div>
        </form>
        <form name=traderefundquery
            action=alipay.trade.fastpay.refund.query.jsp method=post
            target="_blank">
            <div id="body4" class="tab-content" name="divcontent">
                <dl class="content">
                    <dt>商户订单号 :</dt>
                    <dd>
                        <input id="WIDRQout_trade_no" name="WIDRQout_trade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt>支付宝交易号 :</dt>
                    <dd>
                        <input id="WIDRQtrade_no" name="WIDRQtrade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt>退款请求号 :</dt>
                    <dd>
                        <input id="WIDRQout_request_no" name="WIDRQout_request_no" />
                    </dd>
                    <hr class="one_line">
                    <dt></dt>
                    <dd id="btn-dd">
                        <span class="new-btn-login-sp">
                            <button class="new-btn-login" type="submit"
                                style="text-align: center;">退 款 查 询</button>
                        </span> <span class="note-help">商户订单号与支付宝交易号二选一,如果您点击“退款查询”按钮,即表示您同意该次的执行操作。</span>
                    </dd>
                </dl>
            </div>
        </form>
        <form name=tradeclose action=alipay.trade.close.jsp method=post
            target="_blank">
            <div id="body5" class="tab-content" name="divcontent">
                <dl class="content">
                    <dt>商户订单号 :</dt>
                    <dd>
                        <input id="WIDTCout_trade_no" name="WIDTCout_trade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt>支付宝交易号 :</dt>
                    <dd>
                        <input id="WIDTCtrade_no" name="WIDTCtrade_no" />
                    </dd>
                    <hr class="one_line">
                    <dt></dt>
                    <dd id="btn-dd">
                        <span class="new-btn-login-sp">
                            <button class="new-btn-login" type="submit"
                                style="text-align: center;">交 易 关 闭</button>
                        </span> <span class="note-help">商户订单号与支付宝交易号二选一,如果您点击“交易关闭”按钮,即表示您同意该次的执行操作。</span>
                    </dd>
                </dl>
            </div>
        </form>
        <div id="foot">
            <ul class="foot-ul">
                <li>支付宝版权所有 2015-2018 ALIPAY.COM</li>
            </ul>
        </div>
    </div>
</body>
<script language="javascript">
    var tabs = document.getElementsByName(‘tab‘);
    var contents = document.getElementsByName(‘divcontent‘);
    
    (function changeTab(tab) 
        for(var i = 0, len = tabs.length; i < len; i++) 
            tabs[i].onmouseover = showTab;
        
    )();
    
    function showTab() 
        for(var i = 0, len = tabs.length; i < len; i++) 
            if(tabs[i] === this) 
                tabs[i].className = ‘selected‘;
                contents[i].className = ‘show‘;
             else 
                tabs[i].className = ‘‘;
                contents[i].className = ‘tab-content‘;
            
        
    
    
    function GetDateNow() 
        var vNow = new Date();
        var sNow = "";
        sNow += String(vNow.getFullYear());
        sNow += String(vNow.getMonth() + 1);
        sNow += String(vNow.getDate());
        sNow += String(vNow.getHours());
        sNow += String(vNow.getMinutes());
        sNow += String(vNow.getSeconds());
        sNow += String(vNow.getMilliseconds());
        document.getElementById("WIDout_trade_no").value =  sNow;
        document.getElementById("WIDsubject").value = "测试";
        document.getElementById("WIDtotal_amount").value = "0.01";
    
    GetDateNow();
</script>
</html>
index.jsp
技术图片
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.Map"%>
<%@ page import="com.alipay.api.internal.util.*"%>
<%@ page import="alipay.AlipayConfig" %>
<%
/* *
 * 功能:支付宝服务器异步通知页面
 * 日期:2017-03-30
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
 * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。


 *************************页面功能说明*************************
 * 创建该页面文件时,请留心该页面文件中无任何HTML代码及空格。
 * 该页面不能在本机电脑测试,请到服务器上做测试。请确保外部可以访问该页面。
 * 如果没有收到该页面返回的 success 
 * 建议该页面只做支付成功的业务逻辑处理,退款的处理请以调用退款查询接口的结果为准。
 */
 
    //获取支付宝POST过来反馈信息
    Map<String,String> params = new HashMap<String,String>();
    Map<String,String[]> requestParams = request.getParameterMap();
    for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) 
        String name = (String) iter.next();
        String[] values = (String[]) requestParams.get(name);
        String valueStr = "";
        for (int i = 0; i < values.length; i++) 
            valueStr = (i == values.length - 1) ? valueStr + values[i]
                    : valueStr + values[i] + ",";
        
        //乱码解决,这段代码在出现乱码时使用
        valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
        params.put(name, valueStr);
    
    
    boolean signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type); //调用SDK验证签名

    //——请在这里编写您的程序(以下代码仅作参考)——
    
    /* 实际验证过程建议商户务必添加以下校验:
    1、需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
    2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
    3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
    4、验证app_id是否为该商户本身。
    */
    if(signVerified) //验证成功
        //商户订单号
        String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
    
        //支付宝交易号
        String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
    
        //交易状态
        String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"),"UTF-8");
        
        if(trade_status.equals("TRADE_FINISHED"))
            //判断该笔订单是否在商户网站中已经做过处理
            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
            //如果有做过处理,不执行商户的业务程序
                
            //注意:
            //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
        else if (trade_status.equals("TRADE_SUCCESS"))
            //判断该笔订单是否在商户网站中已经做过处理
            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
            //如果有做过处理,不执行商户的业务程序
            
            //注意:
            //付款完成后,支付宝系统发送该交易状态通知
        
        
        out.println("success");
        
    else //验证失败
        out.println("fail");
    
        //调试用,写文本函数记录程序运行情况是否正常
        //String sWord = AlipaySignature.getSignCheckContentV1(params);
        //AlipayConfig.logResult(sWord);
    
    
    //——请在这里编写您的程序(以上代码仅作参考)——
    
%>
notify_url.jsp
技术图片
<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>
<!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>电脑网站支付return_url</title>
</head>
<%@ page import="java.util.*"%>
<%@ page import="java.util.Map"%>
<%@ page import="com.alipay.api.internal.util.*"%>
<%@ page import="alipay.AlipayConfig" %>
<%
/* *
 * 功能:支付宝服务器同步通知页面
 * 日期:2017-03-30
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
 * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。


 *************************页面功能说明*************************
 * 该页面仅做页面展示,业务逻辑处理请勿在该页面执行
 */
 
    //获取支付宝GET过来反馈信息
    Map<String,String> params = new HashMap<String,String>();
    Map<String,String[]> requestParams = request.getParameterMap();
    for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) 
        String name = (String) iter.next();
        String[] values = (String[]) requestParams.get(name);
        String valueStr = "";
        for (int i = 0; i < values.length; i++) 
            valueStr = (i == values.length - 1) ? valueStr + values[i]
                    : valueStr + values[i] + ",";
        
        //乱码解决,这段代码在出现乱码时使用
        valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
        params.put(name, valueStr);
    
    
    boolean signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type); //调用SDK验证签名

    //——请在这里编写您的程序(以下代码仅作参考)——
    if(signVerified) 
        //商户订单号
        String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
    
        //支付宝交易号
        String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
    
        //付款金额
        String total_amount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"),"UTF-8");
        out.println("交易编号:"+trade_no+"<br/>订单编号:"+out_trade_no+"<br/>订单金额:"+total_amount);

    else 
        out.println("验签失败");
    
    //——请在这里编写您的程序(以上代码仅作参考)——

%>
<body>
</body>
</html>
return_url.jsp

 

以上是关于ssm_支付宝沙箱的主要内容,如果未能解决你的问题,请参考以下文章

支付宝支付—沙箱环境使用

支付宝支付沙箱环境配置

支付宝沙箱环境应用

支付宝支付沙箱环境配置

支付宝支付沙箱环境配置

springboot调用支付宝沙箱扫码支付