guyue
2025-09-05 e4451cbe7eea81c397353e8d5649e52dcbd3b7d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.linghu.controller;
 
 
import com.linghu.model.common.ResponseResult;
import com.linghu.model.dto.TokenRequest;
import com.linghu.service.AuthService;
import com.linghu.utils.OpenCryptUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
 
 
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
 
import javax.validation.Valid;
 
@Api(value = "认证接口", tags = "认证管理")
@RestController
@RequestMapping("/auth")
public class AuthController {
 
    @Autowired
    private AuthService authService;
 
    //open-crypt解析token
    @PostMapping("/parseToken")
    @ApiOperation(value = "解析token")
    public ResponseResult<?> parseToken(@Valid @RequestBody TokenRequest tokenRequest) {
        return authService.parseTokenAuth(tokenRequest);
    }
    @GetMapping("/getToken")
    @ApiOperation(value = "获取token")
    public ResponseEntity<?> getToken(@RequestParam(value = "user" ) String user) {
        // 创建JwtUtils对象,并生成JWT令牌
        OpenCryptUtil openCryptUtil = new OpenCryptUtil();
        String decrypt = openCryptUtil.encrypt(user);
        // 返回JWT令牌
        return ResponseEntity.ok(decrypt);
    }
}