api开放钱包创建接口
This commit is contained in:
1 parent
658e6ccf1e
commit
a2be79377b
26 files changed
+636
-4
No files matched your search
@@ -7,6 +7,7 @@ import com.ruoyi.system.domain.UsdtOrdersPlus;
|
||||
import com.ruoyi.system.service.IAppApiKeysService;
|
||||
import com.ruoyi.system.service.IUsdtOrdersService;
|
||||
import com.ruoyi.system.service.PaymentSignatureService;
|
||||
import com.ruoyi.system.service.AppPrivateKeyCipher;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -25,13 +26,14 @@ public class PaymentApiController {
|
||||
@Autowired private IAppApiKeysService keys;
|
||||
@Autowired private IUsdtOrdersService orders;
|
||||
@Autowired private StringRedisTemplate redis;
|
||||
@Autowired private AppPrivateKeyCipher privateKeyCipher;
|
||||
|
||||
@PostMapping("/create-transaction")
|
||||
public AjaxResult create(@RequestBody Map<String, Object> body) {
|
||||
String signature = String.valueOf(body.get("signature"));
|
||||
Long appId = parseLong(body.get("app_id"));
|
||||
AppApiKeysPlus key = activeKey(appId, body.get("api_key"));
|
||||
if (key == null || !PaymentSignatureService.verify(body, key.getApiSecret(), signature)) return AjaxResult.error("签名无效");
|
||||
if (key == null || !PaymentSignatureService.verify(body, privateKeyCipher.decryptCredentialSecret(key.getApiSecret()), signature)) return AjaxResult.error("签名无效");
|
||||
String orderId = String.valueOf(body.get("order_id"));
|
||||
if (orderId.length() == 0 || orderId.length() > 32 || body.get("amount") == null || body.get("wallet_user_name") == null) return AjaxResult.error("缺少必要参数");
|
||||
if (!validUrl(body.get("notify_url")) || (body.get("redirect_url") != null && !validUrl(body.get("redirect_url")))) return AjaxResult.error("回调地址无效");
|
||||
@@ -51,7 +53,7 @@ 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, key.getApiSecret(), signature)) return AjaxResult.error("签名无效");
|
||||
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"))));
|
||||
if (order == null) return AjaxResult.error("订单不存在");
|
||||
Map<String, Object> result = new HashMap<String, Object>(); result.put("order_id", order.getOrderId()); result.put("trade_id", order.getTradeId()); result.put("status", order.getStatus()); result.put("transaction_id", order.getBlockTransactionId()); return AjaxResult.success(result);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.system.domain.dto.EncryptedRequest;
|
||||
import com.ruoyi.system.domain.vo.DecryptResult;
|
||||
import com.ruoyi.system.service.ApiSecurityService;
|
||||
import com.ruoyi.system.service.WalletOpenApiService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.RestController;
|
||||
|
||||
/** 免登录商户钱包 API;生产环境必须由 HTTPS 反向代理保护。 */
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/wallet")
|
||||
public class WalletOpenApiController {
|
||||
@Autowired private ApiSecurityService apiSecurityService;
|
||||
@Autowired private WalletOpenApiService walletOpenApiService;
|
||||
|
||||
@Log(title = "开放 API 创建钱包", businessType = BusinessType.INSERT,
|
||||
isSaveRequestData = false, isSaveResponseData = false)
|
||||
@PostMapping("/create")
|
||||
public AjaxResult create(@RequestBody EncryptedRequest request) {
|
||||
DecryptResult decrypted = apiSecurityService.decryptAndVerify(request);
|
||||
return AjaxResult.success(walletOpenApiService.createWallet(decrypted));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user