添加项目文件。

This commit is contained in:
2025-12-02 13:10:10 +08:00
parent 93a2382a16
commit 289aa4cbe7
400 changed files with 91177 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
using System.Text;
namespace Atomx.Utils.Extension
{
public static class IdCodeExtension
{
private static readonly char[] Base62Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray();
/// <summary>
/// 将long类型ID编码为10位Base62邀请码
/// </summary>
public static string IdToCode(this long id)
{
ulong value = (ulong)id;
var sb = new StringBuilder();
for (int i = 0; i < 10; i++)
{
sb.Insert(0, Base62Chars[(int)(value % 62)]);
value /= 62;
}
return sb.ToString();
}
/// <summary>
/// 将10位Base62邀请码还原为long类型ID
/// </summary>
public static long CodeToId(this string code)
{
ulong value = 0;
foreach (var c in code)
{
value = value * 62 + (ulong)Array.IndexOf(Base62Chars, c);
}
return (long)value;
}
}
}