parent
81f3804527
commit
929caaf234
@ -0,0 +1,27 @@
|
|||||||
|
package com.mashibing.apipassenger.controller;
|
||||||
|
|
||||||
|
import com.mashibing.apipassenger.service.UserService;
|
||||||
|
import com.mashibing.internalcommon.dto.ResponseResult;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@GetMapping("/users")
|
||||||
|
public ResponseResult getUsers(HttpServletRequest request){
|
||||||
|
|
||||||
|
// 从http请求中获取 accessToken
|
||||||
|
String accessToken = request.getHeader("Authorization");
|
||||||
|
|
||||||
|
return userService.getUserByAccessToken(accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.mashibing.apipassenger.service;
|
||||||
|
|
||||||
|
import com.mashibing.internalcommon.constant.CommonStatusEnum;
|
||||||
|
import com.mashibing.internalcommon.dto.PassengerUser;
|
||||||
|
import com.mashibing.internalcommon.dto.ResponseResult;
|
||||||
|
import com.mashibing.internalcommon.dto.TokenResult;
|
||||||
|
import com.mashibing.internalcommon.util.JwtUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class UserService {
|
||||||
|
|
||||||
|
public ResponseResult getUserByAccessToken(String accessToken){
|
||||||
|
|
||||||
|
log.info("accessToken = "+accessToken);
|
||||||
|
// 根据传入 accessToken 解析出用户手机号
|
||||||
|
TokenResult tokenResult = JwtUtils.checkToken(accessToken);
|
||||||
|
if(tokenResult == null){
|
||||||
|
return ResponseResult.fail(CommonStatusEnum.FAIL.getCode(),CommonStatusEnum.FAIL.getValue());
|
||||||
|
}
|
||||||
|
String phone = tokenResult.getPhone();
|
||||||
|
|
||||||
|
// 根据手机号 查询用户信息
|
||||||
|
|
||||||
|
PassengerUser passengerUser = new PassengerUser();
|
||||||
|
|
||||||
|
|
||||||
|
return ResponseResult.success(passengerUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue