2022-06-21 20:47:46 +08:00
|
|
|
package com.njcn.auth.utils;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
2023-07-26 11:20:12 +08:00
|
|
|
import okhttp3.*;
|
2022-06-21 20:47:46 +08:00
|
|
|
|
2023-07-26 11:20:12 +08:00
|
|
|
import java.io.IOException;
|
2022-06-21 20:47:46 +08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|