diff --git a/sms4j-comm/src/main/java/org/dromara/sms4j/comm/utils/SmsUtil.java b/sms4j-comm/src/main/java/org/dromara/sms4j/comm/utils/SmsUtil.java index 94d6dfca..40862249 100644 --- a/sms4j-comm/src/main/java/org/dromara/sms4j/comm/utils/SmsUtil.java +++ b/sms4j-comm/src/main/java/org/dromara/sms4j/comm/utils/SmsUtil.java @@ -1,6 +1,11 @@ package org.dromara.sms4j.comm.utils; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import java.security.NoSuchAlgorithmException; @@ -9,11 +14,13 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Random; +/** + * @author wind + */ public class SmsUtil { private SmsUtil() { } //私有构造防止实例化 - /** *
说明:生成一个指定长度的随机字符串,包含大小写英文字母和数字但不包含符号
*
@@ -22,18 +29,7 @@ public class SmsUtil {
* @author :Wind
*/
public static String getRandomString(int len) {
- String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- StringBuilder sb = new StringBuilder();
- try {
- Random random = SecureRandom.getInstanceStrong();
- for (int i = 0; i < len; i++) {
- int number = random.nextInt(62);
- sb.append(str.charAt(number));
- }
- } catch (NoSuchAlgorithmException e){
- throw new RuntimeException(e);
- }
- return sb.toString();
+ return RandomUtil.randomString(RandomUtil.BASE_CHAR_NUMBER + RandomUtil.BASE_CHAR.toUpperCase(), len);
}
/**
@@ -52,18 +48,7 @@ public class SmsUtil {
* @author :Wind
*/
public static String getRandomInt(int len) {
- String str = "0123456789";
- StringBuilder sb = new StringBuilder();
- try {
- Random random = SecureRandom.getInstanceStrong();
- for (int i = 0; i < len; i++) {
- int number = random.nextInt(10);
- sb.append(str.charAt(number));
- }
- } catch (NoSuchAlgorithmException e){
- throw new RuntimeException(e);
- }
- return sb.toString();
+ return RandomUtil.randomString(RandomUtil.BASE_NUMBER, len);
}
/**
@@ -73,7 +58,7 @@ public class SmsUtil {
* @author :Wind
*/
public static boolean isEmpty(Object str) {
- return str == null || "".equals(str);
+ return ObjectUtil.isEmpty(str);
}
/**
@@ -93,16 +78,7 @@ public class SmsUtil {
* @author :Wind
*/
public static String listToString(List