feat: support notify url in checkout
This commit is contained in:
1 parent
79f829c12e
commit
77eece5e90
1 file changed
+8
-7
+8
-7
@@ -104,7 +104,8 @@ public class SysUsdtDemoController {
|
|||||||
@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) {
|
@RequestParam(value = "redirectUrl", required = false) String redirectUrl,
|
||||||
|
@RequestParam(value = "notifyUrl", required = false) String notifyUrl) {
|
||||||
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 {
|
||||||
@@ -115,10 +116,10 @@ public class SysUsdtDemoController {
|
|||||||
+ UUID.randomUUID().toString().substring(0, 8));
|
+ UUID.randomUUID().toString().substring(0, 8));
|
||||||
params.put("walletUserName", normalizeWalletUserName(walletUserName));
|
params.put("walletUserName", normalizeWalletUserName(walletUserName));
|
||||||
params.put("amount", paymentAmount.toPlainString());
|
params.put("amount", paymentAmount.toPlainString());
|
||||||
params.put("notify_url", optionalEnv("PAYMENT_NOTIFY_URL",
|
params.put("notify_url", normalizeCallbackUrl(notifyUrl, optionalEnv("PAYMENT_NOTIFY_URL",
|
||||||
contextPath + "/system/demoUsdt/notify"));
|
contextPath + "/system/demoUsdt/notify"), "异步回调地址"));
|
||||||
params.put("redirect_url", normalizeRedirectUrl(redirectUrl, optionalEnv("PAYMENT_REDIRECT_URL",
|
params.put("redirect_url", normalizeCallbackUrl(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) {
|
||||||
@@ -258,13 +259,13 @@ public class SysUsdtDemoController {
|
|||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String normalizeRedirectUrl(String value, String defaultValue) {
|
private String normalizeCallbackUrl(String value, String defaultValue, String label) {
|
||||||
if (StringUtils.isBlank(value)) return defaultValue;
|
if (StringUtils.isBlank(value)) return defaultValue;
|
||||||
String normalized = value.trim();
|
String normalized = value.trim();
|
||||||
if (normalized.length() > 512 || !(normalized.startsWith("https://")
|
if (normalized.length() > 512 || !(normalized.startsWith("https://")
|
||||||
|| normalized.startsWith("http://localhost")
|
|| normalized.startsWith("http://localhost")
|
||||||
|| normalized.startsWith("http://127.0.0.1"))) {
|
|| normalized.startsWith("http://127.0.0.1"))) {
|
||||||
throw new CustomException("跳转地址必须使用HTTPS");
|
throw new CustomException(label + "必须使用HTTPS");
|
||||||
}
|
}
|
||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user