123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /*
- *
- *
- *
- */
- package com.szwl.model.utils;
- /**
- * 处理id
- */
- public final class AdminUtils {
- private static final Long base1 = 2452l;
- private static final Long base2 = 13l;
- private static final String prefix = "u";
- /**
- * 将id转成加密样式
- */
- public static String encrypt(boolean isPrefix , Long id) {
- id = id * base2 + base1;
- if(isPrefix){
- return prefix + id.toString();
- }else{
- return id.toString();
- }
- }
- /**
- * 解密id
- */
- public static Long decrypt(boolean isPrefix , String uid) {
- try {
- if(isPrefix){
- uid = uid.substring(1, uid.length());
- }
- Long id = Long.valueOf(uid);
- id = id - base1;
- id = id / base2;
- return id;
- } catch (Exception e) {
- return null;
- }
- }
- public static void main(String[] args) {
- System.out.println(encrypt(false, 3L));
- System.out.println(decrypt(false, "2478"));
- }
- }
|