初始化
This commit is contained in:
29
pqs-auth/src/main/java/com/njcn/auth/utils/AuthPubUtil.java
Normal file
29
pqs-auth/src/main/java/com/njcn/auth/utils/AuthPubUtil.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.njcn.auth.utils;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年06月04日 14:00
|
||||
*/
|
||||
public class AuthPubUtil {
|
||||
|
||||
public static String getKaptchaText(int codeLength) {
|
||||
StringBuilder code = new StringBuilder();
|
||||
int letterLength = RandomUtil.randomInt(codeLength - 1) + 1;
|
||||
code.append(RandomUtil.randomString(RandomUtil.BASE_CHAR, letterLength).toUpperCase(Locale.ROOT));
|
||||
int numberLength = codeLength - letterLength;
|
||||
code.append(RandomUtil.randomString(RandomUtil.BASE_NUMBER, numberLength));
|
||||
List<String> textList = Arrays.asList(code.toString().split(""));
|
||||
//填充完字符后,打乱顺序,返回字符串
|
||||
Collections.shuffle(textList);
|
||||
return String.join("", textList);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user