支付成功页面添加

This commit is contained in:
lu7213 committed 2026-10-14 04:04:49 -04:00
1 parent 935307e9ca
commit dcd8eadd20
2 files changed
+62 -42

No files matched your search

@@ -43,6 +43,8 @@ public class SysUsdtDemoController {
private static final Logger log = LoggerFactory.getLogger(SysUsdtDemoController.class);
private static final String DEFAULT_API_URL =
"http://192.168.3.103:2020/api/v1/order/create-transaction";
private static final String DEFAULT_QUERY_API_URL =
"http://192.168.3.103:2020/api/v1/order/query";
private final RestTemplate restTemplate;
public SysUsdtDemoController() {
@@ -74,12 +76,7 @@ public class SysUsdtDemoController {
@RequestParam(value = "walletUserName", required = false) String walletUserName) {
BigDecimal paymentAmount = parseAmount(amount);
String apiUrl = optionalEnv("PAYMENT_API_URL", DEFAULT_API_URL);
String apiKey = requiredEnvWithAlias("PAYMENT_API_KEY", "PAYMENT_API_KEK");
String apiSecret = requiredEnv("PAYMENT_API_SECRET");
String publicKeyText = requiredEnv("PAYMENT_RSA_PUBLIC_KEY").replace("\\n", "\n");
try {
PublicKey publicKey = RsaKeyUtil.loadPublicKey(publicKeyText);
String contextPath = ServletUriComponentsBuilder.fromCurrentContextPath()
.build().toUriString();
Map<String, Object> params = new HashMap<String, Object>();
@@ -92,17 +89,7 @@ public class SysUsdtDemoController {
params.put("redirect_url", optionalEnv("PAYMENT_REDIRECT_URL",
contextPath + "/system/demoUsdt/redirect"));
EncryptedRequest encrypted = SecureClient.encrypt(apiKey, apiSecret, publicKey, params);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(java.util.Collections.singletonList(MediaType.APPLICATION_JSON));
ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST,
new HttpEntity<EncryptedRequest>(encrypted, headers), String.class);
JSONObject result = JSON.parseObject(response.getBody());
if (result == null || result.getIntValue("code") != 200 || result.get("data") == null) {
throw new CustomException(result == null ? "创建支付订单失败" : result.getString("msg"));
}
return AjaxResult.success(result.get("data"));
return AjaxResult.success(sendEncryptedRequest(apiUrl, params, "创建支付订单失败"));
} catch (RestClientResponseException ex) {
log.warn("支付演示请求失败,HTTP状态={}", ex.getRawStatusCode());
throw new CustomException("支付服务暂时不可用,请稍后重试");
@@ -114,6 +101,50 @@ public class SysUsdtDemoController {
}
}
/** 查询支付状态;API 凭据和加密过程不会暴露给浏览器。 */
@PostMapping("/order-status")
public AjaxResult orderStatus(@RequestParam("orderId") String orderId) {
String normalized = orderId == null ? "" : orderId.trim();
if (normalized.isEmpty() || normalized.length() > 32
|| !normalized.matches("[A-Za-z0-9_-]+")) {
throw new CustomException("订单号格式不正确");
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("order_id", normalized);
String queryUrl = optionalEnv("PAYMENT_QUERY_API_URL", DEFAULT_QUERY_API_URL);
try {
return AjaxResult.success(sendEncryptedRequest(queryUrl, params, "查询支付订单失败"));
} catch (RestClientResponseException ex) {
log.warn("支付状态查询失败,HTTP状态={}", ex.getRawStatusCode());
throw new CustomException("支付状态查询暂时不可用");
} catch (CustomException ex) {
throw ex;
} catch (Exception ex) {
log.warn("支付状态查询失败,异常类型={}", ex.getClass().getSimpleName());
throw new CustomException("支付状态查询暂时不可用");
}
}
private Object sendEncryptedRequest(String apiUrl, Map<String, Object> params,
String failureMessage) throws Exception {
String apiKey = requiredEnvWithAlias("PAYMENT_API_KEY", "PAYMENT_API_KEK");
String apiSecret = requiredEnv("PAYMENT_API_SECRET");
PublicKey publicKey = RsaKeyUtil.loadPublicKey(
requiredEnv("PAYMENT_RSA_PUBLIC_KEY").replace("\\n", "\n"));
EncryptedRequest encrypted = SecureClient.encrypt(apiKey, apiSecret, publicKey, params);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(java.util.Collections.singletonList(MediaType.APPLICATION_JSON));
ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST,
new HttpEntity<EncryptedRequest>(encrypted, headers), String.class);
JSONObject result = JSON.parseObject(response.getBody());
if (result == null || result.getIntValue("code") != 200 || result.get("data") == null) {
throw new CustomException(result == null || StringUtils.isBlank(result.getString("msg"))
? failureMessage : result.getString("msg"));
}
return result.get("data");
}
private BigDecimal parseAmount(String amount) {
try {
BigDecimal value = new BigDecimal(amount);