diff --git a/api-passenger/pom.xml b/api-passenger/pom.xml index a3ad75a..5c7eee5 100644 --- a/api-passenger/pom.xml +++ b/api-passenger/pom.xml @@ -26,6 +26,17 @@ org.springframework.cloud spring-cloud-starter-openfeign + + + com.mashibing + internal-common + 1.0-SNAPSHOT + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + 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 44138bc..18cbfc6 100644 --- a/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/ApiPassengerApplication.java @@ -3,6 +3,7 @@ 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; /** * @author kezhen @@ -11,6 +12,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; */ @SpringBootApplication @EnableDiscoveryClient +@EnableFeignClients public class ApiPassengerApplication { public static void main(String[] args) { SpringApplication.run(ApiPassengerApplication.class); diff --git a/api-passenger/src/main/java/com/mashibing/apipassenger/controller/TestController.java b/api-passenger/src/main/java/com/mashibing/apipassenger/controller/TestController.java index c505268..f0f39e6 100644 --- a/api-passenger/src/main/java/com/mashibing/apipassenger/controller/TestController.java +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/controller/TestController.java @@ -1,6 +1,10 @@ package com.mashibing.apipassenger.controller; +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.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; /** @@ -11,8 +15,18 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { + @Autowired + VerificationCodeService verificationCodeService; + @GetMapping("/test") public String test(){ return "tingting"; } + + @GetMapping("/verification-code") + public String getNumberCode(){ + String s = verificationCodeService.generatorCode("1234"); + System.out.println("s = " + s); + return null; + } } 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..51c8597 --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.java @@ -0,0 +1,22 @@ +package com.mashibing.apipassenger.remote; + +import com.mashibing.internalcommon.dto.ResponseResult; +import com.mashibing.internalcommon.response.NumberCodeResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.reflect.Method; + +/** + * @author kezhen + * @date 2023/7/12 + * @description + */ +@FeignClient("service-verificationcode") +public interface ServiceVefificationcodeClient { + + @RequestMapping(method = RequestMethod.GET,value = "/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 new file mode 100644 index 0000000..f1779bd --- /dev/null +++ b/api-passenger/src/main/java/com/mashibing/apipassenger/service/VerificationCodeService.java @@ -0,0 +1,30 @@ +package com.mashibing.apipassenger.service; + +import com.mashibing.apipassenger.remote.ServiceVefificationcodeClient; +import com.mashibing.internalcommon.dto.ResponseResult; +import com.mashibing.internalcommon.response.NumberCodeResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author kezhen + * @date 2023/7/12 + * @description + */ +@Service +public class VerificationCodeService { + + @Autowired + ServiceVefificationcodeClient serviceVefificationcodeClient; + + public String generatorCode(String passengerPhone) { + // 调用验证码服务,获取验证码 + ResponseResult numberCodeResponse = serviceVefificationcodeClient.getNumberCode(6); + int numberCode = numberCodeResponse.getData().getNumberCode(); + System.out.println("numberCode = " + numberCode); + + // 存入redis + + return Integer.toString(numberCode); + } +} diff --git a/pom.xml b/pom.xml index 01b39aa..ff08538 100644 --- a/pom.xml +++ b/pom.xml @@ -33,11 +33,7 @@ jdk15 - - com.mashibing - internal-common - 1.0-SNAPSHOT - + diff --git a/service-verificationcode/pom.xml b/service-verificationcode/pom.xml index d0b2795..5e6593f 100644 --- a/service-verificationcode/pom.xml +++ b/service-verificationcode/pom.xml @@ -23,6 +23,12 @@ spring-cloud-starter-alibaba-nacos-discovery + + com.mashibing + internal-common + 1.0-SNAPSHOT + +