diff --git a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/controller/PassengerController.java b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/controller/PassengerController.java index 3db31eb..2aa0289 100644 --- a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/controller/PassengerController.java +++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/controller/PassengerController.java @@ -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()); + + } } diff --git a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/PassengerUserService.java b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/PassengerUserService.java index fbd5ff2..bde8cfa 100644 --- a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/PassengerUserService.java +++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/PassengerUserService.java @@ -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); } diff --git a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/PassengerUserServiceImpl.java b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/PassengerUserServiceImpl.java index ecceae6..97ccd50 100644 --- a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/PassengerUserServiceImpl.java +++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/PassengerUserServiceImpl.java @@ -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(); + } } diff --git a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/intercept/JwtIntercept.java b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/intercept/JwtIntercept.java index 8998a92..080bdcd 100644 --- a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/intercept/JwtIntercept.java +++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/intercept/JwtIntercept.java @@ -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"; diff --git a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/controller/UserController.java b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/controller/UserController.java index 4cdd39a..94a05ca 100644 --- a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/controller/UserController.java +++ b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/controller/UserController.java @@ -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 passengerUsers = passengerUserMapper.selectList(new QueryWrapper().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 passengerUserList = passengerUserMapper.selectList(new QueryWrapper() + .lambda().eq(PassengerUser::getPassengerPhone, phoneNumber)); + if(ObjectUtil.isEmpty(passengerUserList)){ + ResponseResult.fail(ErrorCodeConstant.DATA_NOT_EXIST,"手机号码不存在"); + } + return ResponseResult.success(passengerUserList.get(0)); + + } } diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/ErrorCodeConstant.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/ErrorCodeConstant.java new file mode 100644 index 0000000..e9a8a31 --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/ErrorCodeConstant.java @@ -0,0 +1,23 @@ +package com.mashibing.constant; + +/** + * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved. + * 1.版权归博纳德集团公司所有; + * 2.未经原作者允许不得转载本代码内容,否则将视为侵权; + * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。. + * Description:
+ * + * @author nod + * ProjectName: onelinetextplublic + *
PackageName: com.mashibing.constant + *
ClassName: + *
Date: 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; + +}