api-passenger、user接口完毕。

master
liuyuanqiang 2 years ago
parent 13b1585eaf
commit fed573aa48

@ -0,0 +1,25 @@
package com.mashibing.apipassenger.controller;
import com.mashibing.apipassenger.service.UserService;
import com.mashibing.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
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 getUser(HttpServletRequest request){
String token = request.getHeader("Authorization");
return userService.getUserByToken(token);
}
}

@ -3,6 +3,8 @@ package com.mashibing.apipassenger.remote;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.request.VerificationCodeDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -11,5 +13,7 @@ public interface ServicePassengerUserClient {
@PostMapping("/user")
public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO);
@GetMapping("/user/{phone}")
public ResponseResult getUserByPhone(@PathVariable("phone") String phone);
}

@ -42,8 +42,8 @@ public class TokenService {
String newRefreshToken = JwtUtils.generateToken(phone, identity, TokenConstants.ACCESS_TOKEN_TYPE);
String accessTokenKey = RedisPrefixUtils.generateTokenKey(phone,identity,TokenConstants.ACCESS_TOKEN_TYPE);
stringRedisTemplate.opsForValue().set(accessTokenKey,newAccessToken,10, TimeUnit.SECONDS);
stringRedisTemplate.opsForValue().set(tokenKey,newRefreshToken,300,TimeUnit.SECONDS);
stringRedisTemplate.opsForValue().set(accessTokenKey,newAccessToken,30, TimeUnit.DAYS);
stringRedisTemplate.opsForValue().set(tokenKey,newRefreshToken,31,TimeUnit.DAYS);
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setRefreshToken(newRefreshToken);

@ -0,0 +1,32 @@
package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServicePassengerUserClient;
import com.mashibing.common.dto.PassengerUser;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.dto.TokenResult;
import com.mashibing.common.request.VerificationCodeDTO;
import com.mashibing.common.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class UserService {
@Autowired
private ServicePassengerUserClient servicePassengerUserClient;
public ResponseResult getUserByToken(String token){
//校验token
log.info("userService--token:" + token);
//根据手机号获取用户信息
TokenResult tokenResult = JwtUtils.checkToken(token);
String phone = tokenResult.getPhone();
log.info("手机号: " + phone);
ResponseResult userByPhone = servicePassengerUserClient.getUserByPhone(phone);
return ResponseResult.success(userByPhone.getData());
}
}

@ -87,8 +87,8 @@ public class VerificationCodeService {
//token存入Redis
String accessTokenRedisKey = RedisPrefixUtils.generateTokenKey(passengerPhone, IdentityConstant.PASSENGER_IDENTITY, TokenConstants.ACCESS_TOKEN_TYPE);
String refreshTokenRedisKey = RedisPrefixUtils.generateTokenKey(passengerPhone, IdentityConstant.PASSENGER_IDENTITY, TokenConstants.REFRESH_TOKEN_TYPE);
stringRedisTemplate.opsForValue().set(accessTokenRedisKey, accessToken, 10,TimeUnit.SECONDS);
stringRedisTemplate.opsForValue().set(refreshTokenRedisKey, refreshToken, 301,TimeUnit.SECONDS);
stringRedisTemplate.opsForValue().set(accessTokenRedisKey, accessToken, 30,TimeUnit.DAYS);
stringRedisTemplate.opsForValue().set(refreshTokenRedisKey, refreshToken, 31,TimeUnit.DAYS);
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setAccessToken(accessToken);

@ -0,0 +1,13 @@
com\mashibing\apipassenger\ApiPassengerApplication.class
com\mashibing\apipassenger\controller\TestController.class
com\mashibing\apipassenger\controller\VerificationCodeController.class
com\mashibing\apipassenger\remote\ServiceVefificationcodeClient.class
com\mashibing\apipassenger\service\TokenService.class
com\mashibing\apipassenger\interceptor\InterceptorConfig.class
com\mashibing\apipassenger\interceptor\JwtInterceptor.class
com\mashibing\apipassenger\controller\UserController.class
com\mashibing\apipassenger\request\VerificationCodeDTO.class
com\mashibing\apipassenger\service\VerificationCodeService.class
com\mashibing\apipassenger\service\UserService.class
com\mashibing\apipassenger\remote\ServicePassengerUserClient.class
com\mashibing\apipassenger\controller\TokenController.class

@ -0,0 +1,13 @@
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\service\VerificationCodeService.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\remote\ServicePassengerUserClient.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\controller\TokenController.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\ApiPassengerApplication.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\controller\VerificationCodeController.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\request\VerificationCodeDTO.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\interceptor\InterceptorConfig.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\service\TokenService.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\interceptor\JwtInterceptor.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\service\UserService.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\controller\UserController.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\controller\TestController.java
D:\Works\workspaces\online-taxi-public\api-passenger\src\main\java\com\mashibing\apipassenger\remote\ServiceVefificationcodeClient.java

@ -15,6 +15,11 @@ public enum CommonStatusEnum {
*/
TOKEN_ERROR(1100,"token错误"),
/**
* user error 1200 ~ 1299
*/
USER_NOT_EXIST(1200,"当前用户不存在"),
/**
*
*/

@ -1,17 +1,20 @@
package com.mashibing.serviceDriverUser.dto;
package com.mashibing.common.dto;
import lombok.Data;
import java.beans.Transient;
import java.time.LocalDateTime;
@Data
public class PassengerUser {
private Long id;
private String passengerPhone;//不是passenger_phone 这里要注意啦!!!
private String passengerPhone;//不是passenger_phonemysql 这里要注意啦!!!
private String passengerName;
private byte passengerGender;
private byte state;
private LocalDateTime gmtCreate;
private LocalDateTime gmtUpdate;
private String profilePhoto;
}

@ -70,7 +70,7 @@ public class JwtUtils {
return tokenResult;
}
public static void main(String[] args) {
String token = JwtUtils.generateToken("13751145166","1", TokenConstants.ACCESS_TOKEN_TYPE);
String token = JwtUtils.generateToken("18626772944","1", TokenConstants.ACCESS_TOKEN_TYPE);
System.out.println("token:" + token);
TokenResult result = JwtUtils.parseToken(token);
System.out.println("phone parsed:" + result.toString());

@ -1 +1,11 @@
com\mashibing\common\dto\ResponseResult.class
com\mashibing\common\constant\CommonStatusEnum.class
com\mashibing\common\dto\PassengerUser.class
com\mashibing\common\response\NumberCodeResponse.class
com\mashibing\common\util\RedisPrefixUtils.class
com\mashibing\common\util\JwtUtils.class
com\mashibing\common\constant\IdentityConstant.class
com\mashibing\common\request\VerificationCodeDTO.class
com\mashibing\common\dto\TokenResult.class
com\mashibing\common\response\TokenResponse.class
com\mashibing\common\constant\TokenConstants.class

@ -5,6 +5,7 @@ D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibi
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\constant\TokenConstants.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\request\VerificationCodeDTO.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\response\TokenResponse.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\dto\PassengerUser.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\util\JwtUtils.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\util\RedisPrefixUtils.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\dto\TokenResult.java

@ -3,8 +3,6 @@ package com.mashibing.serviceDriverUser.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class TestController {
@GetMapping

@ -4,9 +4,7 @@ import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.request.VerificationCodeDTO;
import com.mashibing.serviceDriverUser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
public class UserController {
@ -19,4 +17,10 @@ public class UserController {
System.out.println("passengerPhone:" + passengerPhone);
return userService.loginOrRegister(passengerPhone);
}
@GetMapping("/user/{phone}")
public ResponseResult getUserByPhone(@PathVariable("phone") String phone){
System.out.println("passengerPhone:" + phone);
return userService.getUserByPhone(phone);
}
}

@ -1,7 +1,7 @@
package com.mashibing.serviceDriverUser.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mashibing.serviceDriverUser.dto.PassengerUser;
import com.mashibing.common.dto.PassengerUser;
import org.springframework.stereotype.Repository;
@Repository

@ -1,7 +1,8 @@
package com.mashibing.serviceDriverUser.service;
import com.mashibing.common.constant.CommonStatusEnum;
import com.mashibing.common.dto.PassengerUser;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.serviceDriverUser.dto.PassengerUser;
import com.mashibing.serviceDriverUser.mapper.PassengerUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -41,4 +42,25 @@ public class UserService {
return ResponseResult.success();
}
/**
*
* @param passengerPhone
* @return ResponseResult
*/
public ResponseResult getUserByPhone(String passengerPhone){
//根据手机号查询用户信息
HashMap map = new HashMap();
map.put("passenger_phone",passengerPhone);
List<PassengerUser> user = this.passengerUserMapper.selectByMap(map);
if(user.size() == 0){
return ResponseResult.fail(CommonStatusEnum.USER_NOT_EXIST.getCode(), CommonStatusEnum.USER_NOT_EXIST.getMsg());
}else{
PassengerUser passengerUser = user.get(0);
return ResponseResult.success(passengerUser);
}
}
}

@ -0,0 +1,5 @@
com\mashibing\serviceDriverUser\mapper\PassengerUserMapper.class
com\mashibing\serviceDriverUser\service\UserService.class
com\mashibing\serviceDriverUser\controller\TestController.class
com\mashibing\serviceDriverUser\controller\UserController.class
com\mashibing\serviceDriverUser\ServicePassengerUserApplication.class

@ -2,5 +2,4 @@ D:\Works\workspaces\online-taxi-public\service-passenger-user\src\main\java\com\
D:\Works\workspaces\online-taxi-public\service-passenger-user\src\main\java\com\mashibing\serviceDriverUser\ServicePassengerUserApplication.java
D:\Works\workspaces\online-taxi-public\service-passenger-user\src\main\java\com\mashibing\serviceDriverUser\controller\TestController.java
D:\Works\workspaces\online-taxi-public\service-passenger-user\src\main\java\com\mashibing\serviceDriverUser\mapper\PassengerUserMapper.java
D:\Works\workspaces\online-taxi-public\service-passenger-user\src\main\java\com\mashibing\serviceDriverUser\dto\PassengerUser.java
D:\Works\workspaces\online-taxi-public\service-passenger-user\src\main\java\com\mashibing\serviceDriverUser\service\UserService.java

@ -0,0 +1,3 @@
com\mashibing\service\controller\NumberCodeController.class
com\mashibing\service\ServiceVerificationcodeApplication.class
com\mashibing\service\controller\TestController.class
Loading…
Cancel
Save