diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/userinfo/controller/UserInfoController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/userinfo/controller/UserInfoController.java new file mode 100644 index 0000000..0489224 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/userinfo/controller/UserInfoController.java @@ -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 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)); + } + +}