parent
9f0532f523
commit
80e298d8fa
@ -1,26 +0,0 @@
|
|||||||
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,30 @@
|
|||||||
|
<?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>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<description>公共的注解模块</description>
|
||||||
|
|
||||||
|
<artifactId>common-annotation</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- SpringBoot的相关依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 公共常量类模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.greateme</groupId>
|
||||||
|
<artifactId>common-contant</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.greateme.springboot;
|
||||||
|
|
||||||
|
import com.greateme.contant.PackageContent;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 自定义启用feign的注解
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 14:54:30
|
||||||
|
* @file EnableTaxiFeignClients.java
|
||||||
|
*/
|
||||||
|
@EnableFeignClients(basePackages = PackageContent.SPRING_BOOT_SCAN_PACKAGE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE})
|
||||||
|
public @interface EnableTaxiFeignClients {
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.greateme.springboot;
|
||||||
|
|
||||||
|
import com.greateme.contant.PackageContent;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 自定义的SpringBoot启动类注解
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 14:18:59
|
||||||
|
* @file TaxiSpringBootApplication.java
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(scanBasePackages = PackageContent.SPRING_BOOT_SCAN_PACKAGE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE})
|
||||||
|
public @interface TaxiSpringBootApplication {
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.greateme.contant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 包名相关的常量类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 14:16:08
|
||||||
|
* @file PackageContent.java
|
||||||
|
*/
|
||||||
|
public class PackageContent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此类不允许实例化
|
||||||
|
*/
|
||||||
|
private PackageContent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringBoot扫描的包路径
|
||||||
|
*/
|
||||||
|
public static final String SPRING_BOOT_SCAN_PACKAGE = "com.greateme";
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.greateme.contant.http;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务名称的常量类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023_05_31 星期三 14:28:04
|
||||||
|
* @file ServiceNameConstant.java
|
||||||
|
*/
|
||||||
|
public class ServiceNameConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此类不允许实例化
|
||||||
|
*/
|
||||||
|
private ServiceNameConstant() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api_passenger 的服务名称
|
||||||
|
*/
|
||||||
|
public static final String API_PASSENGER = "api-passenger";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* service-verification-code 的服务名称
|
||||||
|
*/
|
||||||
|
public static final String SERVICE_VERIFICATION_CODE = "service-verification-code";
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<artifactId>feign-client</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>verification-code-client</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,36 @@
|
|||||||
|
<?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>feign-client</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<description>验证码模块的远程调用</description>
|
||||||
|
|
||||||
|
<artifactId>verification-code-client</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 远程调用 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 负载均衡器 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 公共实体类模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.greateme</groupId>
|
||||||
|
<artifactId>common-entity</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -1,4 +1,4 @@
|
|||||||
package com.greateme.passenger.entity.dto;
|
package com.greateme.verification.entity.dto;
|
||||||
|
|
||||||
import com.greateme.util.JsonUtil;
|
import com.greateme.util.JsonUtil;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.greateme.passenger.entity.dto;
|
package com.greateme.verification.entity.dto;
|
||||||
|
|
||||||
import com.greateme.util.JsonUtil;
|
import com.greateme.util.JsonUtil;
|
||||||
|
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.greateme.verification.entity.vo;
|
||||||
|
|
||||||
|
import com.greateme.util.JsonUtil;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机验证码的token
|
||||||
|
*/
|
||||||
|
private String verificationToken;
|
||||||
|
|
||||||
|
public String getVerificationCode() {
|
||||||
|
return verificationCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVerificationCode(String verificationCode) {
|
||||||
|
this.verificationCode = verificationCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVerificationToken() {
|
||||||
|
return verificationToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVerificationToken(String verificationToken) {
|
||||||
|
this.verificationToken = verificationToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return JsonUtil.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.greateme.verification.feign;
|
||||||
|
|
||||||
|
import com.greateme.contant.http.ServiceNameConstant;
|
||||||
|
import com.greateme.entity.respose.ResponseEntity;
|
||||||
|
import com.greateme.verification.entity.dto.PassengerVerificationCodeDTO;
|
||||||
|
import com.greateme.verification.entity.vo.PassengerVerificationCodeVO;
|
||||||
|
import com.greateme.verification.feign.fallback.VerificationCodeFallback;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 验证码的远程调用器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 14:32:59
|
||||||
|
* @file VerificationCodeRemote.java
|
||||||
|
*/
|
||||||
|
@FeignClient(contextId = "verificationCodeRemote", value = ServiceNameConstant.SERVICE_VERIFICATION_CODE, fallback = VerificationCodeFallback.class)
|
||||||
|
public interface VerificationCodeRemote {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个乘客的短信验证码
|
||||||
|
*
|
||||||
|
* @param verificationCode 生成乘客验证码的参数
|
||||||
|
* @param length 生成验证码的长度
|
||||||
|
* @return 生成后的详细数据
|
||||||
|
*/
|
||||||
|
@PostMapping("/verificationCode/passengerPhone/{length}")
|
||||||
|
ResponseEntity<PassengerVerificationCodeVO> passengerPhone(@RequestBody PassengerVerificationCodeDTO verificationCode, @PathVariable("length") int length);
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.greateme.verification.feign.fallback;
|
||||||
|
|
||||||
|
import com.greateme.entity.respose.ResponseEntity;
|
||||||
|
import com.greateme.verification.entity.dto.PassengerVerificationCodeDTO;
|
||||||
|
import com.greateme.verification.entity.vo.PassengerVerificationCodeVO;
|
||||||
|
import com.greateme.verification.feign.VerificationCodeRemote;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 验证码的远程调用器的回调类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 14:43:10
|
||||||
|
* @file VerificationCodeFallback.java
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class VerificationCodeFallback implements FallbackFactory<VerificationCodeRemote> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录日志的实体
|
||||||
|
*/
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(VerificationCodeFallback.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VerificationCodeRemote create(Throwable cause) {
|
||||||
|
return new VerificationCodeRemote() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个乘客的短信验证码发生了错误
|
||||||
|
*
|
||||||
|
* @param verificationCode 生成乘客验证码的参数
|
||||||
|
* @param length 生成验证码的长度
|
||||||
|
* @return 生成后的详细数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<PassengerVerificationCodeVO> passengerPhone(PassengerVerificationCodeDTO verificationCode, int length) {
|
||||||
|
log.error("调用远程发送验证码的接口发生了错误,手机号码:{},验证码长度:{}", verificationCode.getPassengerPhone(), length);
|
||||||
|
return ResponseEntity.error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
com.greateme.verification.feign.fallback.VerificationCodeFallback
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.greateme.verification.controller;
|
||||||
|
|
||||||
|
import com.greateme.entity.respose.ResponseEntity;
|
||||||
|
import com.greateme.verification.entity.dto.PassengerVerificationCodeDTO;
|
||||||
|
import com.greateme.verification.entity.vo.PassengerVerificationCodeVO;
|
||||||
|
import com.greateme.verification.service.VerificationCodeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 验证码的控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 11:49:00
|
||||||
|
* @file VerificationCodeController.java
|
||||||
|
*/
|
||||||
|
@RequestMapping("/verificationCode")
|
||||||
|
@RestController
|
||||||
|
public class VerificationCodeController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VerificationCodeService verificationCodeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个乘客的短信验证码
|
||||||
|
*
|
||||||
|
* @param verificationCode 生成乘客验证码的参数
|
||||||
|
* @param length 生成验证码的长度
|
||||||
|
* @return 生成后的详细数据
|
||||||
|
*/
|
||||||
|
@PostMapping("/passengerPhone/{length}")
|
||||||
|
public ResponseEntity<PassengerVerificationCodeVO> passengerPhone(@RequestBody PassengerVerificationCodeDTO verificationCode, @PathVariable("length") int length) {
|
||||||
|
return ResponseEntity.success(this.verificationCodeService.generationPassengerPhone(verificationCode, length));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.greateme.verification.service;
|
||||||
|
|
||||||
|
import com.greateme.verification.entity.dto.PassengerVerificationCodeDTO;
|
||||||
|
import com.greateme.verification.entity.vo.PassengerVerificationCodeVO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 验证码的业务处理接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 13:56:40
|
||||||
|
* @file VerificationCodeServiceImpl.java
|
||||||
|
*/
|
||||||
|
public interface VerificationCodeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个乘客的短信验证码
|
||||||
|
*
|
||||||
|
* @param verificationCode 生成乘客验证码的参数
|
||||||
|
* @param length 生成验证码的长度
|
||||||
|
* @return 生成后的详细数据
|
||||||
|
*/
|
||||||
|
PassengerVerificationCodeVO generationPassengerPhone(PassengerVerificationCodeDTO verificationCode, int length);
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.greateme.verification.service.impl;
|
||||||
|
|
||||||
|
import com.greateme.util.StringUtil;
|
||||||
|
import com.greateme.verification.entity.dto.PassengerVerificationCodeDTO;
|
||||||
|
import com.greateme.verification.entity.dto.PassengerVerificationCodeRedisDTO;
|
||||||
|
import com.greateme.verification.entity.vo.PassengerVerificationCodeVO;
|
||||||
|
import com.greateme.verification.service.VerificationCodeService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 验证码的业务处理实现
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author XiaoHH
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2023-05-31 星期三 13:58:24
|
||||||
|
* @file VerificationCodeServiceImpl.java
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class VerificationCodeServiceImpl implements VerificationCodeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个乘客的短信验证码
|
||||||
|
*
|
||||||
|
* @param verificationCode 生成乘客验证码的参数
|
||||||
|
* @param length 生成验证码的长度
|
||||||
|
* @return 生成后的详细数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PassengerVerificationCodeVO generationPassengerPhone(PassengerVerificationCodeDTO verificationCode, int length) {
|
||||||
|
// 生成6位的手机验证码
|
||||||
|
String code = StringUtil.generationVerificationCode(length);
|
||||||
|
// 生成对应手机验证码的token
|
||||||
|
String token = UUID.randomUUID().toString();
|
||||||
|
// 初始化存入redis当中的对象
|
||||||
|
PassengerVerificationCodeRedisDTO verificationCodeRedis = new PassengerVerificationCodeRedisDTO();
|
||||||
|
verificationCodeRedis.setVerificationCode(code);
|
||||||
|
verificationCodeRedis.setPassengerPhone(verificationCode.getPassengerPhone());
|
||||||
|
verificationCodeRedis.setToken(token);
|
||||||
|
// TODO 将 verificationCodeRedis 存入redis
|
||||||
|
// 将token和code返回
|
||||||
|
PassengerVerificationCodeVO result = new PassengerVerificationCodeVO();
|
||||||
|
result.setVerificationCode(code);
|
||||||
|
result.setVerificationToken(token);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue