diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUsdtDemoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUsdtDemoController.java index c93b180..3610344 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUsdtDemoController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUsdtDemoController.java @@ -103,7 +103,8 @@ public class SysUsdtDemoController { /** 使用 RSA-AES-HMAC 协议创建支付订单。 */ @PostMapping("/pay") public AjaxResult pay(@RequestParam("amount") String amount, - @RequestParam(value = "walletUserName", required = false) String walletUserName) { + @RequestParam(value = "walletUserName", required = false) String walletUserName, + @RequestParam(value = "redirectUrl", required = false) String redirectUrl) { BigDecimal paymentAmount = parseAmount(amount); String apiUrl = optionalEnv("PAYMENT_API_URL", DEFAULT_API_URL); try { @@ -116,8 +117,8 @@ public class SysUsdtDemoController { params.put("amount", paymentAmount.toPlainString()); params.put("notify_url", optionalEnv("PAYMENT_NOTIFY_URL", contextPath + "/system/demoUsdt/notify")); - params.put("redirect_url", optionalEnv("PAYMENT_REDIRECT_URL", - contextPath + "/system/demoUsdt/redirect")); + params.put("redirect_url", normalizeRedirectUrl(redirectUrl, optionalEnv("PAYMENT_REDIRECT_URL", + contextPath + "/system/demoUsdt/redirect"))); return AjaxResult.success(sendEncryptedRequest(apiUrl, params, "创建支付订单失败")); } catch (RestClientResponseException ex) { @@ -257,6 +258,17 @@ public class SysUsdtDemoController { return normalized; } + private String normalizeRedirectUrl(String value, String defaultValue) { + if (StringUtils.isBlank(value)) return defaultValue; + String normalized = value.trim(); + if (normalized.length() > 512 || !(normalized.startsWith("https://") + || normalized.startsWith("http://localhost") + || normalized.startsWith("http://127.0.0.1"))) { + throw new CustomException("跳转地址必须使用HTTPS"); + } + return normalized; + } + protected String requiredEnv(String name) { String value = System.getenv(name); if (StringUtils.isBlank(value)) {