获取验证码

main
kaiupup 2 years ago
parent 153bbac097
commit 36a5181b2b

@ -4,6 +4,7 @@
<file url="file://$PROJECT_DIR$/api-passenger/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/api-passenger/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/internal-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/internal-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/service-verificationcode/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />

@ -28,11 +28,17 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- <dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.kaiupup</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
@ -41,7 +47,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>-->
</dependency>
</dependencies>
</project>

@ -2,6 +2,8 @@ package com.kaiupup.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;
/**
* @projectName: online-taxi-public
@ -14,6 +16,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ApiPassengerApplication {
public static void main(String[] args) {

@ -0,0 +1,35 @@
package com.kaiupup.apipassenger.controller;
import com.kaiupup.apipassenger.service.VerificationCodeService;
import com.kaiupup.internalcommon.dto.ResponseResult;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @projectName: online-taxi-public
* @package: com.kaiupup.apipassenger.controller
* @className: VerificationCodeController
* @author: kaiupup
* @description: TODO
* @date: 2023/7/26 20:42
* @version: 1.0
*/
@RestController
@RequestMapping("/api")
public class VerificationCodeController {
@Autowired
private VerificationCodeService verificationCodeService;
@GetMapping("numberCode/{size}")
public ResponseResult getNumberCode(@PathVariable("size") int size){
ResponseResult responseResult = verificationCodeService.numberCode(size);
return responseResult;
}
}

@ -0,0 +1,15 @@
package com.kaiupup.apipassenger.remote;
import com.kaiupup.internalcommon.dto.ResponseResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@FeignClient("service-verificationcode")
public interface ServiceVerificationCodeClient {
@RequestMapping("/numberCode/{size}")
ResponseResult numberCode(@PathVariable("size") int size);
}

@ -0,0 +1,29 @@
package com.kaiupup.apipassenger.service;
import com.kaiupup.apipassenger.remote.ServiceVerificationCodeClient;
import com.kaiupup.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @projectName: online-taxi-public
* @package: com.kaiupup.apipassenger.service
* @className: VerificationCodeService
* @author: kaiupup
* @description: TODO
* @date: 2023/7/26 20:39
* @version: 1.0
*/
@Service
public class VerificationCodeService {
@Autowired
private ServiceVerificationCodeClient serviceVerificationCodeClient;
public ResponseResult numberCode(int size){
ResponseResult responseResult = serviceVerificationCodeClient.numberCode(size);
System.out.println("responseResult = " + responseResult);
return responseResult;
}
}

@ -1,3 +0,0 @@
artifactId=api-passenger
groupId=com.kaiupup
version=1.0-SNAPSHOT

@ -1,2 +0,0 @@
com/kaiupup/ApiPassengerApplication.class
com/kaiupup/controller/TestController.class

@ -1,2 +0,0 @@
/Users/zhaokai/Desktop/study/java/code/online-taxi/online-taxi-public/api-passenger/src/main/java/com/kaiupup/controller/TestController.java
/Users/zhaokai/Desktop/study/java/code/online-taxi/online-taxi-public/api-passenger/src/main/java/com/kaiupup/ApiPassengerApplication.java

@ -2,27 +2,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kaiupup</groupId>
<artifactId>online-taxi-public</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.kaiupup</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
@ -35,7 +35,6 @@
<version>2.12.0</version>
</dependency>
</dependencies>

@ -0,0 +1,20 @@
package com.kaiupup.internalcommon.response;
import lombok.Data;
/**
* @projectName: online-taxi-public
* @package: com.kaiupup.internalcommon.response
* @className: NumberCodeResponse
* @author: kaiupup
* @description: TODO
* @date: 2023/7/26 07:54
* @version: 1.0
*/
@Data
public class NumberCodeResponse {
private int numberCode;
}

@ -11,12 +11,6 @@
<artifactId>service-verificationcode</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -35,6 +29,11 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.kaiupup</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

@ -1,8 +1,11 @@
package com.kaiupup.serviceverificationcode.controller;
import com.kaiupup.internalcommon.dto.ResponseResult;
import com.kaiupup.internalcommon.response.NumberCodeResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
@ -16,12 +19,30 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("/numberCode")
@Slf4j
public class NumberCodeController {
@GetMapping("/numberCode/{size}")
@GetMapping("/{size}")
public ResponseResult numberCode(@PathVariable("size") int size){
return null;
log.info("进入生成验证码方法体,参数:{}",size);
double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10, size - 1));
log.info("生成的验证码::{}",mathRandom);
int result = (int) mathRandom;
log.info("生成的验证码(int)::{}",result);
NumberCodeResponse response = new NumberCodeResponse();
response.setNumberCode(result);
log.info("进入生成验证码完成,返回值:,{}",response);
return ResponseResult.success(response);
}
}

Loading…
Cancel
Save