package org.yeshi.utils.sms;
|
|
/**
|
* @author hxh
|
* @title: VerifyCodeFactory
|
* @description: 验证码工厂
|
* @date 2021/11/15 18:47
|
*/
|
public class VerifyCodeFactory {
|
|
final static String NUMBERS = "0123456789";
|
|
final static String NUMBERS_UPPER_CASE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
final static String UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
final static String NUMBERS_LOWER_CASE = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
final static String LOWER_CASE = "abcdefghijklmnopqrstuvwxyz";
|
|
/**
|
* @return java.lang.String
|
* @author hxh
|
* @description 纯数字验证码
|
* @date 18:56 2021/11/15
|
* @param: length
|
**/
|
public static String createNumber(int length) {
|
|
return createCode(length, NUMBERS);
|
}
|
|
/**
|
* @return java.lang.String
|
* @author hxh
|
* @description 数字大写字母混合验证码
|
* @date 18:56 2021/11/15
|
* @param: length
|
**/
|
public static String createNumberAndUpperCase(int length) {
|
|
return createCode(length, NUMBERS_UPPER_CASE);
|
}
|
|
/**
|
* @return java.lang.String
|
* @author hxh
|
* @description 数字小写字母混合验证码
|
* @date 18:56 2021/11/15
|
* @param: length
|
**/
|
public static String createNumberAndLowerCase(int length) {
|
|
return createCode(length, NUMBERS_LOWER_CASE);
|
}
|
|
|
/**
|
* @return java.lang.String
|
* @author hxh
|
* @description 纯大写字母混合验证码
|
* @date 18:56 2021/11/15
|
* @param: length
|
**/
|
public static String createUpperCase(int length) {
|
|
return createCode(length, UPPER_CASE);
|
}
|
|
/**
|
* @return java.lang.String
|
* @author hxh
|
* @description 纯小写字母混合验证码
|
* @date 18:56 2021/11/15
|
* @param: length
|
**/
|
public static String createLowerCase(int length) {
|
|
return createCode(length, LOWER_CASE);
|
}
|
|
private static String createCode(int length, String source) {
|
StringBuffer buffer = new StringBuffer();
|
for (int i = 0; i < length; i++) {
|
buffer.append(source.charAt((int) (Math.random() * source.length())));
|
}
|
return buffer.toString();
|
|
}
|
|
|
}
|