diff --git a/api-passenger/pom.xml b/api-passenger/pom.xml index 23daa23..16f47f1 100644 --- a/api-passenger/pom.xml +++ b/api-passenger/pom.xml @@ -21,6 +21,24 @@ org.springframework.boot spring-boot-starter-web + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.mashibing + internal-common + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java b/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java index 3a8fd49..1d09a87 100644 --- a/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java @@ -3,9 +3,11 @@ package com.mashibing.apipassenger; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableDiscoveryClient +@EnableFeignClients public class ApiPassengerApplication { //log public static void main(String[] args) { diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.java b/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.java new file mode 100644 index 0000000..bed7500 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.java @@ -0,0 +1,13 @@ +package com.mashibing.apipassenger.remote; + +import com.mashibing.common.dto.ResponseResult; +import com.mashibing.common.response.NumberCodeResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient("service-verificationcode") +public interface ServiceVefificationcodeClient { + @GetMapping("/numberCode/{size}") + ResponseResult getNumberCode(@PathVariable("size") int size); +} 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 4bbcdb2..4b4f284 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 @@ -1,15 +1,22 @@ package com.mashibing.apipassenger.service; +import com.mashibing.apipassenger.remote.ServiceVefificationcodeClient; +import com.mashibing.common.dto.ResponseResult; +import com.mashibing.common.response.NumberCodeResponse; import net.sf.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class VerificationCodeService { - + @Autowired + ServiceVefificationcodeClient serviceVefificationcodeClient; public String generatorCode(String passengerPhone){ //调用验证码服务,获取验证码 System.out.println("调用验证码服务,获取验证码"); - String code = "111111"; + ResponseResult responseResult = serviceVefificationcodeClient.getNumberCode(6); + int numberCode = responseResult.getData().getNumberCode(); + System.out.println("接收到的numberCode:" + numberCode); //存入redis System.out.println("存入redis"); diff --git a/api-passenger/target/classes/com/mashibing/apipassenger/ApiPassengerApplication.class b/api-passenger/target/classes/com/mashibing/apipassenger/ApiPassengerApplication.class index d97cd2e..1dca2bf 100644 Binary files a/api-passenger/target/classes/com/mashibing/apipassenger/ApiPassengerApplication.class and b/api-passenger/target/classes/com/mashibing/apipassenger/ApiPassengerApplication.class differ diff --git a/api-passenger/target/classes/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.class b/api-passenger/target/classes/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.class new file mode 100644 index 0000000..548bfa1 Binary files /dev/null and b/api-passenger/target/classes/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.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 a00518d..c0f5a47 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/target/internal-common-1.0-SNAPSHOT.jar b/internal-common/target/internal-common-1.0-SNAPSHOT.jar index b7d0fd8..6c03e84 100644 Binary files a/internal-common/target/internal-common-1.0-SNAPSHOT.jar and b/internal-common/target/internal-common-1.0-SNAPSHOT.jar differ diff --git a/pom.xml b/pom.xml index df61aeb..a07f4b9 100644 --- a/pom.xml +++ b/pom.xml @@ -34,24 +34,39 @@ 2.4 jdk15 + org.projectlombok lombok 1.18.24 - + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2021.1 + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + 2020.0.1 + pom + import + + + + \ No newline at end of file diff --git a/service-verificationcode/pom.xml b/service-verificationcode/pom.xml index 74e4c42..97cd096 100644 --- a/service-verificationcode/pom.xml +++ b/service-verificationcode/pom.xml @@ -32,6 +32,11 @@ internal-common 1.0-SNAPSHOT + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + diff --git a/service-verificationcode/src/main/java/com/mashibing/service/controller/NumberCodeController.java b/service-verificationcode/src/main/java/com/mashibing/service/controller/NumberCodeController.java index a6ceb4b..eee6d2a 100644 --- a/service-verificationcode/src/main/java/com/mashibing/service/controller/NumberCodeController.java +++ b/service-verificationcode/src/main/java/com/mashibing/service/controller/NumberCodeController.java @@ -18,7 +18,7 @@ public class NumberCodeController { //获取随机数 double mathRandom = (Math.random() * 9 + 1) * pow(10, size-1); int resultInt = (int) mathRandom; - System.out.println(resultInt); + System.out.println("generate numberCode:" + resultInt); NumberCodeResponse response = new NumberCodeResponse(); response.setNumberCode(resultInt);