代理商 注册

This commit is contained in:
2024-12-18 16:37:42 +08:00
parent c9242db805
commit 297c028985
3 changed files with 269 additions and 188 deletions

View File

@@ -2,85 +2,125 @@ package com.sqx.modules.utils;
/**
* 邀请码生成解密工具类
*
* @author fang
* @date 2020/7/8
*/
public class InvitationCodeUtil {
/** 自定义进制选择你想要的进制数不能重复且最好不要0、1这些容易混淆的字符 */
private static final char[] r=new char[]{ 'M', 'J', 'U', 'D', 'Z', 'X', '9', 'C', '7', 'P','E', '8', '6', 'B', 'G', 'H', 'S', '2', '5', 'F', 'R', '4','Q', 'W', 'K', '3', 'V', 'Y', 'T', 'N'};
/**
* 自定义进制选择你想要的进制数不能重复且最好不要0、1这些容易混淆的字符
*/
private static final char[] r = new char[]{'M', 'J', 'U', 'D', 'Z', 'X', '9', 'C', '7', 'P', 'E', '8', '6', 'B', 'G', 'H', 'S', '2', '5', 'F', 'R', '4', 'Q', 'W', 'K', '3', 'V', 'Y', 'T', 'N'};
/** 定义一个字符用来补全邀请码长度(该字符前面是计算出来的邀请码,后面是用来补全用的) */
private static final char b='A';
/**
* 定义一个字符用来补全邀请码长度(该字符前面是计算出来的邀请码,后面是用来补全用的)
*/
private static final char b = 'A';
/** 进制长度 */
private static final int binLen=r.length;
/**
* 进制长度
*/
private static final int binLen = r.length;
/** 邀请码长度 */
private static final int s=6;
/**
* 邀请码长度
*/
private static final int s = 6;
/** 补位字符串 */
private static final String e="KSLFXFR";
/**
* 补位字符串
*/
private static final String e = "KSLFXFR";
/**
* 代理注册 补位字符串
*/
private static final String re = "REGISTER";
/**
* 根据ID生成六位随机码
*
* @param id ID
* @return 随机码
*/
public static String toRegisteredCode(long id) {
char[] buf = new char[32];
int charPos = 32;
while ((id / binLen) > 0) {
int ind = (int) (id % binLen);
buf[--charPos] = r[ind];
id /= binLen;
}
buf[--charPos] = r[(int) (id % binLen)];
String str = new String(buf, charPos, (32 - charPos));
// 不够长度的自动补全
if (str.length() < s) {
StringBuilder sb = new StringBuilder();
sb.append(re.subSequence(0, s - str.length()));
str += sb.toString();
}
return str;
}
/**
* 根据ID生成六位随机码
*
* @param id ID
* @return 随机码
*/
public static String toSerialCode(long id) {
char[] buf=new char[32];
int charPos=32;
char[] buf = new char[32];
int charPos = 32;
while((id / binLen) > 0) {
int ind=(int)(id % binLen);
buf[--charPos]=r[ind];
while ((id / binLen) > 0) {
int ind = (int) (id % binLen);
buf[--charPos] = r[ind];
id /= binLen;
}
buf[--charPos]=r[(int)(id % binLen)];
String str=new String(buf, charPos, (32 - charPos));
buf[--charPos] = r[(int) (id % binLen)];
String str = new String(buf, charPos, (32 - charPos));
// 不够长度的自动补全
if(str.length() < s) {
StringBuilder sb=new StringBuilder();
sb.append(e.subSequence(0, s-str.length()));
str+=sb.toString();
if (str.length() < s) {
StringBuilder sb = new StringBuilder();
sb.append(e.subSequence(0, s - str.length()));
str += sb.toString();
}
return str;
}
/**
* 根据随机码生成ID
*
* @param code 随机码
* @return ID
*/
public static long codeToId(String code) {
char[] chs;
chs = code.toCharArray();
long res=0L;
for(int i=0; i < chs.length; i++) {
int ind=0;
for(int j=0; j < binLen; j++) {
if(chs[i] == r[j]) {
ind=j;
long res = 0L;
for (int i = 0; i < chs.length; i++) {
int ind = 0;
for (int j = 0; j < binLen; j++) {
if (chs[i] == r[j]) {
ind = j;
break;
}
}
if(chs[i] == b) {
if (chs[i] == b) {
break;
}
if(i > 0) {
res=res * binLen + ind;
if (i > 0) {
res = res * binLen + ind;
} else {
res=ind;
res = ind;
}
}
return res;
}
}