mcwl-ai/mcwl-common/src/main/java/com/mcwl/common/utils/CodeUtils.java

30 lines
653 B
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.mcwl.common.utils;
import java.util.Random;
/**
* 验证码工具类
*
* @author DaiZibo
* @date 2024/12/28
* @apiNote
*/
public class CodeUtils {
/**
* 生成一个随机的4位数验证码
*
* @return 返回生成的验证码字符串
*/
public static String generateCaptcha() {
// 创建Random对象用于生成随机数
Random random = new Random();
// 生成100000到999999之间的随机整数包括100000和999999
int captcha = 100000 + random.nextInt(900000);
// 将整数转换为字符串并返回
return String.valueOf(captcha);
}
}