【1】創建賬號
首先去支付寶開放平臺註冊賬號,創建了沙箱如下:
![Springboot整合支付寶沙箱測試支付(支付和退款)](http://p2.ttnews.xyz/loading.gif)
【2】下載沙箱
手機上下載一個沙箱前包
![Springboot整合支付寶沙箱測試支付(支付和退款)](http://p2.ttnews.xyz/loading.gif)
【3】沙箱賬號
【4】密鑰工具
下載生成 RSA 密鑰 https://docs.open.alipay.com/291/105971
【5】生成密鑰
【6】修改RSA2/SHA256密鑰
【7】下載代碼
去資源界面(https://www.toptech.top/s/file)下載:Springboot整合支付寶沙箱支付
【8】修改代碼中的密鑰
<code>package springbootalipay.alipay.util;
public class AlipayConfig {
\t// 應用ID,您的APPID,收款賬號既是您的APPID對應支付寶賬號
\tpublic static String app_id = "APPID";
\t// 商戶私鑰,您的PKCS8格式RSA2私鑰
\tpublic static String merchant_private_key = "替換成剛剛生成的私鑰";
\t// 支付寶公鑰,查看地址:https://openhome.alipay.com/platform/keyManage.htm 對應APPID下的支付寶公鑰。
\tpublic static String alipay_public_key = "替換成剛剛生成的公鑰";
\tpublic static String notify_url = "http://localhost:8888/alipay/alipayNotifyNotice";
\tpublic static String return_url = "http://localhost:8888/alipay/alipayReturnNotice";
\tpublic static String sign_type = "RSA2";
\tpublic static String charset = "utf-8";
\tpublic static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";//注意:沙箱測試環境,正式環境為:https://openapi.alipay.com/gateway.do
}
/<code>
【9】運行
- 1、導入數據庫
- 2、運行代碼
【10】運行截圖
1、支付
此時可以去看金額是否變化
2、退款
此時可以去看金額是否變化
總結
整個支付流程:
- 1、用戶選擇商品
- 2、進入商品確認界面
- 3、生成訂單進入訂單確認界面
- 4、選擇支付方式
- 5、進入支付寶支付
- 6、支付成功修改支付狀態
- 7、添加支付流水數據
閱讀更多 理木客 的文章