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