Merge branch 'dev' into 'release'

Dev

See merge request wanghao/afis-recall!7
This commit is contained in:
wanghao
2023-05-25 07:30:54 +00:00
3 changed files with 20 additions and 14 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.wabestway.recall</groupId>
<artifactId>afis-recall-api</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0</version>
<properties>
+1 -1
View File
@@ -33,7 +33,7 @@
<dependency>
<groupId>com.wabestway.recall</groupId>
<artifactId>afis-recall-api</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.wabestway.recall</groupId>
@@ -1,19 +1,24 @@
package com.wabestway.recall.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.UUID;
public class ShortAppKeyGenerator {
private static final char[] BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
public static String generate() {
UUID uuid = UUID.randomUUID();
long mostSigBits = uuid.getMostSignificantBits();
long leastSigBits = uuid.getLeastSignificantBits();
byte[] bytes = new byte[16];
for (int i = 0; i < 8; i++) {
bytes[i] = (byte) (mostSigBits >>> (8 * (7 - i)));
bytes[i + 8] = (byte) (leastSigBits >>> (8 * (7 - i)));
String input = System.currentTimeMillis() + "";
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
byte[] bytes = md.digest(input.getBytes());
return toBase62(bytes);
}
@@ -32,12 +37,13 @@ public class ShortAppKeyGenerator {
long result = 0;
for (int i = 0; i < 8; i++) {
result <<= 8;
result |= (bytes[i] & 0xFF);
}
for (int i = 8; i < 16; i++) {
result <<= 8;
result |= (bytes[i] & 0xFF);
result |= ((long) (bytes[i] & 0xFF));
}
return result;
}
public static void main(String[] args) {
String appKey = generate();
System.out.println(appKey); // 输出:pT8bnL3ZTYqdBlUo
}
}