add:实现根据手机号码查询用户信息功能

master
msb_89821 2 years ago
parent 19fa8a7ddd
commit c6cb02199a

@ -2,8 +2,10 @@ package mashibing.online.text.controller;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.mashibing.constant.ErrorCodeConstant;
import com.mashibing.dto.PassengerRequestDto;
import com.mashibing.dto.ResponseResult;
import com.mashibing.dto.TokenResult;
import com.mashibing.exception.BizExecption;
import com.mashibing.util.JwtUtils;
import com.mashibing.util.RediesPreKeyUtil;
@ -12,12 +14,15 @@ import mashibing.online.text.consonant.PassengerConsonant;
import mashibing.online.text.dto.UserInfo;
import mashibing.online.text.feign.PassengerUserService;
import mashibing.online.text.feign.SendSMSCodeService;
import mashibing.online.text.utils.BussizParaTokenUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;
/**
@ -98,7 +103,7 @@ public class PassengerController {
String accessTokenKey= RediesPreKeyUtil.generateKeyPre(PassengerConsonant.ACCESS_TOKEN_TYPE,phone,PassengerConsonant.PassengerIdendity);
String reshTokenKey= RediesPreKeyUtil.generateKeyPre(PassengerConsonant.REFLSH_TOKEN_TYPE,phone,PassengerConsonant.PassengerIdendity);
stringRedisTemplate.opsForValue().set(accessTokenKey,
accessToken,15,TimeUnit.SECONDS);
accessToken,15,TimeUnit.DAYS);
stringRedisTemplate.opsForValue().set(reshTokenKey,
refshToken,55,TimeUnit.SECONDS);
log.info("reshTokenKey ={},refshToken={}",reshTokenKey,refshToken);
@ -106,6 +111,16 @@ public class PassengerController {
return ResponseResult.success(userInfo);
}
@GetMapping("/getUserInfoByPhone")
public ResponseResult getUserInfoByPhone(HttpServletRequest httpRequest){
String authorization = httpRequest.getHeader("Authorization");
TokenResult tokenResult= BussizParaTokenUtil.pareToken(authorization);
if(ObjectUtil.isNull(tokenResult)){
ResponseResult.fail(ErrorCodeConstant.TOKEN_ERROR,"token 错误");
}
return passengerUserService.getUserInfoByPhone(tokenResult.getPhoneNum());
}
}

@ -4,8 +4,12 @@ import com.mashibing.dto.PassengerRequestDto;
import com.mashibing.dto.ResponseResult;
import mashibing.online.text.feign.fallback.PassengerUserServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Copyright© 2020.10.20 by .All rights reserved.
@ -22,6 +26,9 @@ import org.springframework.web.bind.annotation.RequestBody;
public interface PassengerUserService {
@PostMapping("/user/reginsterUserbyPhone")
@RequestMapping(value = "/user/reginsterUserbyPhone",method = RequestMethod.POST)
public ResponseResult reginsterUserbyPhone(@RequestBody PassengerRequestDto passengerRequestDto);
@RequestMapping(value ="/user/getUserInfoByPhone", method = RequestMethod.GET)
public ResponseResult getUserInfoByPhone(@RequestParam String phoneNumber);
}

@ -30,4 +30,10 @@ public class PassengerUserServiceImpl implements PassengerUserService {
log.error("注册用户失败");
return ResponseResult.fail();
}
@Override
public ResponseResult getUserInfoByPhone(String phoneNumber) {
log.error("查询用户失败");
return ResponseResult.fail();
}
}

@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.mashibing.dto.ResponseResult;
import com.mashibing.dto.TokenResult;
import com.mashibing.util.RediesPreKeyUtil;
import lombok.extern.slf4j.Slf4j;
import mashibing.online.text.utils.BussizParaTokenUtil;
import org.apache.commons.lang3.StringUtils;
@ -34,7 +35,8 @@ public class JwtIntercept implements HandlerInterceptor {
String idendity=tokenResult.getIdendity();
String tokenType = tokenResult.getTokenType();
//根据手机号 和身份类型 查询
String s = stringRedisTemplate.opsForValue().get(tokenType + phone + idendity);
String tokenKey = RediesPreKeyUtil.generateKeyPre(tokenType,phone,idendity);
String s = stringRedisTemplate.opsForValue().get(tokenKey);
if(StringUtils.isBlank(s) || !token.equals(s)){
//token 无效
message="token is inval";

@ -4,12 +4,16 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.servicepassengeruser.mapper.PassengerUserMapper;
import com.example.servicepassengeruser.pojo.PassengerUser;
import com.mashibing.constant.ErrorCodeConstant;
import com.mashibing.dto.PassengerRequestDto;
import com.mashibing.dto.ResponseResult;
import com.mashibing.exception.BizExecption;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -42,7 +46,7 @@ public class UserController {
@PostMapping("/reginsterUserbyPhone")
public ResponseResult reginsterUserbyPhone(@RequestBody PassengerRequestDto passengerRequestDto){
if(ObjectUtil.isNull(passengerRequestDto) || ObjectUtil.isEmpty(passengerRequestDto.getPhoneNumber())){
throw new BizExecption("手机号不能为空",1003,null);
throw new BizExecption("手机号不能为空", ErrorCodeConstant.PARAM_ERROR,null);
}
List<PassengerUser> passengerUsers = passengerUserMapper.selectList(new QueryWrapper<PassengerUser>().lambda()
@ -60,5 +64,19 @@ public class UserController {
return ResponseResult.success("成功");
}
@GetMapping("/getUserInfoByPhone")
public ResponseResult getUserInfoByPhone(@RequestParam String phoneNumber){
if(StringUtils.isBlank(phoneNumber)){
ResponseResult.fail(ErrorCodeConstant.PARAM_ERROR,"手机号不能为空");
}
List<PassengerUser> passengerUserList = passengerUserMapper.selectList(new QueryWrapper<PassengerUser>()
.lambda().eq(PassengerUser::getPassengerPhone, phoneNumber));
if(ObjectUtil.isEmpty(passengerUserList)){
ResponseResult.fail(ErrorCodeConstant.DATA_NOT_EXIST,"手机号码不存在");
}
return ResponseResult.success(passengerUserList.get(0));
}
}

@ -0,0 +1,23 @@
package com.mashibing.constant;
/**
* Copyright© 2020.10.20 by .All rights reserved.
* 1.
* 2.
* 3.使.
* <b>Description:</b><br>
*
* @author nod
* <b>ProjectName:</b> onelinetextplublic
* <br><b>PackageName:</b> com.mashibing.constant
* <br><b>ClassName:</b>
* <br><b>Date:</b> 2022/10/21 14:50
*/
public class ErrorCodeConstant {
public static final int PARAM_ERROR = 1001;
public static final int TOKEN_ERROR = 1003;
public static final int TOKEN_OVERTIME = 1004;
public static final int DATA_NOT_EXIST = 1005;
}
Loading…
Cancel
Save