代码格式化

This commit is contained in:
lu7213 committed 2026-10-18 10:26:02 -04:00
1 parent 64ba6cd28e
commit 6bdf96ab70
1 file changed
+58 -34
@@ -12,21 +12,9 @@ import com.ruoyi.system.service.PaymentSignatureService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestClientResponseException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
@@ -40,7 +28,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/** 公开支付演示入口;加密凭据仅从服务端环境变量读取。 */
/**
* 公开支付演示入口;加密凭据仅从服务端环境变量读取。
*/
@RestController
@RequestMapping("/system/demoUsdt")
public class SysUsdtDemoController {
@@ -103,7 +93,9 @@ public class SysUsdtDemoController {
return ResponseEntity.ok("redirect SUCCESS");
}
/** 使用 RSA-AES-HMAC 协议创建支付订单。 */
/**
* 使用 RSA-AES-HMAC 协议创建支付订单。
*/
@PostMapping("/pay")
public AjaxResult pay(@RequestParam("amount") String amount,
@RequestParam(value = "walletUserName", required = false) String walletUserName,
@@ -136,7 +128,9 @@ public class SysUsdtDemoController {
}
}
/** 查询支付状态;API 凭据和加密过程不会暴露给浏览器。 */
/**
* 查询支付状态;API 凭据和加密过程不会暴露给浏览器。
*/
@PostMapping("/order-status")
public AjaxResult orderStatus(@RequestParam("orderId") String orderId) {
String normalized = orderId == null ? "" : orderId.trim();
@@ -160,36 +154,64 @@ public class SysUsdtDemoController {
}
}
/** RSA-AES-HMAC代付创建客户端示例,不依赖浏览器上下文。 */
/**
* RSA-AES-HMAC代付创建客户端示例,不依赖浏览器上下文。
*/
@PostMapping("/payout")
public AjaxResult payout(@RequestParam String orderId, @RequestParam String currency,
@RequestParam String amount, @RequestParam String toAddress,
@RequestParam String notifyUrl, @RequestParam(required = false) String redirectUrl) {
Map<String,Object> p=new HashMap<String,Object>();p.put("order_id",orderId);p.put("currency",currency);
p.put("amount",amount);p.put("to_address",toAddress);p.put("notify_url",notifyUrl);p.put("redirect_url",redirectUrl);
try{return AjaxResult.success(sendEncryptedRequest(optionalEnv("PAYOUT_API_URL",DEFAULT_PAYOUT_API_URL),p,"创建代付订单失败"));}
catch(Exception e){throw e instanceof CustomException?(CustomException)e:new CustomException("创建代付订单失败");}
Map<String, Object> p = new HashMap<String, Object>();
p.put("order_id", orderId);
p.put("currency", currency);
p.put("amount", amount);
p.put("to_address", toAddress);
p.put("notify_url", notifyUrl);
p.put("redirect_url", redirectUrl);
try {
return AjaxResult.success(sendEncryptedRequest(optionalEnv("PAYOUT_API_URL", DEFAULT_PAYOUT_API_URL), p, "创建代付订单失败"));
} catch (Exception e) {
throw e instanceof CustomException ? (CustomException) e : new CustomException("创建代付订单失败");
}
}
/** 代付查询示例;完成后响应中的redirect_url由商户前端自行跳转。 */
/**
* 代付查询示例;完成后响应中的redirect_url由商户前端自行跳转。
*/
@PostMapping("/payout-status")
public AjaxResult payoutStatus(@RequestParam String orderId) {
Map<String,Object> p=new HashMap<String,Object>();p.put("order_id",orderId);
try{return AjaxResult.success(sendEncryptedRequest(optionalEnv("PAYOUT_QUERY_API_URL",DEFAULT_PAYOUT_QUERY_API_URL),p,"查询代付订单失败"));}
catch(Exception e){throw e instanceof CustomException?(CustomException)e:new CustomException("查询代付订单失败");}
Map<String, Object> p = new HashMap<String, Object>();
p.put("order_id", orderId);
try {
return AjaxResult.success(sendEncryptedRequest(optionalEnv("PAYOUT_QUERY_API_URL", DEFAULT_PAYOUT_QUERY_API_URL), p, "查询代付订单失败"));
} catch (Exception e) {
throw e instanceof CustomException ? (CustomException) e : new CustomException("查询代付订单失败");
}
}
@PostMapping("/payout-notify") @ResponseBody
@PostMapping("/payout-notify")
@ResponseBody
public ResponseEntity<String> payoutNotify(@RequestHeader(value = "X-Payment-Api-Key", required = false) String apiKey,
@RequestHeader(value = "X-Payment-Rsa-Signature", required = false) String signature, @RequestBody(required = false) String body) {
try{JSONObject p=JSON.parseObject(body);if(p==null||!"3".equals(p.getString("status"))||!verifyCallback(p,apiKey,signature))return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("invalid signature");return ResponseEntity.ok("ok");}
catch(Exception e){return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("invalid signature");}}
try {
JSONObject p = JSON.parseObject(body);
if (p == null || !"3".equals(p.getString("status")) || !verifyCallback(p, apiKey, signature))
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("invalid signature");
return ResponseEntity.ok("ok");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("invalid signature");
}
}
@GetMapping("/payout-redirect") @ResponseBody
@GetMapping("/payout-redirect")
@ResponseBody
public ResponseEntity<String> payoutRedirect(@RequestParam Map<String, String> parameters) {
String signature=parameters.remove("signature");parameters.remove("api_key");
if(!"3".equals(parameters.get("status"))||!verifyCallback(parameters,null,signature))return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("invalid signature");
return ResponseEntity.ok("payout redirect SUCCESS");}
String signature = parameters.remove("signature");
parameters.remove("api_key");
if (!"3".equals(parameters.get("status")) || !verifyCallback(parameters, null, signature))
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("invalid signature");
return ResponseEntity.ok("payout redirect SUCCESS");
}
private Object sendEncryptedRequest(String apiUrl, Map<String, Object> params,
String failureMessage) throws Exception {
@@ -223,7 +245,9 @@ public class SysUsdtDemoController {
}
}
/** 将异步通知JSON规范化为签名字段,拒绝嵌套值和缺失的核心订单字段。 */
/**
* 将异步通知JSON规范化为签名字段,拒绝嵌套值和缺失的核心订单字段。
*/
private JSONObject parseCallbackPayload(String body) {
if (StringUtils.isBlank(body)) {
throw new CustomException("回调正文为空");