1
lrh3321 2016-10-14 14:08:56 +08:00
|
3
sutra 2016-10-14 14:22:05 +08:00
不带这样伸手的吧。
|
5
lrh3321 2016-10-14 14:28:08 +08:00
我尽力了
var aaa =ClassA.yeast(); ```csharp static class ClassA { static char[] alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".ToCharArray(); static int length = 64, seed = 0, i = 0; static string prev = null; public static string encode(long num) { var encoded = ""; do { encoded = alphabet[num % length] + encoded; num = (int)(num / length) ; } while (num > 0); return encoded; } /// <summary> /// 获取时间戳 /// </summary> /// <returns></returns> public static long GetTimeStamp() { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); return (long)ts.TotalMilliseconds; } public static string yeast() { var now = encode(GetTimeStamp()); if (now != prev){ seed = 0; return prev = now; } return now + "." + encode(seed++); } } ``` |
6
sutra 2016-10-14 14:29:08 +08:00
var aaa = Convert.ToBase64String(DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
|
9
lrh3321 2016-10-14 14:46:04 +08:00 1
num = (int)(num / length) ;
改成 num = (long)(num / length) ; 用长整型应该更保险一点 |
10
pyengwoei OP @lrh3321 好的我再试试,我刚刚试了 正确得出的是一个五位数的字符 LV1JPJk 但是用 C#得出的是 1V1_ZP2 开头还对不太起来好像就是 encoded = alphabet[num % length] + encoded; 这里有点问题,不过其他地方应该都没什么问题了,这里我再试试
|
13
SoloCompany 2016-10-14 23:30:34 +08:00
base64 和 64 进制有区别吗?不就是 base64 换了两个特殊字符吗
|