package com.njcn.auth.utils; import cn.hutool.core.util.RandomUtil; import okhttp3.*; import java.io.IOException; 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 textList = Arrays.asList(code.toString().split("")); //填充完字符后,打乱顺序,返回字符串 Collections.shuffle(textList); return String.join("", textList); } }