From 01e2fd58081781685ca6ac3c58d5d62cf56e0ffd Mon Sep 17 00:00:00 2001 From: XiaoHH <1431984546@qq.com> Date: Tue, 30 May 2023 20:57:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81=E7=A0=81=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 35 +++++++ api/api-passenger/pom.xml | 45 +++++++++ .../passenger/ApiPassengerApplication.java | 22 +++++ .../PassengerVerificationController.java | 33 +++++++ .../dto/PassengerVerificationCodeDTO.java | 35 +++++++ .../PassengerVerificationCodeRedisDTO.java | 62 +++++++++++++ .../vo/PassengerVerificationCodeVO.java | 26 ++++++ .../service/PassengerVerificationService.java | 24 +++++ .../PassengerVerificationServiceImpl.java | 51 ++++++++++ .../src/main/resources/application.yaml | 2 + api/pom.xml | 18 ++++ common/common-contant/.gitignore | 38 ++++++++ common/common-contant/pom.xml | 15 +++ .../com/greateme/contant/http/HttpStatus.java | 30 ++++++ common/common-entity/.gitignore | 38 ++++++++ common/common-entity/pom.xml | 28 ++++++ .../entity/respose/ResponseEntity.java | 92 +++++++++++++++++++ common/common-util/pom.xml | 22 +++++ .../main/java/com/greateme/util/JsonUtil.java | 34 +++++++ .../java/com/greateme/util/StringUtil.java | 35 +++++++ common/pom.xml | 22 +++++ pom.xml | 68 ++++++++++++++ 22 files changed, 775 insertions(+) create mode 100644 .gitignore create mode 100644 api/api-passenger/pom.xml create mode 100644 api/api-passenger/src/main/java/com/greateme/passenger/ApiPassengerApplication.java create mode 100644 api/api-passenger/src/main/java/com/greateme/passenger/controller/PassengerVerificationController.java create mode 100644 api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeDTO.java create mode 100644 api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeRedisDTO.java create mode 100644 api/api-passenger/src/main/java/com/greateme/passenger/entity/vo/PassengerVerificationCodeVO.java create mode 100644 api/api-passenger/src/main/java/com/greateme/passenger/service/PassengerVerificationService.java create mode 100644 api/api-passenger/src/main/java/com/greateme/passenger/service/impl/PassengerVerificationServiceImpl.java create mode 100644 api/api-passenger/src/main/resources/application.yaml create mode 100644 api/pom.xml create mode 100644 common/common-contant/.gitignore create mode 100644 common/common-contant/pom.xml create mode 100644 common/common-contant/src/main/java/com/greateme/contant/http/HttpStatus.java create mode 100644 common/common-entity/.gitignore create mode 100644 common/common-entity/pom.xml create mode 100644 common/common-entity/src/main/java/com/greateme/entity/respose/ResponseEntity.java create mode 100644 common/common-util/pom.xml create mode 100644 common/common-util/src/main/java/com/greateme/util/JsonUtil.java create mode 100644 common/common-util/src/main/java/com/greateme/util/StringUtil.java create mode 100644 common/pom.xml create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d769462 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/api/api-passenger/pom.xml b/api/api-passenger/pom.xml new file mode 100644 index 0000000..6947994 --- /dev/null +++ b/api/api-passenger/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + com.greateme + api + 1.0-SNAPSHOT + + + jar + + api-passenger + + + 11 + 11 + UTF-8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.greateme + common-entity + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/api/api-passenger/src/main/java/com/greateme/passenger/ApiPassengerApplication.java b/api/api-passenger/src/main/java/com/greateme/passenger/ApiPassengerApplication.java new file mode 100644 index 0000000..e2fe4d7 --- /dev/null +++ b/api/api-passenger/src/main/java/com/greateme/passenger/ApiPassengerApplication.java @@ -0,0 +1,22 @@ +package com.greateme.passenger; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + *

+ * 乘客微服务的启动类 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 18:17:31 + * @file ApiPassengerApplication.java + */ +@SpringBootApplication +public class ApiPassengerApplication { + + public static void main(String[] args) { + SpringApplication.run(ApiPassengerApplication.class, args); + } +} diff --git a/api/api-passenger/src/main/java/com/greateme/passenger/controller/PassengerVerificationController.java b/api/api-passenger/src/main/java/com/greateme/passenger/controller/PassengerVerificationController.java new file mode 100644 index 0000000..cb32e50 --- /dev/null +++ b/api/api-passenger/src/main/java/com/greateme/passenger/controller/PassengerVerificationController.java @@ -0,0 +1,33 @@ +package com.greateme.passenger.controller; + +import com.greateme.entity.respose.ResponseEntity; +import com.greateme.passenger.entity.dto.PassengerVerificationCodeDTO; +import com.greateme.passenger.service.PassengerVerificationService; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 乘客验证码的前端控制器 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 18:42:34 + * @file PassengerVerificationController.java + */ +@RestController +@RequestMapping("/verification") +public class PassengerVerificationController { + + @Autowired + private PassengerVerificationService verificationService; + + @PostMapping("/code") + public ResponseEntity verificationCode(@RequestBody PassengerVerificationCodeDTO verificationCode) { + return ResponseEntity.success(this.verificationService.generationPhoneVerificationCode(verificationCode)); + } +} diff --git a/api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeDTO.java b/api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeDTO.java new file mode 100644 index 0000000..5761d6e --- /dev/null +++ b/api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeDTO.java @@ -0,0 +1,35 @@ +package com.greateme.passenger.entity.dto; + +import com.greateme.util.JsonUtil; + +import java.io.Serializable; + +/** + *

+ * 乘客手机验证码的DTO + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 18:41:03 + * @file PassengerVerificationCodeDTO.java + */ +public class PassengerVerificationCodeDTO implements Serializable { + /** + * 乘客的手机号码 + */ + private String passengerPhone; + + public String getPassengerPhone() { + return passengerPhone; + } + + public void setPassengerPhone(String passengerPhone) { + this.passengerPhone = passengerPhone; + } + + @Override + public String toString() { + return JsonUtil.toJson(this); + } +} diff --git a/api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeRedisDTO.java b/api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeRedisDTO.java new file mode 100644 index 0000000..20e0bd8 --- /dev/null +++ b/api/api-passenger/src/main/java/com/greateme/passenger/entity/dto/PassengerVerificationCodeRedisDTO.java @@ -0,0 +1,62 @@ +package com.greateme.passenger.entity.dto; + +import com.greateme.util.JsonUtil; + +import java.io.Serializable; + +/** + *

+ * 验证码存入redis的实体类 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 20:30:05 + * @file PassengerVerificationCodeRedisDTO.java + */ +public class PassengerVerificationCodeRedisDTO implements Serializable { + + /** + * 验证码答案 + */ + private String verificationCode; + + /** + * 验证码的token + */ + private String token; + + /** + * 客户的手机号码 + */ + private String passengerPhone; + + public String getVerificationCode() { + return verificationCode; + } + + public void setVerificationCode(String verificationCode) { + this.verificationCode = verificationCode; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getPassengerPhone() { + return passengerPhone; + } + + public void setPassengerPhone(String passengerPhone) { + this.passengerPhone = passengerPhone; + } + + @Override + public String toString() { + return JsonUtil.toJson(this); + } +} diff --git a/api/api-passenger/src/main/java/com/greateme/passenger/entity/vo/PassengerVerificationCodeVO.java b/api/api-passenger/src/main/java/com/greateme/passenger/entity/vo/PassengerVerificationCodeVO.java new file mode 100644 index 0000000..d759e2f --- /dev/null +++ b/api/api-passenger/src/main/java/com/greateme/passenger/entity/vo/PassengerVerificationCodeVO.java @@ -0,0 +1,26 @@ +package com.greateme.passenger.entity.vo; + +import java.io.Serializable; + +/** + *

+ * 乘客验证码的视图对象 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 19:40:35 + * @file PassengerVerificationCodeVO.java + */ +public class PassengerVerificationCodeVO implements Serializable { + + /** + * 手机验证码 + */ + private String verificationCode; + + /** + * + */ + private String verificationToken; +} diff --git a/api/api-passenger/src/main/java/com/greateme/passenger/service/PassengerVerificationService.java b/api/api-passenger/src/main/java/com/greateme/passenger/service/PassengerVerificationService.java new file mode 100644 index 0000000..702158f --- /dev/null +++ b/api/api-passenger/src/main/java/com/greateme/passenger/service/PassengerVerificationService.java @@ -0,0 +1,24 @@ +package com.greateme.passenger.service; + +import com.greateme.passenger.entity.dto.PassengerVerificationCodeDTO; + +/** + *

+ * 乘客验证码的服务层接口 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 19:39:43 + * @file PassengerVerificationService.java + */ +public interface PassengerVerificationService { + + /** + * 生成手机验证码 + * + * @param verificationCode 手机验证码内容 + * @return 手机验证码后续的验证token + */ + String generationPhoneVerificationCode(PassengerVerificationCodeDTO verificationCode); +} diff --git a/api/api-passenger/src/main/java/com/greateme/passenger/service/impl/PassengerVerificationServiceImpl.java b/api/api-passenger/src/main/java/com/greateme/passenger/service/impl/PassengerVerificationServiceImpl.java new file mode 100644 index 0000000..ee294ac --- /dev/null +++ b/api/api-passenger/src/main/java/com/greateme/passenger/service/impl/PassengerVerificationServiceImpl.java @@ -0,0 +1,51 @@ +package com.greateme.passenger.service.impl; + +import com.greateme.passenger.entity.dto.PassengerVerificationCodeDTO; +import com.greateme.passenger.entity.dto.PassengerVerificationCodeRedisDTO; +import com.greateme.passenger.service.PassengerVerificationService; +import com.greateme.util.StringUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +/** + *

+ * 乘客验证码的服务层接口实现 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 19:57:37 + * @file PassengerVerificationServiceImpl.java + */ +@Service +public class PassengerVerificationServiceImpl implements PassengerVerificationService { + + /** + * 记录日志的对象 + */ + private static final Logger log = LoggerFactory.getLogger(PassengerVerificationServiceImpl.class); + + /** + * 生成手机验证码 + * + * @param verificationCode 手机验证码内容 + * @return 手机验证码后续的验证token + */ + @Override + public String generationPhoneVerificationCode(PassengerVerificationCodeDTO verificationCode) { + // 生成6位的手机验证码 + String code = StringUtil.generationVerificationCode(6); + // 生成对应手机验证码的token + String token = UUID.randomUUID().toString(); + // 初始化存入redis当中的对象 + PassengerVerificationCodeRedisDTO verificationCodeRedis = new PassengerVerificationCodeRedisDTO(); + verificationCodeRedis.setVerificationCode(code); + verificationCodeRedis.setPassengerPhone(verificationCode.getPassengerPhone()); + verificationCodeRedis.setToken(token); + log.info("成功生成短信验证码{},手机号码:{},token:{},即将将验证码传入redis存储", verificationCodeRedis.getVerificationCode(), verificationCodeRedis.getPassengerPhone(), verificationCodeRedis.getToken()); + return token; + } +} diff --git a/api/api-passenger/src/main/resources/application.yaml b/api/api-passenger/src/main/resources/application.yaml new file mode 100644 index 0000000..a7afc92 --- /dev/null +++ b/api/api-passenger/src/main/resources/application.yaml @@ -0,0 +1,2 @@ +server: + port: 8080 diff --git a/api/pom.xml b/api/pom.xml new file mode 100644 index 0000000..c795c07 --- /dev/null +++ b/api/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + com.greateme + online-taxi-public + 1.0-SNAPSHOT + + pom + + api-passenger + + + api + + \ No newline at end of file diff --git a/common/common-contant/.gitignore b/common/common-contant/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/common/common-contant/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/common/common-contant/pom.xml b/common/common-contant/pom.xml new file mode 100644 index 0000000..a256979 --- /dev/null +++ b/common/common-contant/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + com.greateme + common + 1.0-SNAPSHOT + + 公共常量类模块 + + common-contant + + \ No newline at end of file diff --git a/common/common-contant/src/main/java/com/greateme/contant/http/HttpStatus.java b/common/common-contant/src/main/java/com/greateme/contant/http/HttpStatus.java new file mode 100644 index 0000000..dee894e --- /dev/null +++ b/common/common-contant/src/main/java/com/greateme/contant/http/HttpStatus.java @@ -0,0 +1,30 @@ +package com.greateme.contant.http; + +/** + *

+ * http状态的常量类 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 20:19:15 + * @file HttpStatus.java + */ +public class HttpStatus { + + /** + * 此实例不允许被实例化 + */ + private HttpStatus() { + } + + /** + * 成功的常量状态码 + */ + public static final int SUCCESS = 200; + + /** + * 成功的常量状态信息 + */ + public static final String SUCCESS_MESSAGE = "Success"; +} diff --git a/common/common-entity/.gitignore b/common/common-entity/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/common/common-entity/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/common/common-entity/pom.xml b/common/common-entity/pom.xml new file mode 100644 index 0000000..224cfb1 --- /dev/null +++ b/common/common-entity/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + com.greateme + common + 1.0-SNAPSHOT + + 公共实体类模块 + + common-entity + + + + + com.greateme + common-contant + + + + + com.greateme + common-util + + + \ No newline at end of file diff --git a/common/common-entity/src/main/java/com/greateme/entity/respose/ResponseEntity.java b/common/common-entity/src/main/java/com/greateme/entity/respose/ResponseEntity.java new file mode 100644 index 0000000..b8820f5 --- /dev/null +++ b/common/common-entity/src/main/java/com/greateme/entity/respose/ResponseEntity.java @@ -0,0 +1,92 @@ +package com.greateme.entity.respose; + +import com.greateme.contant.http.HttpStatus; +import com.greateme.util.JsonUtil; + +import java.io.Serializable; + +/** + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 20:00:00 + * @file ResponseEntity.java + */ +public class ResponseEntity implements Serializable { + /** + * 无参构造 + */ + public ResponseEntity() { + } + + /** + * 全参构造函数 + * + * @param code 状态码 + * @param date 数据内容 + * @param message 处理的消息信息 + */ + public ResponseEntity(int code, T date, String message) { + this.code = code; + this.date = date; + this.message = message; + } + + /** + * 返回的状态码 + * 200 => 成功 + * 500 => 处理报错 + */ + private int code; + + /** + * 返回的数据内容 + */ + private T date; + + /** + * 返回的处理的消息信息 + */ + private String message; + + /** + * 处理成功的返回方法 + * + * @param data 数据内容 + * @param 数据内容的类型 + * @return 返回的实体 + */ + public static ResponseEntity success(T data) { + return new ResponseEntity<>(HttpStatus.SUCCESS, data, HttpStatus.SUCCESS_MESSAGE); + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public T getDate() { + return date; + } + + public void setDate(T date) { + this.date = date; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return JsonUtil.toJson(this); + } +} diff --git a/common/common-util/pom.xml b/common/common-util/pom.xml new file mode 100644 index 0000000..2e3ddb5 --- /dev/null +++ b/common/common-util/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + com.greateme + common + 1.0-SNAPSHOT + + + common-util + + + + + com.google.code.gson + gson + + + + \ No newline at end of file diff --git a/common/common-util/src/main/java/com/greateme/util/JsonUtil.java b/common/common-util/src/main/java/com/greateme/util/JsonUtil.java new file mode 100644 index 0000000..49c4e11 --- /dev/null +++ b/common/common-util/src/main/java/com/greateme/util/JsonUtil.java @@ -0,0 +1,34 @@ +package com.greateme.util; + +import com.google.gson.Gson; + +import java.io.Serializable; + +/** + *

+ * Json相关的处理类 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 18:45:10 + * @file JsonUtil.java + */ +public class JsonUtil { + + /** + * 此类不允许被实例化 + */ + private JsonUtil() { + } + + /** + * 将对象转换为json字符串(调用Gson的转换字符串方法) + * + * @param obj 需要被转换的对象 + * @return 转换成json字符串后的结果 + */ + public static String toJson(Serializable obj) { + return new Gson().toJson(obj); + } +} diff --git a/common/common-util/src/main/java/com/greateme/util/StringUtil.java b/common/common-util/src/main/java/com/greateme/util/StringUtil.java new file mode 100644 index 0000000..8bf2987 --- /dev/null +++ b/common/common-util/src/main/java/com/greateme/util/StringUtil.java @@ -0,0 +1,35 @@ +package com.greateme.util; + +/** + *

+ * 自定义的字符串处理类 + *

+ * + * @author XiaoHH + * @version 1.0.0 + * @date 2023-05-30 星期二 19:43:12 + * @file StringUtil.java + */ +public class StringUtil { + + /** + * 此类不允许被实例化 + */ + private StringUtil() { + } + + /** + * 生成指定长度的验证码(随机数字) + * + * @param length 随机验证码的长度 + * @return 生成的随机字符串 + */ + public static String generationVerificationCode(int length) { + StringBuilder result = new StringBuilder(length); + for (int i = 0; i < length; i++) { + int num = (int) (Math.random() * 10) + 1; + result.append(num % 10); + } + return result.toString(); + } +} diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..4ccacb4 --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + com.greateme + online-taxi-public + 1.0-SNAPSHOT + + 公共模块 + + pom + + common-entity + common-util + common-contant + + + common + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d55cb3c --- /dev/null +++ b/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + com.greateme + online-taxi-public + 1.0-SNAPSHOT + pom + + api + common + + 马士兵的滴约打车项目 + + + 11 + 11 + UTF-8 + + 1.0-SNAPSHOT + 2.6.14 + 2021.0.7 + 2.10.1 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + com.google.code.gson + gson + ${gson.version} + + + + + com.greateme + common-contant + ${online-taxi-public.version} + + + + + com.greateme + common-entity + ${online-taxi-public.version} + + + + + com.greateme + common-util + ${online-taxi-public.version} + + + + \ No newline at end of file