Files
pqs/pqs-auth/src/main/java/com/njcn/auth/utils/AuthPubUtil.java
chendaofei 59b56a39dc 1.用能代码提交
2.系统并发bug修改
2024-07-29 13:56:28 +08:00

44 lines
1.4 KiB
Java

package com.njcn.auth.utils;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.nimbusds.jose.JWSObject;
import com.njcn.common.pojo.constant.SecurityConstants;
import lombok.SneakyThrows;
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);
}
@SneakyThrows
public static JSONObject getLoginByToken(String token){
JWSObject jwsObject = JWSObject.parse(token);
String payload = jwsObject.getPayload().toString();
JSONObject jsonObject = JSONUtil.parseObj(payload);
return jsonObject;
}
}