public AjaxResult inspectToken(@RequestBody JSONObject jsonObject){
boolean result=false;
HashMap<String, Object> data = new HashMap<>();
String token ="";
//获取前台传入的twttoken
if(!jsonObject.getString("token").equals("")){
//token解析
token = jsonObject.getString("token");
try {
//token解析成loginUser对象
Claims claims = tokenService.parseToken(token);
String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
//因为在redis中是以userkey为键值存储
String userKey = tokenService.getTokenKey(uuid);
//根据键值userkey获取loginUser对象
LoginUser user = redisCache.getCacheObject(userKey);
if(!ObjectUtils.isEmpty(user)){
result=true;
}
data.put("result",result);
return new AjaxResult(200, "success",data);
}catch (SignatureException e){
data.put("result",false);
return new AjaxResult(200, "fail",data);
}
}else{
data.put("detail","传入token为空!");
return new AjaxResult(200, "fail",data);
}
}
若依根据JWTToken验证token获取用户信息
最新推荐文章于 2024-09-14 18:25:33 发布