懒得勤快 7 years ago
parent
commit
de02fab7f4

+ 7 - 9
Masuit.Tools.Core/Extensions.cs

@@ -3,8 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
-using Masuit.Tools.Security;
-using Masuit.Tools.Win32;
 using Newtonsoft.Json;
 
 namespace Masuit.Tools
@@ -1533,18 +1531,18 @@ namespace Masuit.Tools
         /// 生成唯一短字符串
         /// </summary>
         /// <param name="str"></param>
-        /// <param name="length">生成的字符串长度,越长冲突的概率越小,默认长度为10,最小长度为9,最大长度为32</param>
+        /// <param name="length">生成的字符串长度,越长冲突的概率越小,默认长度为6,最小长度为5,最大长度为22</param>
         /// <returns></returns>
-        public static string CreateShortToken(this string str, int length = 10)
+        public static string CreateShortToken(this string str, int length = 6)
         {
-            string temp = Guid.NewGuid().ToString("N").MDString();
-            if (length <= 32)
+            var temp = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Trim('=');
+            if (length <= 22)
             {
-                if (length < 9)
+                if (length < 5)
                 {
-                    length = 9;
+                    length = 5;
                 }
-                temp = temp.Substring(new Random().StrictNext(32 - length), length);
+                temp = temp.Substring(0, length);
             }
             return temp;
         }

+ 1 - 1
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netcoreapp2.0</TargetFramework>
-    <Version>1.9.7.1</Version>
+    <Version>1.9.7.2</Version>
     <Authors>懒得勤快</Authors>
     <Company>masuit.com</Company>
     <Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。

+ 7 - 9
Masuit.Tools/Extensions.cs

@@ -3,8 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
-using Masuit.Tools.Security;
-using Masuit.Tools.Win32;
 using Newtonsoft.Json;
 
 namespace Masuit.Tools
@@ -1488,18 +1486,18 @@ namespace Masuit.Tools
         /// 生成唯一短字符串
         /// </summary>
         /// <param name="str"></param>
-        /// <param name="length">生成的字符串长度,越长冲突的概率越小,默认长度为10,最小长度为9,最大长度为32</param>
+        /// <param name="length">生成的字符串长度,越长冲突的概率越小,默认长度为6,最小长度为5,最大长度为22</param>
         /// <returns></returns>
-        public static string CreateShortToken(this string str, int length = 10)
+        public static string CreateShortToken(this string str, int length = 6)
         {
-            string temp = Guid.NewGuid().ToString("N").MDString();
-            if (length <= 32)
+            var temp = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Trim('=');
+            if (length <= 22)
             {
-                if (length < 9)
+                if (length < 5)
                 {
-                    length = 9;
+                    length = 5;
                 }
-                temp = temp.Substring(new Random().StrictNext(32 - length), length);
+                temp = temp.Substring(0, length);
             }
             return temp;
         }

+ 2 - 2
Masuit.Tools/Properties/AssemblyInfo.cs

@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
 // 方法是按如下所示使用“*”: :
 // [assembly: AssemblyVersion("1.0.*")]
 
-[assembly: AssemblyVersion("1.9.7.3")]
-[assembly: AssemblyFileVersion("1.9.7.3")]
+[assembly: AssemblyVersion("1.9.7.4")]
+[assembly: AssemblyFileVersion("1.9.7.4")]
 [assembly: NeutralResourcesLanguage("zh-CN")]
 

+ 9 - 7
Test/Program.cs

@@ -1,8 +1,8 @@
 using System;
 using System.Collections.Concurrent;
-using System.Net.Http;
-using System.Net.Http.Headers;
+using System.Collections.Generic;
 using System.Threading.Tasks;
+using Masuit.Tools;
 
 namespace Test
 {
@@ -10,11 +10,13 @@ namespace Test
     {
         static void Main(string[] args)
         {
-            var httpClient = new HttpClient() { BaseAddress = new Uri("http://www.hbtswl.com") };
-            httpClient.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("Mozilla/5.0"));
-            var res = httpClient.GetAsync("/").Result;
-            var statusCode = res.StatusCode;
-            Console.WriteLine(statusCode);
+            var dic = new Dictionary<string, string>();
+            for (int i = 0; i < 1000000; i++)
+            {
+                var token = "".CreateShortToken(22);
+                dic.Add(token, token);
+                Console.WriteLine(token);
+            }
         }
 
         public static ConcurrentDictionary<string, object> LockDic { get; set; } = new ConcurrentDictionary<string, object>();