|
@@ -20,11 +20,11 @@ public final class AdminUtils {
|
|
|
/**
|
|
|
* 将id转成加密样式
|
|
|
*/
|
|
|
- public static String encrypt(boolean isPrefix , Long id) {
|
|
|
+ public static String encrypt(boolean isPrefix, Long id) {
|
|
|
id = id * base2 + base1;
|
|
|
- if(isPrefix){
|
|
|
+ if (isPrefix) {
|
|
|
return prefix + id.toString();
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return id.toString();
|
|
|
}
|
|
|
|
|
@@ -34,16 +34,21 @@ public final class AdminUtils {
|
|
|
/**
|
|
|
* 解密id
|
|
|
*/
|
|
|
- public static Long decrypt(boolean isPrefix , String uid) {
|
|
|
+ public static Long decrypt(boolean isPrefix, String uid) {
|
|
|
try {
|
|
|
- if(isPrefix){
|
|
|
+ if (isPrefix) {
|
|
|
uid = uid.substring(1, uid.length());
|
|
|
}
|
|
|
|
|
|
Long id = Long.valueOf(uid);
|
|
|
id = id - base1;
|
|
|
- id = id / base2;
|
|
|
- return id;
|
|
|
+ long l = id % base2;
|
|
|
+ if (l == 0) {
|
|
|
+ id = id / base2;
|
|
|
+ return id;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
@@ -51,7 +56,7 @@ public final class AdminUtils {
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- System.out.println(encrypt(false, 3L));
|
|
|
- System.out.println(decrypt(false, "2478"));
|
|
|
+ System.out.println(encrypt(false, 2958L));
|
|
|
+ System.out.println(decrypt(false, "40918"));
|
|
|
}
|
|
|
}
|