新增apiKey和相关逻辑
This commit is contained in:
1 parent
bc772b8b15
commit
051f78b59c
9 files changed
+77
-15
No files matched your search
@@ -32,14 +32,14 @@ public class AppApiKeysController extends BaseController {
|
||||
@PreAuthorize("@ss.hasPermi('system:keys:getByIds')" )
|
||||
@PostMapping("/getByIds" )
|
||||
public AjaxResult getByIds(@RequestBody Ids ids) {
|
||||
List<AppApiKeysPlus> list = appApiKeysService.getByIds(ids.getLongIds(), false, AppApiKeysPlus::getApiSecret, AppApiKeysPlus::getId);
|
||||
List<AppApiKeysPlus> list = appApiKeysService.getByIds(ids.getLongIds(), false, AppApiKeysPlus::getApiKey, AppApiKeysPlus::getId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:keys:user-getByIds')" )
|
||||
@PostMapping("/user/getByIds" )
|
||||
public AjaxResult userGetByIds(@RequestBody Ids ids) {
|
||||
List<AppApiKeysPlus> list = appApiKeysService.getByIds(ids.getLongIds(), true, AppApiKeysPlus::getApiSecret,AppApiKeysPlus::getUserId, AppApiKeysPlus::getId);
|
||||
List<AppApiKeysPlus> list = appApiKeysService.getByIds(ids.getLongIds(), true, AppApiKeysPlus::getApiKey, AppApiKeysPlus::getUserId, AppApiKeysPlus::getId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
/** 对外支付 API,统一使用 JSON 和签名校验。 */
|
||||
@RestController
|
||||
@@ -29,8 +30,8 @@ public class PaymentApiController {
|
||||
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);
|
||||
if (key == null || !PaymentSignatureService.sign(body, key.getApiSecret()).equalsIgnoreCase(signature)) return AjaxResult.error("签名无效");
|
||||
AppApiKeysPlus key = activeKey(appId, body.get("api_key"));
|
||||
if (key == null || !PaymentSignatureService.verify(body, 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("回调地址无效");
|
||||
@@ -49,13 +50,19 @@ public class PaymentApiController {
|
||||
|
||||
@PostMapping("/query")
|
||||
public AjaxResult query(@RequestBody Map<String, Object> body) {
|
||||
Long appId = parseLong(body.get("app_id")); AppApiKeysPlus key = activeKey(appId); String signature = String.valueOf(body.get("signature"));
|
||||
if (key == null || !PaymentSignatureService.sign(body, key.getApiSecret()).equalsIgnoreCase(signature)) return AjaxResult.error("签名无效");
|
||||
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("签名无效");
|
||||
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);
|
||||
}
|
||||
private AppApiKeysPlus activeKey(Long appId) { return appId == null ? null : keys.getOne(new LambdaQueryWrapper<AppApiKeysPlus>().eq(AppApiKeysPlus::getAppId, appId).eq(AppApiKeysPlus::getStatus, 1)); }
|
||||
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 boolean validUrl(Object value) { try { if (value == null) return false; URI uri = new URI(String.valueOf(value)); return ("https".equalsIgnoreCase(uri.getScheme()) || "http".equalsIgnoreCase(uri.getScheme())) && uri.getHost() != null; } catch (Exception ex) { return false; } }
|
||||
}
|
||||
Reference in new issue
Block a user