huliguo
4 天以前 1cb09e4cde9fb97b8369478a9fc16418ac4e29a4
src/main/java/com/linghu/controller/AuthController.java
@@ -3,17 +3,18 @@
import java.util.HashMap;
import java.util.Map;
import com.linghu.utils.OpenCryptUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.linghu.model.entity.User;
import com.linghu.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(value = "认证接口", tags = "认证管理")
@RestController
@RequestMapping("/auth")
public class AuthController {
@@ -21,6 +22,7 @@
    private String secretKey;
    @PostMapping("/login")
    @ApiOperation(value = "外部登录")
    public ResponseEntity<?> externalLogin(
            @RequestBody User user) {
@@ -36,6 +38,7 @@
    // 获取用户信息
    @PostMapping("/getUserInfo")
    @ApiOperation(value = "获取用户信息")
    public ResponseEntity<?> getUserInfo(@RequestParam String token) {
        // 解析JWT令牌,获取用户信息
        JwtUtils jwtUtils = new JwtUtils(secretKey, 3600);
@@ -43,4 +46,32 @@
        // 返回用户信息
        return ResponseEntity.ok(user);
    }
    //open-crypt解析token
    @GetMapping("/parseToken")
    @ApiOperation(value = "解析token")
    public ResponseEntity<?> parseToken(@RequestParam String token) {
        if (token == null || "".equals(token)){
            return ResponseEntity.ok("token为空");
        }
        // 解析token,获取用户信息
        OpenCryptUtil openCryptUtil = new OpenCryptUtil();
        String decrypt = openCryptUtil.decrypt(token);
        System.out.println(decrypt);
        System.out.println("----------------");
        // 返回用户信息
        return ResponseEntity.ok(decrypt);
    }
    @GetMapping("/getToken")
    @ApiOperation(value = "获取token")
    public ResponseEntity<?> getToken(@RequestBody User user) {
        // 创建用户对
        // 创建JwtUtils对象,并生成JWT令牌
        OpenCryptUtil openCryptUtil = new OpenCryptUtil();
        String decrypt = openCryptUtil.encrypt(user);
        // 返回JWT令牌
        return ResponseEntity.ok(decrypt);
    }
}