1. 重构支付宝支付
This commit is contained in:
2026-03-28 16:35:05 +08:00
parent 967da9e95e
commit 924ee879ce

View File

@@ -10,6 +10,7 @@ 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.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.api.wxpay.IWxPayApiService;
@@ -148,26 +149,26 @@ public class CallbackController {
try {
// 获取支付宝POST过来反馈信息
Map<String, String> params = AliPayApiUtil.toMap(request);
System.out.println("支付宝回调参数:" + params.toString());
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, new String[]{"encoding:UTF-8"});
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, "encoding:UTF-8");
return;
}
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, appId);
if (aliPayAccountConfig == null) {
AliPayAccountConfig config = PaymentCache.getAliConfig();
if (config == null) {
result = "该商户号尚未接入";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, "encoding:UTF-8");
return;
}
String signType = aliPayAccountConfig.getSignType();
String pubKey = aliPayAccountConfig.getPubKey();
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, new String[]{"encoding:UTF-8"});
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, "encoding:UTF-8");
return;
}
//支付状态
@@ -218,13 +219,13 @@ public class CallbackController {
default:
break;
}
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
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(), new String[]{"encoding:UTF-8"});
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(), new String[]{"encoding:UTF-8"});
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), e.getMessage(), "encoding:UTF-8");
}
}