六位邀请码
public class InviteCodeUtils {
private static String source = "MWX8YZE9FCDG3J2RS1TU5V6KL7HQA4BNP";
public static String Create(Integer length,Long phoneNo)
{
String code = "";
while (phoneNo > 0 && code.length()<6)
{
Long mod = phoneNo%source.length();
phoneNo = (phoneNo - mod) / source.length();
code = source.split("")[Math.toIntExact(mod)] + code;
}
return addZero(code,length);
}
public static String addZero(String str, int strLength) {
int strLen = str.length();
StringBuffer sb = null;
while (strLen < strLength) {
sb = new StringBuffer();
sb.append(str).append("0");
str = sb.toString();
strLen = str.length();
}
return str;
}
}
String inviteCode = InviteCodeUtils.Create(6, Long.valueOf("手机号"));
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210313144341585.png)
八位邀请码
String inviteCode = Integer.toHexString((int) System.currentTimeMillis());
![!在这里插入图片描述](https://img-blog.csdnimg.cn/20210313144036443.png)](https://img-blog.csdnimg.cn/20210313144059451.png)