diff --git a/api-passenger/pom.xml b/api-passenger/pom.xml
index 16f47f1..9997975 100644
--- a/api-passenger/pom.xml
+++ b/api-passenger/pom.xml
@@ -33,6 +33,10 @@
org.springframework.cloud
spring-cloud-starter-loadbalancer
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
org.mashibing
diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/controller/VerificationCodeController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/controller/VerificationCodeController.java
index 13a4706..5e386a6 100644
--- a/api-passenger/src/main/java/com/mashibing/apipassenger/controller/VerificationCodeController.java
+++ b/api-passenger/src/main/java/com/mashibing/apipassenger/controller/VerificationCodeController.java
@@ -2,8 +2,10 @@ package com.mashibing.apipassenger.controller;
import com.mashibing.apipassenger.request.VerificationCodeDTO;
import com.mashibing.apipassenger.service.VerificationCodeService;
+import com.mashibing.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
@@ -13,12 +15,23 @@ public class VerificationCodeController {
private VerificationCodeService verificationCodeService;
@GetMapping("verification-code")
- public String verificateCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
+ public ResponseResult verificateCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
String passengerPhone = verificationCodeDTO.getPassengerPhone();
System.out.println("接收到的参数:" + passengerPhone);
//调用短信验证码服务并存储到Redis
return verificationCodeService.generatorCode(passengerPhone);
+ }
+
+ @PostMapping("/verification-code-check")
+ public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
+
+ String verificationCode = verificationCodeDTO.getVerificationCode();
+ String passengerPhone = verificationCodeDTO.getPassengerPhone();
+ System.out.println("verificationCode:" + verificationCode + ",passengerPhone:" + passengerPhone);
+
+ return verificationCodeService.checkCode(passengerPhone,verificationCode);
}
+
}
diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/request/VerificationCodeDTO.java b/api-passenger/src/main/java/com/mashibing/apipassenger/request/VerificationCodeDTO.java
index c1e2456..bcdcd5e 100644
--- a/api-passenger/src/main/java/com/mashibing/apipassenger/request/VerificationCodeDTO.java
+++ b/api-passenger/src/main/java/com/mashibing/apipassenger/request/VerificationCodeDTO.java
@@ -1,16 +1,10 @@
package com.mashibing.apipassenger.request;
+import lombok.Data;
+
+@Data
public class VerificationCodeDTO {
private String passengerPhone;
-
- public String getPassengerPhone() {
- return passengerPhone;
- }
-
- public void setPassengerPhone(String passengerPhone) {
- this.passengerPhone = passengerPhone;
- }
-
-
+ private String verificationCode;
}
diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java b/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java
index 4b4f284..fa4e8f7 100644
--- a/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java
+++ b/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java
@@ -3,15 +3,29 @@ package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServiceVefificationcodeClient;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.response.NumberCodeResponse;
+import com.mashibing.common.response.TokenResponse;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
+import java.util.concurrent.TimeUnit;
+
@Service
public class VerificationCodeService {
@Autowired
- ServiceVefificationcodeClient serviceVefificationcodeClient;
- public String generatorCode(String passengerPhone){
+ private ServiceVefificationcodeClient serviceVefificationcodeClient;
+
+ @Autowired
+ private StringRedisTemplate stringRedisTemplate;
+ private String verificationCodePrefix = "verification-code-";
+
+ /**
+ * 生成验证码
+ * @param passengerPhone
+ * @return
+ */
+ public ResponseResult generatorCode(String passengerPhone){
//调用验证码服务,获取验证码
System.out.println("调用验证码服务,获取验证码");
ResponseResult responseResult = serviceVefificationcodeClient.getNumberCode(6);
@@ -20,25 +34,33 @@ public class VerificationCodeService {
//存入redis
System.out.println("存入redis");
+ String key = verificationCodePrefix + numberCode;
+ stringRedisTemplate.opsForValue().set(key, "" + numberCode,2, TimeUnit.MINUTES);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code",1);
- jsonObject.put("message","success");
-
- return jsonObject.toString();
-
-
-
-
-
+ //发送短信。。。
+ return ResponseResult.success("");
+ }
+ /**
+ * 校验验证码
+ * @param passengerPhone
+ * @param verificationCode
+ * @return
+ */
+ public ResponseResult checkCode(String passengerPhone, String verificationCode) {
+ System.out.println("根据手机号和验证码,查询redis");
+ System.out.println("校验验证码");
+ System.out.println("判断是否有用户,没有则新增用户");
+ System.out.println("颁发token");
+ TokenResponse tokenResponse = new TokenResponse();
+ tokenResponse.setToken("my token");
+ return ResponseResult.success(tokenResponse);
}
-
}
diff --git a/api-passenger/src/main/resources/application.yml b/api-passenger/src/main/resources/application.yml
index 5718e4f..5ef4dda 100644
--- a/api-passenger/src/main/resources/application.yml
+++ b/api-passenger/src/main/resources/application.yml
@@ -7,4 +7,8 @@ spring:
cloud:
nacos:
discovery:
- server-addr: 127.0.0.1:8848
\ No newline at end of file
+ server-addr: 127.0.0.1:8848
+ redis:
+ port: 6379
+ host: 192.168.1.10
+ database: 0
\ No newline at end of file
diff --git a/api-passenger/target/classes/application.yml b/api-passenger/target/classes/application.yml
index 5718e4f..5ef4dda 100644
--- a/api-passenger/target/classes/application.yml
+++ b/api-passenger/target/classes/application.yml
@@ -7,4 +7,8 @@ spring:
cloud:
nacos:
discovery:
- server-addr: 127.0.0.1:8848
\ No newline at end of file
+ server-addr: 127.0.0.1:8848
+ redis:
+ port: 6379
+ host: 192.168.1.10
+ database: 0
\ No newline at end of file
diff --git a/api-passenger/target/classes/com/mashibing/apipassenger/controller/VerificationCodeController.class b/api-passenger/target/classes/com/mashibing/apipassenger/controller/VerificationCodeController.class
index dd48253..dd4419a 100644
Binary files a/api-passenger/target/classes/com/mashibing/apipassenger/controller/VerificationCodeController.class and b/api-passenger/target/classes/com/mashibing/apipassenger/controller/VerificationCodeController.class differ
diff --git a/api-passenger/target/classes/com/mashibing/apipassenger/request/VerificationCodeDTO.class b/api-passenger/target/classes/com/mashibing/apipassenger/request/VerificationCodeDTO.class
index b9bb2e2..316211c 100644
Binary files a/api-passenger/target/classes/com/mashibing/apipassenger/request/VerificationCodeDTO.class and b/api-passenger/target/classes/com/mashibing/apipassenger/request/VerificationCodeDTO.class differ
diff --git a/api-passenger/target/classes/com/mashibing/apipassenger/service/VerificationCodeService.class b/api-passenger/target/classes/com/mashibing/apipassenger/service/VerificationCodeService.class
index c0f5a47..322fb10 100644
Binary files a/api-passenger/target/classes/com/mashibing/apipassenger/service/VerificationCodeService.class and b/api-passenger/target/classes/com/mashibing/apipassenger/service/VerificationCodeService.class differ
diff --git a/internal-common/src/main/java/com/mashibing/common/dto/ResponseResult.java b/internal-common/src/main/java/com/mashibing/common/dto/ResponseResult.java
index ca3d085..55f065c 100644
--- a/internal-common/src/main/java/com/mashibing/common/dto/ResponseResult.java
+++ b/internal-common/src/main/java/com/mashibing/common/dto/ResponseResult.java
@@ -11,6 +11,16 @@ public class ResponseResult {
private String message;
private T data;
+ /**
+ * 成功响应的方法
+ * @param
+ * @return
+ */
+ public static ResponseResult success(){
+ return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode())
+ .setMessage(CommonStatusEnum.SUCCESS.getMsg());
+ }
+
/**
* 成功响应的方法
* @param data
diff --git a/internal-common/src/main/java/com/mashibing/common/response/TokenResponse.java b/internal-common/src/main/java/com/mashibing/common/response/TokenResponse.java
new file mode 100644
index 0000000..3e34230
--- /dev/null
+++ b/internal-common/src/main/java/com/mashibing/common/response/TokenResponse.java
@@ -0,0 +1,8 @@
+package com.mashibing.common.response;
+
+import lombok.Data;
+
+@Data
+public class TokenResponse {
+ private String token;
+}
diff --git a/internal-common/target/classes/com/mashibing/common/dto/ResponseResult.class b/internal-common/target/classes/com/mashibing/common/dto/ResponseResult.class
index 3cce099..78d01dd 100644
Binary files a/internal-common/target/classes/com/mashibing/common/dto/ResponseResult.class and b/internal-common/target/classes/com/mashibing/common/dto/ResponseResult.class differ
diff --git a/internal-common/target/classes/com/mashibing/common/response/TokenResponse.class b/internal-common/target/classes/com/mashibing/common/response/TokenResponse.class
new file mode 100644
index 0000000..1097e60
Binary files /dev/null and b/internal-common/target/classes/com/mashibing/common/response/TokenResponse.class differ