From 68a3ca165701bd2524f7664e4fc9ec7e1952b6c3 Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 00:41:50 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=88=B0=20Preview2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Senparc.Weixin.MP.CoreSample.csproj | 6 +++--- .../Senparc.Weixin.MP.CoreSample.CommonService.csproj | 2 +- .../Senparc.Weixin.MP.MvcExtension.vs2017.csproj | 4 ++-- .../Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj | 6 +++--- .../Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj | 4 ++-- .../Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj | 4 ++-- .../Senparc.Weixin.WxOpen.vs2017.csproj | 4 ++-- .../Senparc.Weixin/Senparc.Weixin.vs2017.csproj | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj index 25e2f0565c..e6a391cbfa 100644 --- a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj +++ b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj @@ -5,7 +5,7 @@ AspNetCoreModule - 3.3.3 + 3.3.4 false Linux @@ -18,8 +18,8 @@ - - + + diff --git a/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj b/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj index a968b84255..e28cea03fe 100644 --- a/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj +++ b/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj b/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj index 4e9e7b6143..c0675a4a1c 100644 --- a/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj +++ b/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj @@ -2,7 +2,7 @@ net45;netstandard2.0 - 7.2.8.2-preview1 + 7.2.8-preview2 Senparc.Weixin.MP.MvcExtension Senparc.Weixin.MP.MvcExtension true @@ -159,7 +159,7 @@ - + diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj index 1314ed3ee8..70a658b17b 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj @@ -2,7 +2,7 @@ net45;netstandard2.0 - 16.7.0.2-preview1 + 16.7.0-preview2 Senparc.Weixin.MP Senparc.Weixin.MP true @@ -547,8 +547,8 @@ - - + + diff --git a/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj b/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj index dacecb7239..20e97607a4 100644 --- a/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj +++ b/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj @@ -2,7 +2,7 @@ net45;netstandard2.0 - 4.5.0.2-preview1 + 4.5.0-preview2 Senparc.Weixin.Open Senparc.Weixin.Open true @@ -210,7 +210,7 @@ - + diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj index 78576eda42..77f9464e97 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj @@ -3,7 +3,7 @@ net45;netstandard2.0 $(Net35FrameworkPathOverride) - 3.5.0.2-preview1 + 3.5.0-preview2 Senparc.Weixin.Work Senparc.Weixin.Work true @@ -224,7 +224,7 @@ - + diff --git a/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj b/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj index f30c340ac1..0a39c41979 100644 --- a/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj +++ b/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj @@ -2,7 +2,7 @@ net45;netstandard2.0 - 3.4.0.2-preview1 + 3.4.0-preview2 Senparc.Weixin.WxOpen Senparc.Weixin.WxOpen true @@ -185,7 +185,7 @@ - + diff --git a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj index 4b082960d4..61d6ef13cd 100644 --- a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj +++ b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj @@ -3,7 +3,7 @@ net45;netstandard2.0 $(Net35FrameworkPathOverride) - 6.4.0.2-preview1 + 6.4.0-preview2 Senparc.Weixin Senparc.Weixin true @@ -354,8 +354,8 @@ - - + + From 71ce80ce848deec5a20f357d80d1e394b4450435 Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 01:11:08 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=B9=8B=E5=90=8E=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=20?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=8F=91=E7=8E=B0=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E7=9A=84=E9=97=AE=E9=A2=98=20#1693=20https:/?= =?UTF-8?q?/github.com/JeffreySu/WeiXinMPSDK/issues/1693#issuecomment-4873?= =?UTF-8?q?83269?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdvancedAPIs/AsyncTest.cs | 74 ++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs index a27c138af8..30e551a9f0 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs @@ -4,6 +4,10 @@ using System.Threading.Tasks; using Senparc.Weixin.MP.Test.CommonAPIs; using System.Threading; +using System.Collections.Generic; +using Senparc.CO2NET.Extensions; +using Senparc.CO2NET.Cache; +using Senparc.CO2NET.Cache.Redis; namespace Senparc.Weixin.MP.Test.AdvancedAPIs { @@ -17,13 +21,14 @@ public void TestMethod1() Console.WriteLine("1. Start"); bool finished = false; - Thread thread = new Thread(()=> { + Thread thread = new Thread(() => + { Task.Factory.StartNew(async () => { var d2 = SystemTime.Now; var tagJsonResult = await Senparc.Weixin.MP.AdvancedAPIs.UserTagApi.GetAsync(base._appId); Console.WriteLine("3. tagJsonResult 1:" + string.Join(",", tagJsonResult.tags.Select(z => z.name))); - Console.WriteLine("4. 用时:" + (SystemTime.Now-d2).TotalMilliseconds+" ms"); + Console.WriteLine("4. 用时:" + (SystemTime.Now - d2).TotalMilliseconds + " ms"); return tagJsonResult; }).ContinueWith(async task => @@ -45,7 +50,70 @@ public void TestMethod1() Thread.Sleep(5); } - Console.WriteLine("6. End:"+(SystemTime.Now -d1).TotalMilliseconds+" ms"); + Console.WriteLine("6. End:" + (SystemTime.Now - d1).TotalMilliseconds + " ms"); + + } + + /// + /// 并发测试 + /// + [TestMethod] + public void ConcurrentTesting() + { + var threadCount = 30;//同时运行线程数 + var finishedCount = 0; + var threads = new List(); + + var apiTotalTime = 0D;//接口总耗时 + + //指定缓存 + Senparc.Weixin.Cache.Redis.Register.RegisterDomainCache();//注册领域缓存 + CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance); + + var cacheStrategy = CacheStrategyFactory.GetObjectCacheStrategyInstance(); + Console.WriteLine($"== 开始,缓存:{cacheStrategy.GetType()} =="); + + for (int i = 0; i < threadCount; i++) + { + var index = i; + var thread = new Thread(async () => + { + try + { + var dt0 = SystemTime.Now; + Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{Thread.CurrentThread.Name} START"); + var result = await MP.AdvancedAPIs.QrCodeApi.CreateAsync(base._appId, 300, 100000 * 10 + index, QrCode_ActionName.QR_SCENE); + var apiRunTime = (SystemTime.Now - dt0).TotalMilliseconds; + Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{Thread.CurrentThread.Name} RESULT - 耗时 {apiRunTime:###,###}ms - {result.ticket} - {result.url}"); + apiTotalTime += apiRunTime; + } + catch (Exception ex) + { + Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{ex.ToString()}"); + } + finally + { + finishedCount++; + } + }); + thread.Name = "T" + index.ToString("00"); + + threads.Add(thread); + } + + var dt1 = SystemTime.Now; + foreach (var thread in threads) + { + thread.Start();//尽量在相近的时间开始 + } + + while (finishedCount < threadCount) + { + //等待线程结束(为测试避免线程锁死,这里不使用信号灯) + } + + var costTime = (SystemTime.Now - dt1).TotalMilliseconds; + Console.WriteLine($"== 运行结束,总耗时 {costTime:###,###}ms,平均 {apiTotalTime / threadCount:###,###}ms =="); } } From fc218ea5d0b08e98ee45021ea46ea654e0a1be8d Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 21:32:07 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs index 30e551a9f0..00f7c58e58 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs @@ -8,6 +8,7 @@ using Senparc.CO2NET.Extensions; using Senparc.CO2NET.Cache; using Senparc.CO2NET.Cache.Redis; +using Senparc.Weixin.MP.Containers; namespace Senparc.Weixin.MP.Test.AdvancedAPIs { @@ -60,7 +61,7 @@ public void TestMethod1() [TestMethod] public void ConcurrentTesting() { - var threadCount = 30;//同时运行线程数 + var threadCount = 100;//同时运行线程数 var finishedCount = 0; var threads = new List(); @@ -73,6 +74,9 @@ public void ConcurrentTesting() var cacheStrategy = CacheStrategyFactory.GetObjectCacheStrategyInstance(); Console.WriteLine($"== 开始,缓存:{cacheStrategy.GetType()} =="); + //先获取一次AccessToken(避免并发过程中获取) ——无效 + var accessToken = AccessTokenContainer.GetAccessTokenResult(base._appId).access_token; + for (int i = 0; i < threadCount; i++) { var index = i; @@ -84,7 +88,7 @@ public void ConcurrentTesting() Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{Thread.CurrentThread.Name} START"); var result = await MP.AdvancedAPIs.QrCodeApi.CreateAsync(base._appId, 300, 100000 * 10 + index, QrCode_ActionName.QR_SCENE); var apiRunTime = (SystemTime.Now - dt0).TotalMilliseconds; - Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{Thread.CurrentThread.Name} RESULT - 耗时 {apiRunTime:###,###}ms - {result.ticket} - {result.url}"); + Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{Thread.CurrentThread.Name} RESULT - 耗时 {apiRunTime:###,###}ms - {result.url}"); apiTotalTime += apiRunTime; } catch (Exception ex) @@ -105,6 +109,7 @@ public void ConcurrentTesting() foreach (var thread in threads) { thread.Start();//尽量在相近的时间开始 + //Thread.Sleep(500);//TODO:如果Sleep,则可以快速完成(没有阻塞) } while (finishedCount < threadCount) From ba8d286316ae1a4df951f0824366fcd8f40e458e Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 21:32:41 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=9B=B4=E6=96=B0Demo=20v3.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Senparc.Weixin.MP.CoreSample.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj index e6a391cbfa..15772fc29d 100644 --- a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj +++ b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj @@ -5,7 +5,7 @@ AspNetCoreModule - 3.3.4 + 3.4.0 false Linux @@ -18,7 +18,7 @@ - + From 72feb2a3633f6b1e08ae4e226c92cac8315de987 Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 21:34:23 +0800 Subject: [PATCH 05/11] =?UTF-8?q?v6.4.0=20=E9=87=8D=E6=9E=84=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=20ApiHandlerWapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiHandlerWapper/ApiHandlerWapperBase.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Senparc.Weixin/Senparc.Weixin/CommonAPIs/ApiHandlerWapper/ApiHandlerWapperBase.cs b/src/Senparc.Weixin/Senparc.Weixin/CommonAPIs/ApiHandlerWapper/ApiHandlerWapperBase.cs index bd9d322c56..971192fb65 100644 --- a/src/Senparc.Weixin/Senparc.Weixin/CommonAPIs/ApiHandlerWapper/ApiHandlerWapperBase.cs +++ b/src/Senparc.Weixin/Senparc.Weixin/CommonAPIs/ApiHandlerWapper/ApiHandlerWapperBase.cs @@ -36,6 +36,10 @@ and limitations under the License. 修改标识:Senparc - 20181027 修改描述:v6.1.10 改进 TryCommonApiBase 方法 + + 修改标识:Senparc - 20190429 + 修改描述:v6.4.0 重构异步 ApiHandlerWapper + ----------------------------------------------------------------*/ using System; using System.Collections.Generic; @@ -168,8 +172,8 @@ public static T TryCommonApiBase( /// /// /// 平台类型,PlatformType枚举 - /// AccessTokenContainer中的GetFirstOrDefaultAppId()方法 - /// AccessTokenContainer中的bool CheckRegistered(appId,getNew)方法 + /// AccessTokenContainer中的GetFirstOrDefaultAppId()方法 + /// AccessTokenContainer中的bool CheckRegistered(appId,getNew)方法 /// AccessTokenContainer中的AccessTokenResult GetAccessTokenResultAsync(appId)方法(异步方法) /// "ReturnCode.获取access_token时AppSecret错误或者access_token无效"枚举的值 /// @@ -178,8 +182,8 @@ public static T TryCommonApiBase( /// public static async Task TryCommonApiBaseAsync( PlatformType platformType, - Func accessTokenContainer_GetFirstOrDefaultAppIdFunc, - Func accessTokenContainer_CheckRegisteredFunc, + Func> accessTokenContainer_GetFirstOrDefaultAppIdAsyncFunc, + Func> accessTokenContainer_CheckRegisteredAsyncFunc, Func> accessTokenContainer_GetAccessTokenResultAsyncFunc, int invalidCredentialValue, Func> fun, string accessTokenOrAppId = null, bool retryIfFaild = true) where T : BaseJsonResult @@ -194,7 +198,7 @@ public static async Task TryCommonApiBaseAsync( if (accessTokenOrAppId == null) { - appId = accessTokenContainer_GetFirstOrDefaultAppIdFunc();// AccessTokenContainer.GetFirstOrDefaultAppId(); + appId = await accessTokenContainer_GetFirstOrDefaultAppIdAsyncFunc();// AccessTokenContainer.GetFirstOrDefaultAppId(); if (appId == null) { throw new UnRegisterAppIdException(null, @@ -204,7 +208,7 @@ public static async Task TryCommonApiBaseAsync( else if (ApiUtility.IsAppId(accessTokenOrAppId, platformType)) { //if (!AccessTokenContainer.CheckRegistered(accessTokenOrAppId)) - if (!accessTokenContainer_CheckRegisteredFunc(accessTokenOrAppId)) + if (!await accessTokenContainer_CheckRegisteredAsyncFunc(accessTokenOrAppId)) { throw new UnRegisterAppIdException(accessTokenOrAppId, string.Format("此appId({0})尚未注册,请先使用AccessTokenContainer.Register完成注册(全局执行一次即可)!", @@ -243,8 +247,8 @@ public static async Task TryCommonApiBaseAsync( accessToken = accessTokenResult.access_token; result = await TryCommonApiBaseAsync(platformType, - accessTokenContainer_GetFirstOrDefaultAppIdFunc, - accessTokenContainer_CheckRegisteredFunc, + accessTokenContainer_GetFirstOrDefaultAppIdAsyncFunc, + accessTokenContainer_CheckRegisteredAsyncFunc, accessTokenContainer_GetAccessTokenResultAsyncFunc, invalidCredentialValue, fun, appId, false); From b69172a8593d265e66d31f8b64ac8cc706aac55c Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 21:35:31 +0800 Subject: [PATCH 06/11] =?UTF-8?q?v6.4.1=20=E9=87=8D=E6=9E=84=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=20ApiHandlerWapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Senparc.Weixin/Senparc.Weixin.vs2017.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj index 61d6ef13cd..f8f41e23b4 100644 --- a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj +++ b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj @@ -3,7 +3,7 @@ net45;netstandard2.0 $(Net35FrameworkPathOverride) - 6.4.0-preview2 + 6.4.1-preview3 Senparc.Weixin Senparc.Weixin true @@ -354,7 +354,7 @@ - + From 7ca15d2869b4df0ab30f759e0ab47b9ad7b72e52 Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 21:36:32 +0800 Subject: [PATCH 07/11] =?UTF-8?q?Work=20v3.5.1=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=20ApiHandlerWapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommonAPIs/ApiHandlerWapper.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/ApiHandlerWapper.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/ApiHandlerWapper.cs index f7077178dc..cbca748a8e 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/ApiHandlerWapper.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/ApiHandlerWapper.cs @@ -34,14 +34,17 @@ and limitations under the License. 修改描述:添加TryCommonApi()方法 修改标识:Senparc - 20170102 - 修改描述:v14.3.116 TryCommonApi抛出ErrorJsonResultException、WeixinException异常时加入了accessTokenOrAppId参数 + 修改描述:MP v14.3.116 TryCommonApi抛出ErrorJsonResultException、WeixinException异常时加入了accessTokenOrAppId参数 修改标识:Senparc - 20170123 - 修改描述:v14.3.121 TryCommonApiAsync方法返回代码改为return await result;避免死锁。 + 修改描述:MP v14.3.121 TryCommonApiAsync方法返回代码改为return await result;避免死锁。 修改标识:Senparc - 20180917 修改描述:BaseContainer.GetFirstOrDefaultAppId() 方法添加 PlatformType 属性 + 修改标识:Senparc - 20190429 + 修改描述:v3.5.1 重构异步 ApiHandlerWapper + ----------------------------------------------------------------*/ using System; @@ -124,16 +127,16 @@ public static T TryCommonApi(Func fun, string accessTokenOrAppKey, /// public static async Task TryCommonApiAsync(Func> fun, string accessTokenOrAppKey, bool retryIfFaild = true) where T : WorkJsonResult { - Func accessTokenContainer_GetFirstOrDefaultAppIdFunc = - () => AccessTokenContainer.GetFirstOrDefaultAppId(PlatformType.Work); + Func> accessTokenContainer_GetFirstOrDefaultAppIdAsyncFunc = + async () => await AccessTokenContainer.GetFirstOrDefaultAppIdAsync(PlatformType.Work); - Func accessTokenContainer_CheckRegisteredFunc = - appKey => + Func> accessTokenContainer_CheckRegisteredAsyncFunc = + async appKey => { /* * 对于企业微信来说,AppId = key = CorpId+'@'+CorpSecret */ - return AccessTokenContainer.CheckRegistered(appKey); + return await AccessTokenContainer.CheckRegisteredAsync(appKey); }; Func> accessTokenContainer_GetAccessTokenResultAsyncFunc = @@ -150,8 +153,8 @@ public static async Task TryCommonApiAsync(Func> fun, stri var result = ApiHandlerWapperBase. TryCommonApiBaseAsync( PlatformType.Work, - accessTokenContainer_GetFirstOrDefaultAppIdFunc, - accessTokenContainer_CheckRegisteredFunc, + accessTokenContainer_GetFirstOrDefaultAppIdAsyncFunc, + accessTokenContainer_CheckRegisteredAsyncFunc, accessTokenContainer_GetAccessTokenResultAsyncFunc, invalidCredentialValue, fun, accessTokenOrAppKey, retryIfFaild); From 4358aad6066d82e3142ada2b37bee8cb2c2046c1 Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 21:37:18 +0800 Subject: [PATCH 08/11] =?UTF-8?q?MP=20v16.7.1=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=20ApiHandlerWapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommonAPIs/ApiHandlerWapper.cs | 16 +++++++++------- .../Senparc.Weixin.MP.vs2017.csproj | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/CommonAPIs/ApiHandlerWapper.cs b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/CommonAPIs/ApiHandlerWapper.cs index 159c8de5b1..0538361a4a 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/CommonAPIs/ApiHandlerWapper.cs +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/CommonAPIs/ApiHandlerWapper.cs @@ -41,7 +41,9 @@ and limitations under the License. 修改标识:Senparc - 20180917 修改描述:BaseContainer.GetFirstOrDefaultAppId() 方法添加 PlatformType 属性 - + + 修改标识:Senparc - 20190429 + 修改描述:v16.7.1 重构异步 ApiHandlerWapper ----------------------------------------------------------------*/ using System; @@ -219,11 +221,11 @@ public static T TryCommonApi(Func fun, string accessTokenOrAppId = /// public static async Task TryCommonApiAsync(Func> fun, string accessTokenOrAppId = null, bool retryIfFaild = true) where T : WxJsonResult { - Func accessTokenContainer_GetFirstOrDefaultAppIdFunc = - () => AccessTokenContainer.GetFirstOrDefaultAppId(PlatformType.MP); + Func> accessTokenContainer_GetFirstOrDefaultAppIdAsyncFunc = + async () => await AccessTokenContainer.GetFirstOrDefaultAppIdAsync(PlatformType.MP); - Func accessTokenContainer_CheckRegisteredFunc = - appId => AccessTokenContainer.CheckRegistered(appId); + Func> accessTokenContainer_CheckRegisteredAsyncFunc = + async appId => await AccessTokenContainer.CheckRegisteredAsync(appId); Func> accessTokenContainer_GetAccessTokenResultAsyncFunc = (appId, getNewToken) => AccessTokenContainer.GetAccessTokenResultAsync(appId, getNewToken); @@ -233,8 +235,8 @@ public static async Task TryCommonApiAsync(Func> fun, stri var result = ApiHandlerWapperBase. TryCommonApiBaseAsync( PlatformType.MP, - accessTokenContainer_GetFirstOrDefaultAppIdFunc, - accessTokenContainer_CheckRegisteredFunc, + accessTokenContainer_GetFirstOrDefaultAppIdAsyncFunc, + accessTokenContainer_CheckRegisteredAsyncFunc, accessTokenContainer_GetAccessTokenResultAsyncFunc, invalidCredentialValue, fun, accessTokenOrAppId, retryIfFaild); diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj index 70a658b17b..353470e0d2 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj @@ -2,7 +2,7 @@ net45;netstandard2.0 - 16.7.0-preview2 + 16.7.1-preview2 Senparc.Weixin.MP Senparc.Weixin.MP true From 85ea389fb3fddef4eeeb4332e90b3970198b7efc Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 21:45:41 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=AE=89=E8=A3=85=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84=20CO2NET=20=E5=8F=8A=20NeuChar=20=E5=8C=85=EF=BC=8C?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=20HttpClient=20=E5=BC=82=E6=AD=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Senparc.Weixin.MP.CoreSample.csproj | 2 +- .../Senparc.Weixin.MP.CoreSample.CommonService.csproj | 2 +- .../Senparc.Weixin.MP.MvcExtension.vs2017.csproj | 2 +- .../Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj | 2 +- .../Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj | 2 +- .../Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj | 2 +- .../Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj | 2 +- src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj index 15772fc29d..b66b19e06e 100644 --- a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj +++ b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj @@ -19,7 +19,7 @@ - + diff --git a/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj b/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj index e28cea03fe..e7da1ada2e 100644 --- a/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj +++ b/Samples/Senparc.Weixin.MP.Sample/Senparc.Weixin.MP.Sample.CommonService/Senparc.Weixin.MP.CoreSample.CommonService.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj b/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj index c0675a4a1c..d512e25fa9 100644 --- a/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj +++ b/src/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension/Senparc.Weixin.MP.MvcExtension.vs2017.csproj @@ -159,7 +159,7 @@ - + diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj index 353470e0d2..08ddf7512b 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj @@ -548,7 +548,7 @@ - + diff --git a/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj b/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj index 20e97607a4..82b8768bef 100644 --- a/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj +++ b/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Senparc.Weixin.Open.vs2017.csproj @@ -210,7 +210,7 @@ - + diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj index 77f9464e97..821d0be925 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Senparc.Weixin.Work.vs2017.csproj @@ -224,7 +224,7 @@ - + diff --git a/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj b/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj index 0a39c41979..c5a73747e8 100644 --- a/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj +++ b/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen.vs2017.csproj @@ -185,7 +185,7 @@ - + diff --git a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj index f8f41e23b4..a1a1821982 100644 --- a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj +++ b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj @@ -355,7 +355,7 @@ - + From c2869627e936b01b2d2d2fc8288772b083a584b0 Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 22:02:21 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdvancedAPIs/AsyncTest.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs index 00f7c58e58..46c1bf2082 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/AdvancedAPIs/AsyncTest.cs @@ -55,6 +55,7 @@ public void TestMethod1() } + /// /// 并发测试 /// @@ -77,6 +78,8 @@ public void ConcurrentTesting() //先获取一次AccessToken(避免并发过程中获取) ——无效 var accessToken = AccessTokenContainer.GetAccessTokenResult(base._appId).access_token; + object objLock = new object(); + for (int i = 0; i < threadCount; i++) { var index = i; @@ -85,10 +88,11 @@ public void ConcurrentTesting() try { var dt0 = SystemTime.Now; - Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{Thread.CurrentThread.Name} START"); + var threadName = Thread.CurrentThread.Name; + Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t[{threadName}] START"); var result = await MP.AdvancedAPIs.QrCodeApi.CreateAsync(base._appId, 300, 100000 * 10 + index, QrCode_ActionName.QR_SCENE); var apiRunTime = (SystemTime.Now - dt0).TotalMilliseconds; - Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t{Thread.CurrentThread.Name} RESULT - 耗时 {apiRunTime:###,###}ms - {result.url}"); + Console.WriteLine($"{SystemTime.Now.ToString("HH:mm:ss.ffffff")}\t[{threadName}] RESULT - 耗时 {apiRunTime:###,###}ms - {result.url}"); apiTotalTime += apiRunTime; } catch (Exception ex) @@ -97,7 +101,10 @@ public void ConcurrentTesting() } finally { - finishedCount++; + lock (objLock) + { + finishedCount++; + } } }); thread.Name = "T" + index.ToString("00"); From f13843470a84a160004313e1a77a7b53c2bf271d Mon Sep 17 00:00:00 2001 From: Jeffrey Su Date: Mon, 29 Apr 2019 22:18:26 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=20CO2NET=20=E5=92=8C=20NeuChar=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=AB=98=E5=B9=B6=E5=8F=91HTTP=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=95=88=E7=8E=87=20https://github.com/JeffreySu/WeiX?= =?UTF-8?q?inMPSDK/issues/1693?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Senparc.Weixin.MP.CoreSample.csproj | 2 +- .../Senparc.Weixin.Cache.Memcached.vs2017.csproj | 2 +- .../Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj | 2 +- src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj index b66b19e06e..e2c16043d3 100644 --- a/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj +++ b/Samples/Senparc.Weixin.MP.Sample.vs2017/Senparc.Weixin.MP.CoreSample/Senparc.Weixin.MP.CoreSample.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Memcached/Senparc.Weixin.Cache.Memcached.vs2017.csproj b/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Memcached/Senparc.Weixin.Cache.Memcached.vs2017.csproj index 3926d6239d..cad489b25a 100644 --- a/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Memcached/Senparc.Weixin.Cache.Memcached.vs2017.csproj +++ b/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Memcached/Senparc.Weixin.Cache.Memcached.vs2017.csproj @@ -153,7 +153,7 @@ https://github.com/JeffreySu/WeiXinMPSDK - + diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj index 08ddf7512b..01bbe9ae8e 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP/Senparc.Weixin.MP.vs2017.csproj @@ -547,7 +547,7 @@ - + diff --git a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj index a1a1821982..ce337f76c8 100644 --- a/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj +++ b/src/Senparc.Weixin/Senparc.Weixin/Senparc.Weixin.vs2017.csproj @@ -354,7 +354,7 @@ - +