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 e6bf511..2c789fc 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
@@ -4,10 +4,12 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.mashibing.dto.PassengerRequestDto;
import com.mashibing.dto.ResponseResult;
+import com.mashibing.exception.BizExecption;
import com.mashibing.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
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 org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@@ -29,6 +31,8 @@ public class PassengerController {
@Resource
private SendSMSCodeService sendSMSCodeService;
+ @Resource
+ private PassengerUserService passengerUserService;
@Resource
private StringRedisTemplate stringRedisTemplate;
@@ -38,7 +42,7 @@ public class PassengerController {
public ResponseResult getPhoneNumberCode(@RequestBody PassengerRequestDto passengerRequestDto){
// 校验参数
if(ObjectUtil.isNull(passengerRequestDto)||ObjectUtil.isEmpty(passengerRequestDto.getPhoneNumber())){
- throw new RuntimeException("手机号码必填");
+ return ResponseResult.fail(1005,"手机号码必填");
}
@@ -58,23 +62,25 @@ public class PassengerController {
public ResponseResult checkPhoneNumberCode(@RequestBody PassengerRequestDto passengerRequestDto){
// 校验参数
if(ObjectUtil.isNull(passengerRequestDto)||ObjectUtil.isEmpty(passengerRequestDto.getPhoneNumber())||ObjectUtil.isEmpty(passengerRequestDto.getPhoneNumberCode())){
- throw new RuntimeException("手机号码 和短信验证码必填");
-
+ //throw new BizExecption("手机号码 和短信验证码必填",1005,null);
+ // 抛出异常 会被 自定义的拦截器 拦截,拦截后返回的信息不正确!
+ return ResponseResult.fail(1005,"手机号码 和短信验证码必填");
}
// 校验验证码
String phone=passengerRequestDto.getPhoneNumber();
String redisCode = stringRedisTemplate.opsForValue().get(PassengerConsonant.phoneNumberCodePreKey + phone);
if(StringUtils.isBlank(redisCode)){
- throw new RuntimeException("短信验证码已过期!");
+ return ResponseResult.fail(1003,"短信验证码已过期!");
}
String reqCode=passengerRequestDto.getPhoneNumberCode();
if(!reqCode.equals(redisCode)){
- throw new RuntimeException("短信验证码错误!");
+ return ResponseResult.fail(1004,"短信验证码错误!");
}
- // 用户注册
log.info("phone {} 短信验证码正确!",phone);
-
+ // 用户注册
+ passengerUserService.reginsterUserbyPhone(passengerRequestDto);
+ log.info("手机号码={} 完成注册!",phone);
// 返回token
String token = JwtUtils.genaroteToken(phone, PassengerConsonant.PassengerIdendity);
UserInfo userInfo =new UserInfo();
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
new file mode 100644
index 0000000..fbd5ff2
--- /dev/null
+++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/PassengerUserService.java
@@ -0,0 +1,27 @@
+package mashibing.online.text.feign;
+
+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.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved.
+ * 1.版权归博纳德集团公司所有;
+ * 2.未经原作者允许不得转载本代码内容,否则将视为侵权;
+ * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。.
+ *
+ * @packageName: mashibing.online.text.feign.fallback
+ * @description:
+ * @author: nod
+ * @create: 2022-10-09
+ */
+@FeignClient(name = "service-passenger-user",fallback= PassengerUserServiceImpl.class)
+public interface PassengerUserService {
+
+
+ @PostMapping("/user/reginsterUserbyPhone")
+ public ResponseResult reginsterUserbyPhone(@RequestBody PassengerRequestDto passengerRequestDto);
+}
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
new file mode 100644
index 0000000..ecceae6
--- /dev/null
+++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/PassengerUserServiceImpl.java
@@ -0,0 +1,33 @@
+package mashibing.online.text.feign.fallback;
+
+import com.mashibing.dto.PassengerRequestDto;
+import com.mashibing.dto.ResponseResult;
+import lombok.extern.slf4j.Slf4j;
+import mashibing.online.text.feign.PassengerUserService;
+import mashibing.online.text.feign.SendSMSCodeService;
+import org.springframework.stereotype.Service;
+
+/**
+ * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved.
+ * 1.版权归博纳德集团公司所有;
+ * 2.未经原作者允许不得转载本代码内容,否则将视为侵权;
+ * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。.
+ * Description:
+ *
+ * @author nod
+ * ProjectName: onelinetextplublic
+ *
PackageName: mashibing.online.text.feign.fallback
+ *
ClassName:
+ *
Date: 2022/10/9 18:32
+ */
+@Service
+@Slf4j
+public class PassengerUserServiceImpl implements PassengerUserService {
+
+
+ @Override
+ public ResponseResult reginsterUserbyPhone(PassengerRequestDto passengerRequestDto) {
+ log.error("注册用户失败");
+ return ResponseResult.fail();
+ }
+}
diff --git a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/SendSMSCodeServiceImpl.java b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/SendSMSCodeServiceImpl.java
index 0b8797c..29188d8 100644
--- a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/SendSMSCodeServiceImpl.java
+++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/feign/fallback/SendSMSCodeServiceImpl.java
@@ -29,6 +29,6 @@ public class SendSMSCodeServiceImpl implements SendSMSCodeService {
public String getSmsCode(int size, String phoneNumber) {
log.info("获取短信验证码失败");
- return "";//ResponseResult.fail(CommonStatusEnum.FAIL.getCode(), "获取短信验证码失败");
+ return null;
}
}
diff --git a/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/intercept/InterceptorConfinger.java b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/intercept/InterceptorConfinger.java
new file mode 100644
index 0000000..1243d79
--- /dev/null
+++ b/oneLineTxt/v1/onelinetextplublic/api-passinger/src/main/java/mashibing/online/text/intercept/InterceptorConfinger.java
@@ -0,0 +1,38 @@
+package mashibing.online.text.intercept;
+
+import org.springframework.beans.factory.annotation.Configurable;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved.
+ * 1.版权归博纳德集团公司所有;
+ * 2.未经原作者允许不得转载本代码内容,否则将视为侵权;
+ * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。.
+ * Description:
+ *
+ * @author nod
+ * ProjectName: onelinetextplublic
+ *
PackageName: mashibing.online.text.intercept
+ *
ClassName:
+ *
Date: 2022/10/19 14:18
+ */
+@Configuration
+public class InterceptorConfinger implements WebMvcConfigurer {
+
+ @Bean
+ public JwtIntercept jwtIntercept(){
+ return new JwtIntercept();
+ }
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(jwtIntercept()).addPathPatterns("/**")
+ .excludePathPatterns("/passenger/checkPhoneNumberCode")
+ .excludePathPatterns("/passenger/getPhoneNumberCode")
+ .excludePathPatterns("/test/noTokenTest");
+
+ }
+}
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 6d85e9d..b12e653 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
@@ -1,8 +1,12 @@
package mashibing.online.text.intercept;
+import com.alibaba.fastjson.JSON;
+import com.mashibing.constant.CommonStatusEnum;
import com.mashibing.dto.PassengerRequestDto;
+import com.mashibing.dto.ResponseResult;
import com.mashibing.dto.TokenResult;
import com.mashibing.util.JwtUtils;
+import javafx.print.Printer;
import lombok.extern.slf4j.Slf4j;
import mashibing.online.text.consonant.PassengerConsonant;
import org.apache.commons.lang3.StringUtils;
@@ -12,6 +16,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
@Slf4j
public class JwtIntercept implements HandlerInterceptor {
@@ -21,26 +26,43 @@ public class JwtIntercept implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+
String token = request.getHeader("Authorization");
+ String message=null;
boolean result =true;
TokenResult tokenResult =null;
+ if(StringUtils.isBlank(token)){
+ PrintWriter out = response.getWriter();
+ out.println(JSON.toJSONString(ResponseResult.fail(99, "token is empty !")));
+ return false;
+ }
try{
tokenResult = JwtUtils.parseToken(token);
}catch (Exception e){
- log.error("解析token异常 e",e.getCause());
+ log.error("解析token异常 e ={}",e.getCause());
+ message="parse token exception";
+ result =false;
}
- if(!result){
-
- }else {
+ if(result){
String phone=tokenResult.getPhoneNum();
String idendity=tokenResult.getIdendity();
//根据手机号 和身份类型 查询
String s = stringRedisTemplate.opsForValue().get(PassengerConsonant.phoneNumberTokenPreKey + phone + idendity);
if(StringUtils.isBlank(s)){
//token 无效
+ message="token not exist";
result =false;
+ }else{
+ // 比对token
+ if(!token.equals(s)){
+ message="token is inval";
+ result =false;
+ }
}
-
+ }
+ if(!result){
+ PrintWriter out = response.getWriter();
+ out.println(JSON.toJSONString(ResponseResult.fail(99, message)));
}
diff --git a/oneLineTxt/v1/onelinetextplublic/send-server/src/main/resources/application.yml b/oneLineTxt/v1/onelinetextplublic/send-server/src/main/resources/application.yml
index ea62b44..9a886c7 100644
--- a/oneLineTxt/v1/onelinetextplublic/send-server/src/main/resources/application.yml
+++ b/oneLineTxt/v1/onelinetextplublic/send-server/src/main/resources/application.yml
@@ -11,6 +11,6 @@ spring:
name: send-server
xsxx:
- url: http://api.wxxsxx.com
+ url: http://api.wxxsxx.com/
account: bzxxhyhy
password: 3Vf8S9
\ No newline at end of file
diff --git a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/pom.xml b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/pom.xml
index 3f03853..fc9f939 100644
--- a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/pom.xml
+++ b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/pom.xml
@@ -25,6 +25,36 @@
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.16
+ compile
+
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ 1.1.10
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+
+ 3.3.2
+
+
+
+ com.mashibing
+ untitled4
+ 1.0-SNAPSHOT
+ compile
+
+
+
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
new file mode 100644
index 0000000..4cdd39a
--- /dev/null
+++ b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/controller/UserController.java
@@ -0,0 +1,64 @@
+package com.example.servicepassengeruser.controller.pojo;
+
+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.dto.PassengerRequestDto;
+import com.mashibing.dto.ResponseResult;
+import com.mashibing.exception.BizExecption;
+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.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved.
+ * 1.版权归博纳德集团公司所有;
+ * 2.未经原作者允许不得转载本代码内容,否则将视为侵权;
+ * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。.
+ * Description:
+ *
+ * @author nod
+ * ProjectName: onelinetextplublic
+ *
PackageName: com.example.servicepassengeruser.controller.pojo
+ *
ClassName:
+ *
Date: 2022/10/19 14:31
+ */
+@RestController
+@RequestMapping("/user")
+public class UserController {
+
+
+ @Resource
+ private PassengerUserMapper passengerUserMapper;
+
+
+
+ @PostMapping("/reginsterUserbyPhone")
+ public ResponseResult reginsterUserbyPhone(@RequestBody PassengerRequestDto passengerRequestDto){
+ if(ObjectUtil.isNull(passengerRequestDto) || ObjectUtil.isEmpty(passengerRequestDto.getPhoneNumber())){
+ throw new BizExecption("手机号不能为空",1003,null);
+ }
+
+ List passengerUsers = passengerUserMapper.selectList(new QueryWrapper().lambda()
+ .eq(PassengerUser::getPassengerPhone, passengerRequestDto.getPhoneNumber()));
+ if(ObjectUtil.isEmpty(passengerUsers)){
+ //没有就新增
+ PassengerUser user=new PassengerUser();
+ user.setPassengerPhone(passengerRequestDto.getPhoneNumber());
+ user.setState(true);
+ //user.setId(UUID.randomUUID().toString());
+ //user.setPassengerGender();
+ passengerUserMapper.insert(user);
+ }
+
+ return ResponseResult.success("成功");
+ }
+
+
+}
diff --git a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/mapper/PassengerUserMapper.java b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/mapper/PassengerUserMapper.java
new file mode 100644
index 0000000..9b4b6ee
--- /dev/null
+++ b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/mapper/PassengerUserMapper.java
@@ -0,0 +1,12 @@
+package com.example.servicepassengeruser.mapper;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.servicepassengeruser.pojo.PassengerUser;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface PassengerUserMapper extends BaseMapper {
+
+
+}
\ No newline at end of file
diff --git a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/pojo/PassengerUser.java b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/pojo/PassengerUser.java
new file mode 100644
index 0000000..73f7ec8
--- /dev/null
+++ b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/java/com/example/servicepassengeruser/pojo/PassengerUser.java
@@ -0,0 +1,34 @@
+package com.example.servicepassengeruser.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@TableName("passenger_user")
+public class PassengerUser extends Model {
+
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+
+ private Date gmtCreate;
+
+ private Date gmtModified;
+
+ private String passengerPhone;
+
+ private String passengerName;
+
+ private Boolean passengerGender;
+
+ private Boolean state;
+
+ private String profilePhoto;
+
+
+}
\ No newline at end of file
diff --git a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/resources/application.yml b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/resources/application.yml
index dec570c..628ec53 100644
--- a/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/resources/application.yml
+++ b/oneLineTxt/v1/onelinetextplublic/service-passenger-user/src/main/resources/application.yml
@@ -4,3 +4,14 @@ server:
spring:
application:
name: service-passenger-user
+ cloud:
+ nacos:
+ discovery:
+ server-addr: 127.0.0.1:8848
+ datasource:
+ type: com.alibaba.druid.pool.DruidDataSource
+ driver-class-name: com.mysql.jdbc.Driver
+ url: jdbc:mysql://10.2.23.46:3306/oneline-txt?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true
+ username: root
+ password: 1qaz@WSX
+
diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/exception/BizExecption.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/exception/BizExecption.java
new file mode 100644
index 0000000..f87a55a
--- /dev/null
+++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/exception/BizExecption.java
@@ -0,0 +1,37 @@
+package com.mashibing.exception;
+
+import lombok.Data;
+
+import java.awt.dnd.DropTarget;
+
+/**
+ * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved.
+ * 1.版权归博纳德集团公司所有;
+ * 2.未经原作者允许不得转载本代码内容,否则将视为侵权;
+ * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。.
+ * Description:
+ *
+ * @author nod
+ * ProjectName: onelinetextplublic
+ *
PackageName: com.mashibing.exception
+ *
ClassName:
+ *
Date: 2022/10/19 14:01
+ */
+@Data
+public class BizExecption extends RuntimeException {
+
+ private Integer code;
+
+ private Object data;
+
+ public BizExecption(String message,Throwable throwable){
+ super(message,throwable);
+ }
+
+ public BizExecption(String message,Integer code,Object data){
+ super(message);
+ this.code = code;
+ this.data= data;
+ }
+
+}