diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/controller/VerificationController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/controller/VerificationController.java new file mode 100644 index 0000000..1803d36 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/controller/VerificationController.java @@ -0,0 +1,26 @@ +package com.mashibing.apipassenger.controller; + +import com.mashibing.apipassenger.request.VerificationCodeDTO; +import com.mashibing.apipassenger.service.VerificationCodeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class VerificationController { + + @Autowired + private VerificationCodeService service; + + // 实现 乘客获取验证码 API + @GetMapping("/verification-code") + public String verificationcode(@RequestBody VerificationCodeDTO verificationCodeDTO){ + + String passengerPhone = verificationCodeDTO.getPassengerPhone(); + System.out.println("接受到的手机验证码为"+passengerPhone); + + return service.generatorCode(passengerPhone); + } + +} 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 new file mode 100644 index 0000000..2a4a9ab --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/request/VerificationCodeDTO.java @@ -0,0 +1,15 @@ +package com.mashibing.apipassenger.request; + + +public class VerificationCodeDTO { + + private String passengerPhone; + + public String getPassengerPhone() { + return passengerPhone; + } + + public void setPassengerPhone(String passengerPhone) { + this.passengerPhone = passengerPhone; + } +} 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 new file mode 100644 index 0000000..2d1eb2f --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java @@ -0,0 +1,24 @@ +package com.mashibing.apipassenger.service; + +import net.sf.json.JSONObject; +import org.springframework.stereotype.Service; + +@Service +public class VerificationCodeService { + + public String generatorCode(String passengerPhone){ + + // 调用验证码服务,获取验证码 + System.out.println("调用验证码服务,获取验证码"); + String code = "111111"; + + // 存入redis + System.out.println("存入redis"); + JSONObject result = new JSONObject(); + result.put("code",1); + result.put("message","success"); + // 返回值 + return result.toString(); + } + +} diff --git a/pom.xml b/pom.xml index 000e7d6..0ba094d 100644 --- a/pom.xml +++ b/pom.xml @@ -28,4 +28,13 @@ + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + \ No newline at end of file