package com.taoke.autopay.utils;
|
|
/**
|
* @author hxh
|
* @title: AgentAliasUtil
|
* @description: 代理标识工具
|
* @date 2024/7/24 18:21
|
*/
|
public class AgentAliasUtil {
|
|
private static final String BASE62_CHARACTERS = "ABCDEFabcdGHIJKLMqrstNO01234mnopu56789PQRSTUVWXYZefghijklvwxyz";
|
private static String toBase62(long decimalNumber) {
|
// 特殊情况:处理 0
|
if (decimalNumber == 0) {
|
return "0";
|
}
|
|
StringBuilder base62String = new StringBuilder();
|
while (decimalNumber > 0) {
|
int remainder = (int) (decimalNumber % 62);
|
base62String.append(BASE62_CHARACTERS.charAt(remainder));
|
decimalNumber /= 62;
|
}
|
|
// 由于我们是从低位到高位构建字符串,因此需要反转它
|
return base62String.reverse().toString();
|
}
|
|
|
public static String createAlias(Long agentId ){
|
return toBase62(System.currentTimeMillis()) + toBase62(agentId);
|
}
|
|
public static void main(String[] args){
|
System.out.println(createAlias(1L));
|
|
}
|
|
}
|