feat: support payment redirect url

This commit is contained in:
lu7213 committed 2026-10-15 04:56:00 -04:00
1 parent ad965d086b
commit 2a85724613
1 file changed
+15 -3
@@ -103,7 +103,8 @@ public class SysUsdtDemoController {
/** 使用 RSA-AES-HMAC 协议创建支付订单。 */ /** 使用 RSA-AES-HMAC 协议创建支付订单。 */
@PostMapping("/pay") @PostMapping("/pay")
public AjaxResult pay(@RequestParam("amount") String amount, 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); BigDecimal paymentAmount = parseAmount(amount);
String apiUrl = optionalEnv("PAYMENT_API_URL", DEFAULT_API_URL); String apiUrl = optionalEnv("PAYMENT_API_URL", DEFAULT_API_URL);
try { try {
@@ -116,8 +117,8 @@ public class SysUsdtDemoController {
params.put("amount", paymentAmount.toPlainString()); params.put("amount", paymentAmount.toPlainString());
params.put("notify_url", optionalEnv("PAYMENT_NOTIFY_URL", params.put("notify_url", optionalEnv("PAYMENT_NOTIFY_URL",
contextPath + "/system/demoUsdt/notify")); contextPath + "/system/demoUsdt/notify"));
params.put("redirect_url", optionalEnv("PAYMENT_REDIRECT_URL", params.put("redirect_url", normalizeRedirectUrl(redirectUrl, optionalEnv("PAYMENT_REDIRECT_URL",
contextPath + "/system/demoUsdt/redirect")); contextPath + "/system/demoUsdt/redirect")));
return AjaxResult.success(sendEncryptedRequest(apiUrl, params, "创建支付订单失败")); return AjaxResult.success(sendEncryptedRequest(apiUrl, params, "创建支付订单失败"));
} catch (RestClientResponseException ex) { } catch (RestClientResponseException ex) {
@@ -257,6 +258,17 @@ public class SysUsdtDemoController {
return normalized; 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) { protected String requiredEnv(String name) {
String value = System.getenv(name); String value = System.getenv(name);
if (StringUtils.isBlank(value)) { if (StringUtils.isBlank(value)) {