From d2e20554025955f4c8e831d1969ca060997aaf71 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Sat, 08 Feb 2025 12:01:17 +0800 Subject: [PATCH] feat(pay): 添加 FIUU支付回调处理功能 --- src/main/java/cc/mrbird/febs/pay/controller/FiuuReturnController.java | 43 ++++++++++++++++++++- src/main/java/cc/mrbird/febs/pay/util/FiuuUtil.java | 4 +- src/main/resources/templates/payment-success.html | 13 ++++++ src/main/java/cc/mrbird/febs/common/configure/WebMvcConfigure.java | 1 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/common/configure/WebMvcConfigure.java b/src/main/java/cc/mrbird/febs/common/configure/WebMvcConfigure.java index 83acd92..72d1e04 100644 --- a/src/main/java/cc/mrbird/febs/common/configure/WebMvcConfigure.java +++ b/src/main/java/cc/mrbird/febs/common/configure/WebMvcConfigure.java @@ -34,6 +34,7 @@ registration.excludePathPatterns("/api/xcxPay/rechargeCallBack"); registration.excludePathPatterns("/api/xcxPay/fapiaoCallBack"); registration.excludePathPatterns("/api/fuPayReturn/callback"); + registration.excludePathPatterns("/api/fuPayReturn/payment/callback"); registration.excludePathPatterns("/api/fuPay/notify"); // 添加Swagger UI相关路径 diff --git a/src/main/java/cc/mrbird/febs/pay/controller/FiuuReturnController.java b/src/main/java/cc/mrbird/febs/pay/controller/FiuuReturnController.java index 49c41fe..f9abf88 100644 --- a/src/main/java/cc/mrbird/febs/pay/controller/FiuuReturnController.java +++ b/src/main/java/cc/mrbird/febs/pay/controller/FiuuReturnController.java @@ -9,10 +9,11 @@ import cn.hutool.core.date.DateUtil; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.io.IOException; @@ -20,11 +21,49 @@ import java.security.NoSuchAlgorithmException; @Slf4j -@RestController +@Controller +//@RestController @Api(value = "FiuuReturnController", tags = "FIUU支付-ReturnURL") @RequestMapping(value = "/api/fuPayReturn") public class FiuuReturnController { + @PostMapping("/payment/callback") + public String handlePaymentCallback( + @RequestParam("amount") String amount, + @RequestParam("orderid") String orderId, + @RequestParam("tranID") String tranId, + @RequestParam("status") String status, + @RequestParam("domain") String domain, + @RequestParam("currency") String currency, + @RequestParam("paydate") String payDate, + @RequestParam("skey") String skey, + Model model) { + +// // 验证skey以确保数据完整性 +// if (!validateSkey(tranId, orderId, status, domain, amount, currency, payDate, skey)) { +// return "error"; // 如果验证失败,跳转到错误页面 +// } + + // 将支付结果信息传递给支付成功页面 + model.addAttribute("amount", amount); + model.addAttribute("orderId", orderId); + model.addAttribute("tranId", tranId); + model.addAttribute("status", status); + model.addAttribute("currency", currency); + model.addAttribute("payDate", payDate); + + // 跳转到支付成功页面 + return "payment-success"; + } + + private boolean validateSkey(String tranId, String orderId, String status, String domain, + String amount, String currency, String payDate, String skey) { + // 这里实现skey的验证逻辑 + // 根据支付网关提供的skey生成规则,生成skey并与传入的skey进行比较 + // 如果一致,返回true,否则返回false + return true; // 这里假设验证通过 + } + private static final String SECRET_KEY = "59c709fc18978a6a83b87f05d37cecbf"; @Resource private MallOrderInfoMapper mallOrderInfoMapper; diff --git a/src/main/java/cc/mrbird/febs/pay/util/FiuuUtil.java b/src/main/java/cc/mrbird/febs/pay/util/FiuuUtil.java index b7c1ede..a048bb4 100644 --- a/src/main/java/cc/mrbird/febs/pay/util/FiuuUtil.java +++ b/src/main/java/cc/mrbird/febs/pay/util/FiuuUtil.java @@ -66,8 +66,8 @@ Map<String, String> params = new LinkedHashMap<>(); params.put("RefundType", "P"); // P: Partial Refund, F: Full Refund params.put("MerchantID", MERCHANT_ID); - params.put("RefID", "2025020611124868512_RITEM42432121"); // 商户唯一退款ID - params.put("TxnID", "2685352601"); // Fiuu原始交易ID + params.put("RefID", "2025020611124868512_RITEM2687855760"); // 商户唯一退款ID + params.put("TxnID", "2687855760"); // Fiuu原始交易ID params.put("Amount", "1.00"); // 退款金额 // 生成签名 diff --git a/src/main/resources/templates/payment-success.html b/src/main/resources/templates/payment-success.html new file mode 100644 index 0000000..c96b9ad --- /dev/null +++ b/src/main/resources/templates/payment-success.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html xmlns:th="http://www.thymeleaf.org"> +<head> + <title>Payment Success</title> +</head> +<body> +<h1>Payment Successful</h1> +<p>Order ID: <span th:text="${orderId}"></span></p> +<p>Transaction ID: <span th:text="${tranId}"></span></p> +<p>Amount: <span th:text="${amount}"></span> <span th:text="${currency}"></span></p> +<p>Payment Date: <span th:text="${payDate}"></span></p> +</body> +</html> \ No newline at end of file -- Gitblit v1.9.1