diff --git a/pluss-common-bundle/src/main/java/cn/pluss/platform/util/MD5Util.java b/pluss-common-bundle/src/main/java/cn/pluss/platform/util/MD5Util.java index 32a48cb..2d39103 100644 --- a/pluss-common-bundle/src/main/java/cn/pluss/platform/util/MD5Util.java +++ b/pluss-common-bundle/src/main/java/cn/pluss/platform/util/MD5Util.java @@ -37,6 +37,47 @@ public class MD5Util { } private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", - "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; + "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; + + /** + * MD5指纹算法 + * + * @param str + * @return + */ + public static String md5(String str) { + if (str == null) { + return null; + } + + try { + MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + messageDigest.update(str.getBytes()); + return bytesToHexString(messageDigest.digest()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + /** + * 将二进制转换成16进制 + * + * @param src + * @return + */ + public static String bytesToHexString(byte[] src) { + StringBuilder stringBuilder = new StringBuilder(""); + if (src == null || src.length <= 0) { + return null; + } + for (int i = 0; i < src.length; i++) { + int v = src[i] & 0xFF; + String hv = Integer.toHexString(v); + if (hv.length() < 2) { + stringBuilder.append(0); + } + stringBuilder.append(hv); + } + return stringBuilder.toString(); + } } diff --git a/pluss-common-bundle/src/main/java/cn/pluss/platform/util/TokenUtil.java b/pluss-common-bundle/src/main/java/cn/pluss/platform/util/TokenUtil.java new file mode 100644 index 0000000..bc34e54 --- /dev/null +++ b/pluss-common-bundle/src/main/java/cn/pluss/platform/util/TokenUtil.java @@ -0,0 +1,59 @@ +package cn.pluss.platform.util; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.Base64Utils; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.SecureRandom; +import java.util.*; + +/** + * AES加密工具类 + * + * @author ACGkaka + * @since 2021-06-18 19:11:03 + */ +public class TokenUtil { + + //APPID + private static final String APP_ID = "ZF544"; + //USERCODE + private static final String USER_CODE = "ZF544"; + //APPSECRET + private static final String APP_SECRET = "2022bsjZF544GAH"; + + /** + * 获取TOKEN值 + * @param timestamp 时间戳,13位 + * @param requestId 请求ID,自定义 + * @return + */ + private static Map getToken(String timestamp, String requestId) { + String token = ""; + String encode = ""; + SortedMap map = new TreeMap(); + map.put("appId", APP_ID); + map.put("timestamp", timestamp); + map.put("requestId", requestId); + map.put("userCode", USER_CODE); + Iterator> iterator = map.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry next = iterator.next(); + String key = next.getKey(); + Object value = next.getValue(); + token += key + value; + encode += key + "=" + value + "&"; + } + System.out.println(token); + Map finalMap = new HashMap<>(); + finalMap.put("ENCODE",encode); + System.out.println(token + APP_SECRET); + finalMap.put("TOKEN", MD5Util.md5(token + APP_SECRET)); + return finalMap; + } + +}