商户也要可以配置所属apps的api_secret和api_key

This commit is contained in:
lu7213 committed 2026-10-19 01:37:21 -04:00
1 parent bdad69ba77
commit f5b1a9f638
2 files changed
+73 -10

No files matched your search

@@ -58,31 +58,45 @@ public class AppApiKeysServiceImpl extends ServiceImpl<AppApiKeysMapper, AppApiK
}
private void checkUserPlus(List<AppApiKeysPlus> list) {
Long currentUserId = requireCurrentUserId();
for (AppApiKeysPlus item : list) {
if (null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()) {
throw new RuntimeException("无权限");
if (item == null || !Objects.equals(item.getUserId(), currentUserId)) {
throw new CustomException("无权操作该 API Key");
}
}
}
private void checkUser(List<AppApiKeys> list) {
Long currentUserId = requireCurrentUserId();
for (AppApiKeys item : list) {
if (null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()) {
throw new RuntimeException("无权限");
if (item == null || !Objects.equals(item.getUserId(), currentUserId)) {
throw new CustomException("无权操作该 API Key");
}
}
}
private void checkUser(AppApiKeysPlus item) {
if (null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()) {
throw new RuntimeException("无权限");
if (item == null) {
throw new CustomException("API Key 不存在或已删除");
}
if (!Objects.equals(item.getUserId(), requireCurrentUserId())) {
throw new CustomException("无权操作该 API Key");
}
}
private void checkUser(AppApiKeys item) {
if (null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()) {
throw new RuntimeException("无权限");
if (item == null) {
throw new CustomException("API Key 不存在或已删除");
}
if (!Objects.equals(item.getUserId(), requireCurrentUserId())) {
throw new CustomException("无权操作该 API Key");
}
}
private Long requireCurrentUserId() {
Long userId = SecurityUtils.getUserId();
if (userId == null) throw new CustomException("无法获取当前用户");
return userId;
}
@Override
@@ -297,7 +311,7 @@ public class AppApiKeysServiceImpl extends ServiceImpl<AppApiKeysMapper, AppApiK
private Apps requireApp(Long appId, boolean isUser) {
Apps app = appsMapper.selectAppsById(appId);
if (app == null) throw new CustomException("商户应用不存在或已删除");
if (isUser && !Objects.equals(app.getUserId(), SecurityUtils.getUserId())) throw new CustomException("无权操作该应用");
if (isUser && !Objects.equals(app.getUserId(), requireCurrentUserId())) throw new CustomException("无权操作该应用");
return app;
}
@@ -305,7 +319,7 @@ public class AppApiKeysServiceImpl extends ServiceImpl<AppApiKeysMapper, AppApiK
if (id == null) throw new CustomException("API Key ID 不能为空");
AppApiKeys key = appApiKeysMapper.selectAppApiKeysById(id);
if (key == null) throw new CustomException("API Key 不存在或已删除");
if (isUser && !Objects.equals(key.getUserId(), SecurityUtils.getUserId())) throw new CustomException("无权操作该 API Key");
if (isUser && !Objects.equals(key.getUserId(), requireCurrentUserId())) throw new CustomException("无权操作该 API Key");
return key;
}