guyue
4 天以前 8f5cb469b825cce61734c84fd633f0dfc3000ee6
src/main/java/com/linghu/controller/AuthController.java
@@ -3,13 +3,10 @@
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;
@@ -49,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);
    }
}