获取验证码的逻辑

master
kezhen0805 2 years ago
parent 5445c9f346
commit 52d6e00b17

@ -23,6 +23,7 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.1</version> <version>2021.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>

@ -0,0 +1,28 @@
package com.mashibing.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* @author kezhen
* @date 2023/7/12
* @description
*/
@RestController
public class NumberCodeController {
@GetMapping("/numberCode/{size}")
public String numberCode(@PathVariable("size") int size) {
System.out.println("size = " + size);
// 获取随机数生成验证码
double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10, size - 1));
System.out.println("mathRandom = " + mathRandom);
int resultInt = (int) mathRandom;
System.out.println("resultInt = " + resultInt);
return Integer.toString(resultInt);
}
}
Loading…
Cancel
Save