From 585cb383bdf75a910564a8925e130c511a4f194b Mon Sep 17 00:00:00 2001 From: liuyuanqiang <837052308@qq.com> Date: Sun, 23 Oct 2022 16:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87open=20feign=20=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E8=B0=83=E7=94=A8service-verificationcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api-passenger/pom.xml | 18 ++++++++++ .../apipassenger/ApiPassengerApplication.java | 2 ++ .../remote/ServiceVefificationcodeClient.java | 13 ++++++++ .../service/VerificationCodeService.java | 11 +++++-- .../ApiPassengerApplication.class | Bin 875 -> 938 bytes .../ServiceVefificationcodeClient.class | Bin 0 -> 740 bytes .../service/VerificationCodeService.class | Bin 1235 -> 2172 bytes .../target/internal-common-1.0-SNAPSHOT.jar | Bin 5649 -> 5649 bytes pom.xml | 31 +++++++++++++----- service-verificationcode/pom.xml | 5 +++ .../controller/NumberCodeController.java | 2 +- 11 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 api-passenger/src/main/java/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.java create mode 100644 api-passenger/target/classes/com/mashibing/apipassenger/remote/ServiceVefificationcodeClient.class 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 d97cd2e838243fc19c6adbd184ce4d2aefe1a3e1..1dca2bff191bf77be9f43474a14ca9e4626d6afe 100644 GIT binary patch delta 129 zcmaFOwu)W$)W2Q(7#J8#7!mq_`NQ8D!WQWH-vrWMpAvu<)6z$Rwha zoReRgqMu)onwOTEnVzTbnwOZAlj;UyJLhDk=9Lsr-pUxjCdb1d&!8}wo9Q7V_vE)s dPON+kTnzk^O_+7~`52fPM1i)60kJp(0{|F+9S#5h delta 81 zcmZ3*{+dnp)W2Q(7#J8#7!5KXCWtXG006<04kQ2o 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 0000000000000000000000000000000000000000..548bfa1052cde66e070de7ff699c3d5ad8bc0d97 GIT binary patch literal 740 zcmb7C+e!m55S`T4s`Y*Wef3E}9fabGqDY}4c*8uqE>BzQcR`mszB)& zd6gQCkvDivE;HH@$2{@-0_M-jcTIF9txU<2bppyxJu=Z`OT}9H-17YPAEXCAtJ_ay z{5Jb#X8(|ltX=2YtCZTxsUV?at&Nvnu~`B2Gh<_PndNLch0zCN@9}{G^ zx5)NXNNwtX56aMOoE2Hp*iR1#h4DKlO;{pVfxcUG@S-=>Sxm9>o5iri7 s%Dn^=Fv)S2p;O#zHy|8L!wm0D7x#;Unqzzk=KA>gKEB4=3xlJ@4*??O+W-In literal 0 HcmV?d00001 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 a00518d84853145b5e43174ed279189f9594752e..c0f5a47337b1422fe2f3d94b870f61fff93b4e66 100644 GIT binary patch literal 2172 zcmb7F+fy4=82=pz*|2O|2$VtvYrQ}~+O3Ke0ck0fni?)8ZEDq8Pc|oEG1<-RZs_pX zQD+>dtuGzNaeUB+&N$9EqT>X$j^nfc2bVtiA2@y|S#klS^&#im^PTVV`>y%xpWprf zFbq@0QJikZD;NpkRTZNcYeqN5TksktRGh(C1(Pa5IHzDrg^JT5oR{=V= z|9*Sx?%MiipI7(_u4qW$s)i@fqu?zK*YLK2cQm|<>kOyr2j$T*Oa1p4j_fS_xq_KZ z35Q-b?%vI~^7_E<_ZsZ>^6I8@%INQBe!-}s^J#sX%c7dAkaCtOL zTc4*<@n~QK&ru_^mu%Ft37}jOUe+SLy~d1Iz?pr3KhCZy4YXJ7PKKdK^#9CUe?0)d z2X>Dq1(OlpdG1l$c0_77L}dzTsnN^^c|I?!6vK(VLf*Am{MMlq_DJB>Qj~X5^*Q9( zW!6sr{?cM-t13q=Ptdw2(91kq5OZnjv3m2q1o>^u%fgP-qV+?nLF0330s1T)r~kU6 z^he0(M`K2`m%f5TpCsBqlxCOC<8;%BO1Y-NHLxE`&rj1Sg@G14L#I|2z_WOcZVY|s zCnHk%AsW#{RQ!a7aAOgH!JpC88vGT(2Fwf;1_fhari2IcZQFYzl!KuB}a{r;QG)^XDj`Gx1j@Jil!YS z=)_rcAxg1dq3CZ=+!Fk78K4iIpdx|+3Zes-Fo@?VkYkv}5KfToDCwM}j0A9sG-cRj ZsTWAmrCbwC9N+5{{mjMbVC3D delta 442 zcmXYtOD{t~6vuz}(L1-dm+D2m>Rm;vDD{4`v0*EgO*K|x(U4f#+co2Zh(!sB4`6F+ z>0^jEQzn^nerIyd{QooG9Ut+-_n((Hpv-lR+A zwe*HNnNw_pY_b)y&5nh-sMYJ0^O{ios#=vIWS2dC=f3KOcdakHu{5J3#j#m77NR1t zQTQ4>s?G8%yC+l*?H zCkSzKGqZ33H8L=O)GT2%fy!BeOqeXrqy?s3m@L3_J(CAWe)B0HAIxB7lVbxj)Oa{q z!Agt-?ZI@3AjGKEg8E=1?+RLiX-OdmF#TRgdUCmt9+ZYz3w(ggwCY XVc`g{yqripm~IdO^EclXF=GS(yZB26 delta 255 zcmbQJGf{^(z?+#xgn@yBgW>kxu!+1Im_gJ573Nz&>bX3Kn#{?l38qaM4Z!qmMzzTk zgt)nxS-5~285lrnmN1$?uxcelH|Fxm-vO%w8en0u}QF>$MiP0@D@39$@;g Wa0FOhP9z>oH;91wn{SJlF#-T;PGLp> 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);