From f195c94d9004036a21905743d9778f91790d1896 Mon Sep 17 00:00:00 2001 From: liuyuanqiang <837052308@qq.com> Date: Tue, 25 Oct 2022 21:45:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=A1=E9=AA=8C=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E6=B5=81=E7=A8=8B=E5=92=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api-passenger/pom.xml | 4 ++ .../VerificationCodeController.java | 15 +++++- .../request/VerificationCodeDTO.java | 14 ++--- .../service/VerificationCodeService.java | 48 +++++++++++++----- .../src/main/resources/application.yml | 6 ++- api-passenger/target/classes/application.yml | 6 ++- .../VerificationCodeController.class | Bin 1757 -> 2306 bytes .../request/VerificationCodeDTO.class | Bin 662 -> 2078 bytes .../service/VerificationCodeService.class | Bin 2172 -> 3216 bytes .../mashibing/common/dto/ResponseResult.java | 10 ++++ .../common/response/TokenResponse.java | 8 +++ .../mashibing/common/dto/ResponseResult.class | Bin 3906 -> 4100 bytes .../common/response/TokenResponse.class | Bin 0 -> 1496 bytes 13 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 internal-common/src/main/java/com/mashibing/common/response/TokenResponse.java create mode 100644 internal-common/target/classes/com/mashibing/common/response/TokenResponse.class 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 dd4825303abbf1eb27a04e71d27759b08f67b795..dd4419a2d021643b8075f6b053c5741a2cfd630c 100644 GIT binary patch delta 961 zcmbVKT~8BH5IwgaY`fVaZ3U}HRTN80>w?yb)GCPLR|^G{#Q3x>D^%OvhON9d@zEzu zCY*+sbGF*z9@v*dL!}))2Zn- z!`-Yrt=Jnny_#d|>kUU=vD~_2yB6_fwXyq66hv~++_cOWYt~lfS;aIO6~~@;)-8d7 z?LR`T@1As`?6{4RQLmFYFA&oYCS^<(W;%4OA#XK0gkuVBX}FCA1$Q*u#l6-$Z+7`U z9%v}aU`fLwmNY~VRZ!Njj1>*5SP%#wB$k3^s3=`GT-UNUtgZ5|0~F zwI;@PlRj583**J-#w;!%2i#6hB$$X(LL=;=g3^r!Y9c6jmNIIT84EXCnwm$PyRTWWzFeMEb*%bNZ=G>f;pqqH_A3=ndKJ@%Th@qaE@o}351LD zEC3X#ZJZZ@WVa{pugUBq<|f+Enk8D#;suQ4?amnK(2P)094d9BDN9OEb?JN3b3N%({3fNV%#}lUF?Yxm6TKt<8 delta 395 zcmX|+IZpyn6otPxfKSE&k2QP+S^fLuo}tB!jFW*STXf}u0f zAK*_g@vj)~Oo+uh=e~2#dH24@=ufEr_51z_lsGd9kvCajF-Uokfs^Pq|As^ z5xETrj|dyWGD~W==WfVq|}ylAiyYN!isSw^;NtYj7Zy29oR2(s;NqCvG yr`i1s*rb@0Y=Bv&#APt!zNtjUTP7^cw4BTZ>Q+p1qH86>yc7mm4|D%}+wcboZ7Dba 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 b9bb2e2cbff45bd39a44d623a40eed9fb82b708f..316211ce1f7ef8e2486133fb5aa55bbce7d7aecf 100644 GIT binary patch literal 2078 zcmbVNU2hvz5Ixu4^{(AbVmq-DLkfYW)E{vT^aE-q0otTr#BJ16k>H7qv&35*JFM6J zG5i4Xk_V8$l|Vx9Ql$O{eg=<}a_;WN#k+o}szmqBotZmx=FHsnvwwg24Zvk=rI0~A z2?Y(gtZGBr>OjI+E>=B%rV|_cY z`fhDElzQXgeIm*nSnhTR`dqOz3H&Tw!$BCJ9}SQzM(@kw(oM^4_x86<$2_!L%OUhx zUXKP%5VP5#c`VZXy+>BdZIr$g5WR7R1CxN-bK91~xRROW5eq?6<~(aeo%5Wdy~+FT zQNz@ZYqq{=nnzwAI5*x5=qJlY<%DDP2OU>nCW0ih z98IRXJ%4}%QainY)3R>bav~POys@Jf<m{4BW-%?9s|nxY{)`R5I`p&T?8_=J4A~=FFob ztGh2yoit&Qp$kAY@DAT`hHpN`Khok!WQKbZ95Up&&hu2`F1V}ZClEh+ZVOx!z7hq> zMj*d|H+d409j@b-e?shs&}D7nWfD5!ay)!lpLqFgEU_G!x$YH4oaM^Th)u?wr;n_} z$1NpEgdjC6myZc)9^RcCGXAO|C8wj1b6!XePJr@n?i#bTE9LK@DkqgcpnL~4ep2}z zN^_+=gz6nBB<`(nsVmh#ai*X=MdlbrwV({4oqFhXl`eWcQBb8%;wiGnm@24+#Ho{V z!d!8L`*+*NFyf(&^LUS-bJ)QJ_B2Mk8z@p2M;YrVQBrV=Je4V_Xws)bDS;KnUqVvT z|G~6|>T~2ZT;#tlo@2omlOreHBjTs z1QJLxe!~aI-QtHf|I#i}+@a_eRZ@*w{RsKlZHLtu&vn8H`B&F_zq(C5B9JDl3nuEQ J4EUx*_6ZcG8-M@+ 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 c0f5a47337b1422fe2f3d94b870f61fff93b4e66..322fb10a5eb30bc419e849691484be544fcc07cc 100644 GIT binary patch literal 3216 zcmbtWYjYGu6g{(9vYX8SF$4tVElLsyg9Zf>2!yA>05J(cRMg3ACmFIkv(C%{@qtD_ z0|f9vQD{*LlvtKkNThTlXjy*tf9wLE{0Ek&XE&Q{2my3I^lW$Ed;6Tzw{Q1f|J?cm zz$y$zumsz~c(DXep{WEr@KPAf5$wb+IkLMHEqFPCRhtU&)8NmV>?STCDh7b!O zu3(-koP(wzIz*S*Wg5C?+LmEQ#pakPEKfmWvth@zxbF6tou<{T=?OETyRNXhg`+tl zZhJy&n=C}Vf;p{8%QNGm!*tEgm}s;t+w&K46|8Btoo>xdI1Jw9=y7q#c6zl=p|QHGu2deW;^L`}C{#1k>y6AIQ&7%-}PI^oh%Gi-;D?{#Iw zSqFuaS79?%XmKdZVFl&Q2lRuw7SpLf)|J-9>rBh^8Wa>&R&^){N(Tkgn@vmXO2#{d z)2@@PbhZsW)}cG5?B@o9UXMxo>n4*ow>4VFI8-^k31Motu!N&irR?JCEAItbHEs#+ zXWX{5sAp@f!cEwgEBH;uJjR=r-`kcR+amU9PJxMnM~N1(d>OLPlqL$*EBdH%p&osS z5l!|#EYk6+~(H33inI|0TUt;tKqc@9i_XOhoKRL_B z=M#6#vwMX#0!u;7#GLa~+Q*ucL!`}4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AVS4hS>wq?x}iJXbHIsx1{vlqu8{$Q_PVdLdXTYi06OR) zTj-S;eI%A*D`j4aZ4_M;$r{2AT16=eo~L&U?EPN(1fd`Uew-xKY6P4@C#@L5=%PbJ z^G{UW@KC}(z@@t#NWGiz1iYW&bzw5%K>iBFfp3_~+fZk>;MX+=hgu!fIXFyw(HEe& zjUZL^A*or?>!nXB8_42I%js2GIbW^weVzA&j62aZ*1+ z`m>~5jNf0IaDRN772W6|84XCI7pF-|JH`;f89F>pJ!i=i34PQlgx6T-h;^QJJdB!! Pg%|d)AO642UIhLCiI<#d 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 3cce099c0fc0462928c04502d68a5662e92b4944..78d01ddc342095945860dd919793c63a28ce452a 100644 GIT binary patch delta 1542 zcma)6$xc*36g~BNc(0!Y!5|_I&>&*BsMyd>3@tbyf{ODjh=M5MEI1;XxOHJFy7dFx z7){V-B&}6G&5a>(;%e&Z&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