准備
1、螞蟻金服開放平台商戶注冊-》https://open.alipay.com/platform/home.htm
2、創建應用或者沙箱應用

3、創建應用或者沙箱應用
4.配置相關參數
回調,公鑰私鑰等,然后簽約開發的移動端類型,簽約應用,包括但不限於APP,網頁支付.留存appid, 支付寶公鑰,應用私鑰,支付寶公鑰由上傳的應用私鑰獲取而來。
可以下載阿里提供的sdk進行集成,免去重寫造輪子https://docs.open.alipay.com/54/103419/
代碼
如果使用sdk提供的sdk進行編碼速度歲提升很多,例如:
AlipayTradeQueryRequest 訂單查詢
AlipayTradeWapPayRequest web支付表單
AlipayTradePrecreateRequest 二維碼預下單接口
.....
剩下的就是寫業務相關方面的代碼了
。。。。。。。。。。。。
回調:
@PostMapping("/aliPayBack")
public void aliPayBack(HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.debug("阿里支付成功回調接口");
String result = "failure";
try {
String orderCode= request.getParameter("out_trade_no");
Map<String, String> map = AliPayUtils.sortNotifyMap(request.getParameterMap());//對參數進行處理 應當為<String,String>
boolean signVerified = AlipaySignature.rsaCheckV1(map, "公鑰", AliConstants.UTF_8, AliConstants.RSA2);
if (signVerified) {
//阿里雲主動通知只有兩種情況 1 付款成功 TRADE_SUCCESS 2退款通知TRADE_CLOSED
String status = map.get("trade_status");
}else {
result = "failure";
logger.debug(":阿里API校驗未通過");
}
}catch (Exception e){
result = "failure";
e.printStackTrace();
}finally {
PrintWriter out=response.getWriter();
out.println(result);
out.flush();
out.close();
}
}
