feat(sip):提供给NEX的接口调试

dev_1.0.1
chenh 2026-01-15 16:52:26 +08:00
parent cc29006013
commit b3e5568216
1 changed files with 7 additions and 24 deletions

View File

@ -37,21 +37,6 @@ public class ShiroUtils {
// 检查是否是API Key认证 // 检查是否是API Key认证
Object principal = subject.getPrincipal(); Object principal = subject.getPrincipal();
if (principal instanceof SysUser) {
// 正常登录用户
return (SysUser) principal;
} else if (principal == null) {
// 检查是否是API Key请求
HttpServletRequest request = ServletUtils.getRequest();
String apiKey = request.getHeader("X-API-Key");
if (StringUtils.isNotEmpty(apiKey) && NEX_API_KEY.equals(apiKey)) {
Long userId = validateApiKey(apiKey); // 验证API Key并获取用户ID
if (userId != null) {
SysUser user = loadUserById(userId);
return user;
}
}
}
// 传统方式获取用户 // 传统方式获取用户
SysUser user = null; SysUser user = null;
@ -63,11 +48,8 @@ public class ShiroUtils {
// 检查是否是API Key请求 // 检查是否是API Key请求
HttpServletRequest request = ServletUtils.getRequest(); HttpServletRequest request = ServletUtils.getRequest();
String apiKey = request.getHeader("X-API-Key"); String apiKey = request.getHeader("X-API-Key");
if (StringUtils.isNotEmpty(apiKey)) { if (StringUtils.isNotEmpty(apiKey)&& NEX_API_KEY.equals(apiKey)) {
Long userId = validateApiKey(apiKey); // 验证API Key并获取用户ID return loadUserById();
user = loadUserById(userId);
setSysUser(user);
return user;
} }
return user; return user;
} }
@ -79,18 +61,19 @@ public class ShiroUtils {
// 查询数据库验证API Key并返回对应的用户ID // 查询数据库验证API Key并返回对应的用户ID
// 这里应该查询API Key表获取关联的用户ID // 这里应该查询API Key表获取关联的用户ID
// 例如: select user_id from sys_api_key where api_key = ? and status = 'A' // 例如: select user_id from sys_api_key where api_key = ? and status = 'A'
return 1L; return 101L;
} }
/** /**
* ID * ID
*/ */
private static SysUser loadUserById(Long userId) { private static SysUser loadUserById() {
// 从数据库加载用户信息 // 从数据库加载用户信息
// 例如: select * from sys_user where user_id = ? // 例如: select * from sys_user where user_id = ?
SysUser user = new SysUser(); SysUser user = new SysUser();
user.setUserId(1L); user.setUserId(101L);
user.setUserName("admin"); user.setUserName("乐喽ch");
user.setLoginName("leoloch");
return user; return user;
} }