新增根据token获取用户信息接口
This commit is contained in:
@ -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));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user