添加token校验接口
This commit is contained in:
parent
8e28cdc692
commit
6b042eed63
@ -1,3 +1,9 @@
|
|||||||
#TODO
|
|
||||||
|
修订记录
|
||||||
|
|
||||||
|
| 版本 | 时间 | 修订人 | 改动点 |
|
||||||
|
| :--: |:----------:|:-------:|:-------------------:|
|
||||||
|
| 1.0.0 | 2025-06-05 | Luke.Ye | 添加修订记录(新增token校验接口) |
|
||||||
|
| | | | |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -47,6 +47,20 @@ public class LoginController {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/check")
|
||||||
|
public ResponseEntity<?> check(@RequestHeader("Authorization") String token) {
|
||||||
|
if (isValidToken(token)) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("code", 0);
|
||||||
|
result.put("msg", "校验成功");
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("code", 401);
|
||||||
|
result.put("msg", "未授权");
|
||||||
|
return ResponseEntity.status(401).body(result);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isValidToken(String token) {
|
public static boolean isValidToken(String token) {
|
||||||
if (token == null || !tokenStore.containsKey(token)) return false;
|
if (token == null || !tokenStore.containsKey(token)) return false;
|
||||||
long loginAt = tokenStore.get(token);
|
long loginAt = tokenStore.get(token);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user