1
This commit is contained in:
@@ -112,15 +112,22 @@ public class WPS365Controller extends BaseController {
|
|||||||
@GetMapping("/tokenStatus")
|
@GetMapping("/tokenStatus")
|
||||||
public AjaxResult getTokenStatus(@RequestParam(required = false) String userId) {
|
public AjaxResult getTokenStatus(@RequestParam(required = false) String userId) {
|
||||||
try {
|
try {
|
||||||
// 如果没有提供userId,可以尝试从当前登录用户获取
|
WPS365TokenInfo tokenInfo = null;
|
||||||
// 这里暂时需要前端传入userId,后续可以集成到认证系统中
|
|
||||||
if (userId == null || userId.trim().isEmpty()) {
|
// 如果提供了userId,查询指定用户的token
|
||||||
return AjaxResult.error("userId不能为空");
|
if (userId != null && !userId.trim().isEmpty()) {
|
||||||
|
tokenInfo = wps365OAuthServiceImpl.getTokenByUserId(userId);
|
||||||
|
} else {
|
||||||
|
// 如果没有提供userId,尝试查找所有token(通常只有一个)
|
||||||
|
// 这里使用getCurrentToken方法,它会尝试查找可用的token
|
||||||
|
tokenInfo = wps365OAuthService.getCurrentToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
WPS365TokenInfo tokenInfo = wps365OAuthServiceImpl.getTokenByUserId(userId);
|
|
||||||
if (tokenInfo == null) {
|
if (tokenInfo == null) {
|
||||||
return AjaxResult.success("未授权", false);
|
JSONObject result = new JSONObject();
|
||||||
|
result.put("hasToken", false);
|
||||||
|
result.put("isValid", false);
|
||||||
|
return AjaxResult.success("未授权", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isValid = wps365OAuthService.isTokenValid(tokenInfo);
|
boolean isValid = wps365OAuthService.isTokenValid(tokenInfo);
|
||||||
@@ -129,6 +136,9 @@ public class WPS365Controller extends BaseController {
|
|||||||
result.put("isValid", isValid);
|
result.put("isValid", isValid);
|
||||||
result.put("userId", tokenInfo.getUserId());
|
result.put("userId", tokenInfo.getUserId());
|
||||||
result.put("expired", tokenInfo.isExpired());
|
result.put("expired", tokenInfo.isExpired());
|
||||||
|
if (tokenInfo.getExpiresIn() != null) {
|
||||||
|
result.put("expiresIn", tokenInfo.getExpiresIn());
|
||||||
|
}
|
||||||
|
|
||||||
return AjaxResult.success("获取Token状态成功", result);
|
return AjaxResult.success("获取Token状态成功", result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -261,8 +261,33 @@ public class WPS365OAuthServiceImpl implements IWPS365OAuthService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WPS365TokenInfo getCurrentToken() {
|
public WPS365TokenInfo getCurrentToken() {
|
||||||
// 这里需要根据实际业务获取当前用户ID
|
// 尝试查找所有WPS365 token(通常只有一个)
|
||||||
// 暂时返回null,需要在Controller中处理用户ID获取逻辑
|
// 使用Redis的keys命令查找所有匹配的token key
|
||||||
|
try {
|
||||||
|
String pattern = TOKEN_KEY_PREFIX + "*";
|
||||||
|
// 注意:keys命令在生产环境可能性能较差,但这里token数量通常很少
|
||||||
|
java.util.Collection<String> keys = redisCache.keys(pattern);
|
||||||
|
if (keys != null && !keys.isEmpty()) {
|
||||||
|
// 返回第一个找到的有效token
|
||||||
|
for (String key : keys) {
|
||||||
|
WPS365TokenInfo tokenInfo = redisCache.getCacheObject(key);
|
||||||
|
if (tokenInfo != null && isTokenValid(tokenInfo)) {
|
||||||
|
log.debug("找到有效的WPS365 token: {}", key);
|
||||||
|
return tokenInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果没有有效的token,返回第一个(即使过期)
|
||||||
|
for (String key : keys) {
|
||||||
|
WPS365TokenInfo tokenInfo = redisCache.getCacheObject(key);
|
||||||
|
if (tokenInfo != null) {
|
||||||
|
log.debug("找到WPS365 token(可能已过期): {}", key);
|
||||||
|
return tokenInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("查找WPS365 token失败", e);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user