短信验证码生成工具,记录下
/**
* 验证码工具类
* @author nw
* @version 1.0
* @date 2021/2/21 14:16
*/
public class VerifyCodeUtils {
/**
* 生成指定长度(1~9位)数字串
* @param length 指定长度,1~9位
* @return {@link String}
*/
public static String generateCodeToString(int length) {
length = Math.min(length, 9);
length = Math.max(length, 1);
int code = (int) ((Math.random() * 9 + 1) * (int) Math.pow(10, length - 1));
return code + "";
}
}
阿里云短信服务https://gitee.com/liangcheng_old_dream/aliyun-sms-spring-boot-starter