初始化发送短信验证码的接口

main
XiaoHH 2 years ago
commit 01e2fd5808

35
.gitignore vendored

@ -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

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greateme</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<artifactId>api-passenger</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- util 工具模块 -->
<dependency>
<groupId>com.greateme</groupId>
<artifactId>common-entity</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,22 @@
package com.greateme.passenger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* <p>
*
* </p>
*
* @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);
}
}

@ -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;
/**
* <p>
*
* </p>
*
* @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<String> verificationCode(@RequestBody PassengerVerificationCodeDTO verificationCode) {
return ResponseEntity.success(this.verificationService.generationPhoneVerificationCode(verificationCode));
}
}

@ -0,0 +1,35 @@
package com.greateme.passenger.entity.dto;
import com.greateme.util.JsonUtil;
import java.io.Serializable;
/**
* <p>
* DTO
* </p>
*
* @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);
}
}

@ -0,0 +1,62 @@
package com.greateme.passenger.entity.dto;
import com.greateme.util.JsonUtil;
import java.io.Serializable;
/**
* <p>
* redis
* </p>
*
* @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);
}
}

@ -0,0 +1,26 @@
package com.greateme.passenger.entity.vo;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @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;
}

@ -0,0 +1,24 @@
package com.greateme.passenger.service;
import com.greateme.passenger.entity.dto.PassengerVerificationCodeDTO;
/**
* <p>
*
* </p>
*
* @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);
}

@ -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;
/**
* <p>
*
* </p>
*
* @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;
}
}

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greateme</groupId>
<artifactId>online-taxi-public</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>
<modules>
<module>api-passenger</module>
</modules>
<artifactId>api</artifactId>
</project>

@ -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

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greateme</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<description>公共常量类模块</description>
<artifactId>common-contant</artifactId>
</project>

@ -0,0 +1,30 @@
package com.greateme.contant.http;
/**
* <p>
* http
* </p>
*
* @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";
}

@ -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

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greateme</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<description>公共实体类模块</description>
<artifactId>common-entity</artifactId>
<dependencies>
<!-- 公共常量类模块 -->
<dependency>
<groupId>com.greateme</groupId>
<artifactId>common-contant</artifactId>
</dependency>
<!-- util 工具模块 -->
<dependency>
<groupId>com.greateme</groupId>
<artifactId>common-util</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,92 @@
package com.greateme.entity.respose;
import com.greateme.contant.http.HttpStatus;
import com.greateme.util.JsonUtil;
import java.io.Serializable;
/**
* <p></p>
*
* @author XiaoHH
* @version 1.0.0
* @date 2023-05-30 20:00:00
* @file ResponseEntity.java
*/
public class ResponseEntity<T> 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 <T>
* @return
*/
public static <T> ResponseEntity<T> 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);
}
}

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greateme</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>common-util</artifactId>
<dependencies>
<!-- Gson的json工具 -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,34 @@
package com.greateme.util;
import com.google.gson.Gson;
import java.io.Serializable;
/**
* <p>
* Json
* </p>
*
* @author XiaoHH
* @version 1.0.0
* @date 2023-05-30 18:45:10
* @file JsonUtil.java
*/
public class JsonUtil {
/**
*
*/
private JsonUtil() {
}
/**
* jsonGson
*
* @param obj
* @return json
*/
public static String toJson(Serializable obj) {
return new Gson().toJson(obj);
}
}

@ -0,0 +1,35 @@
package com.greateme.util;
/**
* <p>
*
* </p>
*
* @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();
}
}

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greateme</groupId>
<artifactId>online-taxi-public</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<description>公共模块</description>
<packaging>pom</packaging>
<modules>
<module>common-entity</module>
<module>common-util</module>
<module>common-contant</module>
</modules>
<artifactId>common</artifactId>
</project>

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.greateme</groupId>
<artifactId>online-taxi-public</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>api</module>
<module>common</module>
</modules>
<description>马士兵的滴约打车项目</description>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 软件版本号 -->
<online-taxi-public.version>1.0-SNAPSHOT</online-taxi-public.version>
<spring-boot.version>2.6.14</spring-boot.version>
<spring-cloud.version>2021.0.7</spring-cloud.version>
<gson.version>2.10.1</gson.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- SpringBoot 相关依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Gson 的 json 处理 -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<!-- 公共常量类模块 -->
<dependency>
<groupId>com.greateme</groupId>
<artifactId>common-contant</artifactId>
<version>${online-taxi-public.version}</version>
</dependency>
<!-- 公共实体类模块 -->
<dependency>
<groupId>com.greateme</groupId>
<artifactId>common-entity</artifactId>
<version>${online-taxi-public.version}</version>
</dependency>
<!-- util 工具模块 -->
<dependency>
<groupId>com.greateme</groupId>
<artifactId>common-util</artifactId>
<version>${online-taxi-public.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Loading…
Cancel
Save