1. 旅游团、新闻、景点信息等功能模块访问接口路径拆分

2. 支付回调改造成 endpoint
This commit is contained in:
2026-04-10 19:53:51 +08:00
parent f967cbd846
commit 4688d91f60
74 changed files with 327 additions and 252 deletions

View File

@@ -0,0 +1,118 @@
package org.springblade.plugin.pay.controller;
import cn.hutool.http.ContentType;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springblade.common.cache.PaymentCache;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.service.IRefundService;
import org.springblade.plugin.pay.util.AliPayApiUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@AllArgsConstructor
@RequestMapping( "blade-ali/callback")
public class AliCallbackController {
private final IOrderService orderService;
private final IRefundService refundService;
/**
* 支付宝支付回调
*
* @param request
*/
@RequestMapping(value = "/alipay")
public void alipay(HttpServletRequest request, HttpServletResponse response) {
String result = "支付失败";
try {
// 获取支付宝POST过来反馈信息
Map<String, String> params = AliPayApiUtil.toMap(request);
System.out.println("支付宝回调参数:" + params);
String mchId = params.get("seller_id");
String appId = params.get("app_id");
if (StringUtils.isBlank(mchId)) {
result = "seller_id is not null";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, "encoding:UTF-8");
return;
}
AliPayAccountConfig config = PaymentCache.getAliConfig();
if (config == null) {
result = "该商户号尚未接入";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, "encoding:UTF-8");
return;
}
String signType = config.getSignType();
String pubKey = config.getPubKey();
boolean verify_result = AlipaySignature.rsaCheckV1(params, pubKey, "UTF-8", signType);
if (!verify_result) {
result = "签名验证失败";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, "encoding:UTF-8");
return;
}
//支付状态
String trade_status = params.get("trade_status");
// 总金额
String money = params.get("total_amount");
// 支付宝订单号
String payNo = params.get("trade_no");
// 商户订单号
String orderNo = params.get("out_trade_no");
//买家ID
String openId = params.get("buyer_id");
//支付时间
String payTime = params.get("gmt_payment");
//退款金额
String refund_fee = params.get("refund_fee");
//退款时间
String gmt_refund = params.get("gmt_refund");
//退款单号
String refundNo = params.get("out_biz_no");
switch (trade_status) {
case "WAIT_BUYER_PAY":
result = "wait buyer pay";
break;
case "TRADE_CLOSED":
//全额退款成功回调
if (refundService.refundSuccess(refundNo, mchId)) {
result = "success";
}
break;
case "TRADE_SUCCESS":
if (StringUtils.isBlank(refund_fee) && StringUtils.isBlank(gmt_refund)) {
//支付成功回调
if (orderService.paySuccess(orderNo, mchId, payNo, payTime, openId)) {
result = "success";
}
} else {
//部分退款回调
if (refundService.refundSuccess(refundNo, mchId)) {
result = "success";
}
}
break;
case "TRADE_FINISHED":
//交易结束,不可退款
result = "success";
break;
default:
break;
}
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, "encoding:UTF-8");
} catch (AlipayApiException e) {
e.printStackTrace();
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), e.getMessage(), "encoding:UTF-8");
} catch (Exception e) {
e.printStackTrace();
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), e.getMessage(), "encoding:UTF-8");
}
}
}