This commit is contained in:
Leo
2026-01-15 21:07:53 +08:00
parent 4379277a08
commit c837917be3
2 changed files with 44 additions and 9 deletions

View File

@@ -112,15 +112,22 @@ public class WPS365Controller extends BaseController {
@GetMapping("/tokenStatus")
public AjaxResult getTokenStatus(@RequestParam(required = false) String userId) {
try {
// 如果没有提供userId可以尝试从当前登录用户获取
// 这里暂时需要前端传入userId后续可以集成到认证系统中
if (userId == null || userId.trim().isEmpty()) {
return AjaxResult.error("userId不能为空");
WPS365TokenInfo tokenInfo = null;
// 如果提供了userId查询指定用户的token
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) {
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);
@@ -129,6 +136,9 @@ public class WPS365Controller extends BaseController {
result.put("isValid", isValid);
result.put("userId", tokenInfo.getUserId());
result.put("expired", tokenInfo.isExpired());
if (tokenInfo.getExpiresIn() != null) {
result.put("expiresIn", tokenInfo.getExpiresIn());
}
return AjaxResult.success("获取Token状态成功", result);
} catch (Exception e) {