支付成功页面添加
This commit is contained in:
1 parent
935307e9ca
commit
dcd8eadd20
2 files changed
+62
-42
No files matched your search
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.system.domain.AppApiKeysPlus;
|
||||
import com.ruoyi.system.domain.UsdtOrdersPlus;
|
||||
import com.ruoyi.system.domain.dto.EncryptedRequest;
|
||||
import com.ruoyi.system.domain.vo.DecryptResult;
|
||||
@@ -15,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -25,13 +23,9 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/order")
|
||||
public class PaymentApiController {
|
||||
@Autowired
|
||||
private IAppApiKeysService keys;
|
||||
@Autowired
|
||||
private IUsdtOrdersService orders;
|
||||
@Autowired
|
||||
private AppPrivateKeyCipher privateKeyCipher;
|
||||
@Autowired
|
||||
private ApiSecurityService apiSecurityService;
|
||||
@Autowired
|
||||
private PaymentOrderOpenApiService paymentOrderOpenApiService;
|
||||
@@ -45,13 +39,12 @@ public class PaymentApiController {
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
public AjaxResult query(@RequestBody Map<String, Object> body) {
|
||||
Long appId = parseLong(body.get("app_id"));
|
||||
AppApiKeysPlus key = activeKey(appId, body.get("api_key"));
|
||||
String signature = String.valueOf(body.get("signature"));
|
||||
if (key == null || !PaymentSignatureService.verify(body, privateKeyCipher.decryptCredentialSecret(key.getApiSecret()), signature))
|
||||
return AjaxResult.error("签名无效");
|
||||
UsdtOrdersPlus order = orders.getOne(new LambdaQueryWrapper<UsdtOrdersPlus>().eq(UsdtOrdersPlus::getAppId, appId).eq(UsdtOrdersPlus::getOrderId, String.valueOf(body.get("order_id"))));
|
||||
public AjaxResult query(@RequestBody EncryptedRequest request) {
|
||||
DecryptResult decrypted = apiSecurityService.decryptAndVerify(request);
|
||||
String orderId = parseOrderId(decrypted.getPlainData());
|
||||
UsdtOrdersPlus order = orders.getOne(new LambdaQueryWrapper<UsdtOrdersPlus>()
|
||||
.eq(UsdtOrdersPlus::getAppId, decrypted.getAppId())
|
||||
.eq(UsdtOrdersPlus::getOrderId, orderId).last("limit 1"));
|
||||
if (order == null) return AjaxResult.error("订单不存在");
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("order_id", order.getOrderId());
|
||||
@@ -61,19 +54,15 @@ public class PaymentApiController {
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
private AppApiKeysPlus activeKey(Long appId, Object apiKey) {
|
||||
if (appId == null || apiKey == null || String.valueOf(apiKey).trim().isEmpty()) return null;
|
||||
return keys.getOne(new LambdaQueryWrapper<AppApiKeysPlus>().eq(AppApiKeysPlus::getAppId, appId)
|
||||
.eq(AppApiKeysPlus::getApiKey, String.valueOf(apiKey)).eq(AppApiKeysPlus::getStatus, 1)
|
||||
.isNull(AppApiKeysPlus::getDeletedAt)
|
||||
.and(wrapper -> wrapper.isNull(AppApiKeysPlus::getExpiredAt).or().gt(AppApiKeysPlus::getExpiredAt, new Date())));
|
||||
}
|
||||
|
||||
private Long parseLong(Object value) {
|
||||
try {
|
||||
return value == null ? null : Long.valueOf(String.valueOf(value));
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
private String parseOrderId(String plainData) {
|
||||
final String prefix = "order_id=";
|
||||
if (plainData == null || !plainData.startsWith(prefix) || !plainData.endsWith("&")) {
|
||||
throw new com.ruoyi.common.exception.CustomException("业务参数格式错误");
|
||||
}
|
||||
String orderId = plainData.substring(prefix.length(), plainData.length() - 1).trim();
|
||||
if (orderId.isEmpty() || orderId.length() > 32 || orderId.contains("&")) {
|
||||
throw new com.ruoyi.common.exception.CustomException("order_id 格式错误");
|
||||
}
|
||||
return orderId;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user