新增根据token获取用户信息接口

This commit is contained in:
付庆吉
2021-10-25 15:39:23 +08:00
parent 6d26b06ea6
commit 8d22ec7ef0

View File

@ -0,0 +1,39 @@
package com.chinaunicom.mall.ebtp.extend.userinfo.controller;
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService;
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/v1/userinfo/")
public class UserInfoController {
@Autowired
private UserInfoService service;
/**
* 获取用户信息
*
* @param token (认证token)
* @return
*/
@GetMapping("get")
public ResponseEntity<BaseCacheUser> getUserInfo(
@RequestHeader(name = "Authorization", required = false) String token) {
if (StringUtils.isEmpty(token)) {
log.error("access token is empty");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
return ResponseEntity.ok(service.getUserInfo(token));
}
}