From a199788e5d190012d01f3be8a5973686893a7be7 Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Mon, 30 Sep 2024 00:51:06 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=BF=81=E7=A7=BB=20Senparc.Weixin=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net8-mvc/Senparc.Weixin.Sample.Net8.sln | 2 +- .../Senparc.WeixinTests/app.config | 33 ------------------- .../Senparc.WeixinTests/BaseTest.cs | 17 ++++++++-- .../Cache.Local/Lock/LocalCacheLockTests.cs | 0 .../Cache/CacheStrategyFactoryTests.cs | 0 .../CommonApis/CommonJsonSendTests.cs | 0 .../Containers/BaseContainerTests.cs | 0 .../RequestMessageTextExtensionTests.cs | 0 .../SenparcWeixinSettingTests.cs | 0 .../TemplateMessageDataTests.cs | 2 +- .../Exceptions/CommonTests.cs | 0 .../Containers/ContainerHelperTests.cs | 0 .../Helpers/TenPay/TenPayHelperTests.cs | 0 .../MutipleCacheTestWapper.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Senparc.WeixinTests.net8.csproj | 3 +- .../Tencent/WXBizMsgCryptTests.cs | 0 .../Senparc.WeixinTests/UnitTestHelper.cs | 0 .../Utilities/HttpUtility/GetTests.cs | 0 .../Utilities/HttpUtility/PostTests.cs | 0 .../HttpUtility/RequestUtilityTests.cs | 0 .../Utilities/HttpUtility/Upload.html | 0 .../Utilities/HttpUtility/UrlUtilityTests.cs | 0 .../Senparc.WeixinTests/apiclient_key.pem | 0 .../Senparc.WeixinTests/appsettings.Test.json | 30 +++++++++++++++++ .../Senparc.WeixinTests/appsettings.json | 0 26 files changed, 49 insertions(+), 38 deletions(-) delete mode 100644 src/Senparc.Weixin.MP/Senparc.WeixinTests/app.config rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/BaseTest.cs (83%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Cache.Local/Lock/LocalCacheLockTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Cache/CacheStrategyFactoryTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/CommonApis/CommonJsonSendTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Containers/BaseContainerTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Entities/Request/Extensions/RequestMessageTextExtensionTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Entities/SenparcWeixinSetting/SenparcWeixinSettingTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Entities/TemplateMessage/TemplateMessageDataTests.cs (95%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Exceptions/CommonTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Helpers/Containers/ContainerHelperTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Helpers/TenPay/TenPayHelperTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/MutipleCacheTestWapper.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Properties/AssemblyInfo.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Senparc.WeixinTests.net8.csproj (92%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Tencent/WXBizMsgCryptTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/UnitTestHelper.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Utilities/HttpUtility/GetTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Utilities/HttpUtility/PostTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Utilities/HttpUtility/RequestUtilityTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Utilities/HttpUtility/Upload.html (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/Utilities/HttpUtility/UrlUtilityTests.cs (100%) rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/apiclient_key.pem (100%) create mode 100644 src/Senparc.Weixin/Senparc.WeixinTests/appsettings.Test.json rename src/{Senparc.Weixin.MP => Senparc.Weixin}/Senparc.WeixinTests/appsettings.json (100%) diff --git a/Samples/All/net8-mvc/Senparc.Weixin.Sample.Net8.sln b/Samples/All/net8-mvc/Senparc.Weixin.Sample.Net8.sln index ac5836d38f..51b3784bb9 100644 --- a/Samples/All/net8-mvc/Senparc.Weixin.Sample.Net8.sln +++ b/Samples/All/net8-mvc/Senparc.Weixin.Sample.Net8.sln @@ -50,7 +50,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senparc.Weixin.Work.Test.ne EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senparc.Weixin.MP.Test.net8", "..\..\..\src\Senparc.Weixin.MP\Senparc.Weixin.MP.Test\Senparc.Weixin.MP.Test.net8.csproj", "{B1165EE3-2DBB-474B-AFCA-ECAB096DAAAC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senparc.WeixinTests.net8", "..\..\..\src\Senparc.Weixin.MP\Senparc.WeixinTests\Senparc.WeixinTests.net8.csproj", "{A514FE17-476F-4D10-B28E-A7597CB93F9A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senparc.WeixinTests.net8", "..\..\..\src\Senparc.Weixin\Senparc.WeixinTests\Senparc.WeixinTests.net8.csproj", "{A514FE17-476F-4D10-B28E-A7597CB93F9A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNet", "AspNet", "{6DDD51DD-6029-4F4B-994A-4CD3231BC5B7}" EndProject diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/app.config b/src/Senparc.Weixin.MP/Senparc.WeixinTests/app.config deleted file mode 100644 index 384b75e9a3..0000000000 --- a/src/Senparc.Weixin.MP/Senparc.WeixinTests/app.config +++ /dev/null @@ -1,33 +0,0 @@ - - - -
- - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/BaseTest.cs b/src/Senparc.Weixin/Senparc.WeixinTests/BaseTest.cs similarity index 83% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/BaseTest.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/BaseTest.cs index 247ec262a0..629cd80dcb 100644 --- a/src/Senparc.Weixin.MP/Senparc.WeixinTests/BaseTest.cs +++ b/src/Senparc.Weixin/Senparc.WeixinTests/BaseTest.cs @@ -22,6 +22,8 @@ public class BaseTest protected SenparcSetting _senparcSetting; protected SenparcWeixinSetting _senparcWeixinSetting; + protected IConfiguration _config; + public BaseTest() { RegisterStart(); @@ -32,13 +34,24 @@ public BaseTest() /// protected void RegisterStart() { + var builder = new ConfigurationBuilder(); + //var environment = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production"; + + builder.AddJsonFile("appsettings.json", false, true); + builder.AddJsonFile($"appsettings.Test.json", false, true); + Console.WriteLine("完成 appsettings.json 添加"); + + _config = builder.Build(); + Console.WriteLine("完成 ServiceCollection 和 ConfigurationBuilder 初始化"); + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);//支持 GB2312 //注册开始 RegisterService register; //注册 CON2ET 全局 - var senparcSetting = new SenparcSetting() { IsDebug = true }; + var senparcSetting = _config.GetSection("SenparcSetting").Get(); + var senparcWeixinSetting = _config.GetSection("SenparcWeixinSetting").Get(); var mockEnv = new Mock(); @@ -59,7 +72,7 @@ protected void RegisterStart() register.UseSenparcGlobal(false); //注册微信 - var senparcWeixinSetting = new SenparcWeixinSetting(true); + Senparc.Weixin.All.WeixinEntensions.use register.UseSenparcWeixin(senparcWeixinSetting, senparcSetting); register.ChangeDefaultCacheNamespace("Senparc.Weixin Test Cache"); } diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Cache.Local/Lock/LocalCacheLockTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Cache.Local/Lock/LocalCacheLockTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Cache.Local/Lock/LocalCacheLockTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Cache.Local/Lock/LocalCacheLockTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Cache/CacheStrategyFactoryTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Cache/CacheStrategyFactoryTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Cache/CacheStrategyFactoryTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Cache/CacheStrategyFactoryTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/CommonApis/CommonJsonSendTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/CommonApis/CommonJsonSendTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/CommonApis/CommonJsonSendTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/CommonApis/CommonJsonSendTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Containers/BaseContainerTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Containers/BaseContainerTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Containers/BaseContainerTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Containers/BaseContainerTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Entities/Request/Extensions/RequestMessageTextExtensionTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Entities/Request/Extensions/RequestMessageTextExtensionTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Entities/Request/Extensions/RequestMessageTextExtensionTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Entities/Request/Extensions/RequestMessageTextExtensionTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Entities/SenparcWeixinSetting/SenparcWeixinSettingTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Entities/SenparcWeixinSetting/SenparcWeixinSettingTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Entities/SenparcWeixinSetting/SenparcWeixinSettingTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Entities/SenparcWeixinSetting/SenparcWeixinSettingTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Entities/TemplateMessage/TemplateMessageDataTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Entities/TemplateMessage/TemplateMessageDataTests.cs similarity index 95% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Entities/TemplateMessage/TemplateMessageDataTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Entities/TemplateMessage/TemplateMessageDataTests.cs index 0f92fed568..f0e20bd5fb 100644 --- a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Entities/TemplateMessage/TemplateMessageDataTests.cs +++ b/src/Senparc.Weixin/Senparc.WeixinTests/Entities/TemplateMessage/TemplateMessageDataTests.cs @@ -34,7 +34,7 @@ public void TemplateMessageDataTest() ""Key4"": { ""value"": ""this is value4"" } -}"; +}".Replace("\n ","\r\n ").Replace("\n}","\r\n}"); Assert.AreEqual(exceptStr, json); } diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Exceptions/CommonTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Exceptions/CommonTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Exceptions/CommonTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Exceptions/CommonTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Helpers/Containers/ContainerHelperTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Helpers/Containers/ContainerHelperTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Helpers/Containers/ContainerHelperTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Helpers/Containers/ContainerHelperTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Helpers/TenPay/TenPayHelperTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Helpers/TenPay/TenPayHelperTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Helpers/TenPay/TenPayHelperTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Helpers/TenPay/TenPayHelperTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/MutipleCacheTestWapper.cs b/src/Senparc.Weixin/Senparc.WeixinTests/MutipleCacheTestWapper.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/MutipleCacheTestWapper.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/MutipleCacheTestWapper.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Properties/AssemblyInfo.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Properties/AssemblyInfo.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Properties/AssemblyInfo.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Properties/AssemblyInfo.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Senparc.WeixinTests.net8.csproj b/src/Senparc.Weixin/Senparc.WeixinTests/Senparc.WeixinTests.net8.csproj similarity index 92% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Senparc.WeixinTests.net8.csproj rename to src/Senparc.Weixin/Senparc.WeixinTests/Senparc.WeixinTests.net8.csproj index 12197ce4a1..f562e1138e 100644 --- a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Senparc.WeixinTests.net8.csproj +++ b/src/Senparc.Weixin/Senparc.WeixinTests/Senparc.WeixinTests.net8.csproj @@ -42,7 +42,8 @@ - + + diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Tencent/WXBizMsgCryptTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Tencent/WXBizMsgCryptTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Tencent/WXBizMsgCryptTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Tencent/WXBizMsgCryptTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/UnitTestHelper.cs b/src/Senparc.Weixin/Senparc.WeixinTests/UnitTestHelper.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/UnitTestHelper.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/UnitTestHelper.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/GetTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/GetTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/GetTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/GetTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/PostTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/PostTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/PostTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/PostTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/RequestUtilityTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/RequestUtilityTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/RequestUtilityTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/RequestUtilityTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/Upload.html b/src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/Upload.html similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/Upload.html rename to src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/Upload.html diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/UrlUtilityTests.cs b/src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/UrlUtilityTests.cs similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/Utilities/HttpUtility/UrlUtilityTests.cs rename to src/Senparc.Weixin/Senparc.WeixinTests/Utilities/HttpUtility/UrlUtilityTests.cs diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/apiclient_key.pem b/src/Senparc.Weixin/Senparc.WeixinTests/apiclient_key.pem similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/apiclient_key.pem rename to src/Senparc.Weixin/Senparc.WeixinTests/apiclient_key.pem diff --git a/src/Senparc.Weixin/Senparc.WeixinTests/appsettings.Test.json b/src/Senparc.Weixin/Senparc.WeixinTests/appsettings.Test.json new file mode 100644 index 0000000000..6f677caad5 --- /dev/null +++ b/src/Senparc.Weixin/Senparc.WeixinTests/appsettings.Test.json @@ -0,0 +1,30 @@ +{ + //CO2NET 设置 + "SenparcSetting": { + //以下为 CO2NET 的 SenparcSetting 全局配置,请勿修改 key,勿删除任何项 + "IsDebug": true, + "DefaultCacheNamespace": "DefaultCache", + //分布式缓存 + //"Cache_Redis_Configuration": "localhost:6379,password=123456,defaultDatabase=3" + //"Cache_Redis_Configuration": "#{Cache_Redis_Configuration}#", //Redis配置 + "Cache_Redis_Configuration": "10.37.129.2:6379" //不包含密码 + //"Cache_Redis_Configuration": "localhost:6379",//不包含密码 + //"Cache_Redis_Configuration": "localhost:6379,password=senparc,connectTimeout=1000,connectRetry=2,syncTimeout=10000,defaultDatabase=3",//密码及其他配置 + //"Cache_Memcached_Configuration": "#{Cache_Memcached_Configuration}#", //Memcached配置 + //"SenparcUnionAgentKey": "#{SenparcUnionAgentKey}#" //SenparcUnionAgentKey + }, + "SenparcWeixinSetting": { + "IsDebug": true, + "WeixinAppId": "wxe273c3a02e09ff8c", + "WeixinAppSecret": "631f30445f640e1a870f1ef79aa543bd", + "WxOpenAppId": "WxOpenAppId-1", + "WxOpenAppSecret": "WxOpenAppSecret-1", + "WxOpenToken": "#{WxOpenToken}#", + "WxOpenEncodingAESKey": "#{WxOpenEncodingAESKey}#", + "WeixinCorpId": "wx7618c0a6d9358622", + "WeixinCorpAgentId": "1000009", + "WeixinCorpSecret": "vkTzq-kHROrqiqeelTqzfnSndUHJEbvSKaQOMqcaPqI", + "WeixinCorpToken": "WeixinCorpToken-1", + "WeixinCorpEncodingAESKey": "WeixinCorpEncodingAESKey-1" + } +} \ No newline at end of file diff --git a/src/Senparc.Weixin.MP/Senparc.WeixinTests/appsettings.json b/src/Senparc.Weixin/Senparc.WeixinTests/appsettings.json similarity index 100% rename from src/Senparc.Weixin.MP/Senparc.WeixinTests/appsettings.json rename to src/Senparc.Weixin/Senparc.WeixinTests/appsettings.json From 96fbdd0ce4735bcd3eb0272b25eeb4463f3f9d8f Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Mon, 30 Sep 2024 01:10:04 +0800 Subject: [PATCH 2/6] =?UTF-8?q?WebSocket=20v1.0.3=20=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Senparc.WebSocket.net8.csproj | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/Senparc.WebSocket/src/Senparc.WebSocket/Senparc.WebSocket/Senparc.WebSocket.net8.csproj b/src/Senparc.WebSocket/src/Senparc.WebSocket/Senparc.WebSocket/Senparc.WebSocket.net8.csproj index f84e1e9b25..6a35ba6374 100644 --- a/src/Senparc.WebSocket/src/Senparc.WebSocket/Senparc.WebSocket/Senparc.WebSocket.net8.csproj +++ b/src/Senparc.WebSocket/src/Senparc.WebSocket/Senparc.WebSocket/Senparc.WebSocket.net8.csproj @@ -1,7 +1,7 @@ net462;netstandard2.0;netstandard2.1;netcoreapp3.1;net8.0 - 1.0.2 + 1.0.3 Senparc.WebSocket Senparc.WebSocket true @@ -22,34 +22,35 @@ https://github.com/JeffreySu/WeiXinMPSDK icon.jpg - v0.1.1 完成MessageHandler、WebSocketHandler等基础架构,完成基本消息通讯 + v0.1.1 完成MessageHandler、WebSocketHandler等基础架构,完成基本消息通讯 - v0.1.3 优化WebSocket通讯机制 + v0.1.3 优化WebSocket通讯机制 - v0.2.0 支持 .NET Core + v0.2.0 支持 .NET Core - v0.3.0 支持 .NET Core 2.0 - v0.3.1 - 1、提供WebSocketHandler.IsReusable返回值(true) - 2、升级Newtonsoft.Json版本至10.0.1 - v0.3.2 注册WebSocketMessageHandler,自定义对象的实例化方法,用以支持Spring等框架的注入 - v0.3.3 常规优化 - v0.4.0 停止对 .net core 1.1 生成的独立版本 + v0.3.0 支持 .NET Core 2.0 + v0.3.1 + 1、提供WebSocketHandler.IsReusable返回值(true) + 2、升级Newtonsoft.Json版本至10.0.1 + v0.3.2 注册WebSocketMessageHandler,自定义对象的实例化方法,用以支持Spring等框架的注入 + v0.3.3 常规优化 + v0.4.0 停止对 .net core 1.1 生成的独立版本 - v0.5.0-rc1 支持 .NET Core 2.1.0 + v0.5.0-rc1 支持 .NET Core 2.1.0 - v0.5.5 发布支持 .net core 2.1 的正式版 - v0.6.0 支持最新基础库,使用 .NETStandard2.0 统一支持 .NET Core,放弃对 .NET Core 1.x 的单独适配 - v0.7.3 全局使用 .ConfigureAwait(false) 应对异步锁死问题 - v0.8.0 - 1、支持 .NET Core SignalR - 2、提供 Register 注册方法 - 3、优化 WebSocketMesssageHandler - v0.8.1 引用最新版本 CO2NET - v0.8.2 引用最新版本 CO2NET - v0.8.3 提供带符号的 nuget 包(.snupkg) - v0.9.0 使用最新版本 Senparc.Weixin,支持 .NET Core 3.0 - + v0.5.5 发布支持 .net core 2.1 的正式版 + v0.6.0 支持最新基础库,使用 .NETStandard2.0 统一支持 .NET Core,放弃对 .NET Core 1.x 的单独适配 + v0.7.3 全局使用 .ConfigureAwait(false) 应对异步锁死问题 + v0.8.0 + 1、支持 .NET Core SignalR + 2、提供 Register 注册方法 + 3、优化 WebSocketMesssageHandler + v0.8.1 引用最新版本 CO2NET + v0.8.2 引用最新版本 CO2NET + v0.8.3 提供带符号的 nuget 包(.snupkg) + v0.9.0 使用最新版本 Senparc.Weixin,支持 .NET Core 3.0 + v1.0.3 清理引用项目 + https://github.com/JeffreySu/WeiXinMPSDK @@ -102,13 +103,13 @@ - + - - + From 7fd2db2c0a1238ac652a5487a6edf7725edbe6af Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Mon, 30 Sep 2024 01:12:13 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E8=B0=83=E6=95=B4=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 --- .../Program.cs | 7 +- ...nparc.Weixin.Cache.Redis.Tests.net8.csproj | 2 +- .../Senparc.Weixin.MP.Test.net8.csproj | 2 +- .../Senparc.Weixin.Open.Test.net8.csproj | 2 +- .../Senparc.Weixin.TenPay.Test.net8.csproj | 2 +- .../V3/TenPayV3ResultTest.cs | 4 +- .../Senparc.Weixin.TenPayV3.Test.net8.csproj | 2 +- .../Senparc.Weixin.Work.Test.net8.csproj | 2 +- .../Senparc.Weixin.WxOpen.Tests.net8.csproj | 2 +- .../Senparc.WeixinTests/BaseTest.cs | 70 ++++++------------- 10 files changed, 33 insertions(+), 62 deletions(-) diff --git a/Samples/All/console/Senparc.Weixin.MP.Sample.Consoles/Program.cs b/Samples/All/console/Senparc.Weixin.MP.Sample.Consoles/Program.cs index 4007f336fc..59cee32d51 100644 --- a/Samples/All/console/Senparc.Weixin.MP.Sample.Consoles/Program.cs +++ b/Samples/All/console/Senparc.Weixin.MP.Sample.Consoles/Program.cs @@ -35,6 +35,7 @@ and limitations under the License. using System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Senparc.CO2NET; using Senparc.CO2NET.Extensions; using Senparc.Weixin; @@ -42,9 +43,11 @@ and limitations under the License. using Senparc.Weixin.MP; using Senparc.Weixin.RegisterServices; - var builder = new ConfigurationBuilder(); -builder.AddJsonFile("appsettings.json", false, false); +var environment = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production"; + +builder.AddJsonFile("appsettings.json", false, true); +builder.AddJsonFile($"appsettings.{environment}.json", false, true); Console.WriteLine("完成 appsettings.json 添加"); var config = builder.Build(); diff --git a/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Redis.Tests/Senparc.Weixin.Cache.Redis.Tests.net8.csproj b/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Redis.Tests/Senparc.Weixin.Cache.Redis.Tests.net8.csproj index 981ff834bc..076645cb70 100644 --- a/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Redis.Tests/Senparc.Weixin.Cache.Redis.Tests.net8.csproj +++ b/src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Redis.Tests/Senparc.Weixin.Cache.Redis.Tests.net8.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/Senparc.Weixin.MP.Test.net8.csproj b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/Senparc.Weixin.MP.Test.net8.csproj index e10aba688f..00ad46a6e7 100644 --- a/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/Senparc.Weixin.MP.Test.net8.csproj +++ b/src/Senparc.Weixin.MP/Senparc.Weixin.MP.Test/Senparc.Weixin.MP.Test.net8.csproj @@ -28,7 +28,7 @@ - + diff --git a/src/Senparc.Weixin.Open/Senparc.Weixin.Open.Test/Senparc.Weixin.Open.Test.net8.csproj b/src/Senparc.Weixin.Open/Senparc.Weixin.Open.Test/Senparc.Weixin.Open.Test.net8.csproj index 3845a3c3ce..89bafb5c95 100644 --- a/src/Senparc.Weixin.Open/Senparc.Weixin.Open.Test/Senparc.Weixin.Open.Test.net8.csproj +++ b/src/Senparc.Weixin.Open/Senparc.Weixin.Open.Test/Senparc.Weixin.Open.Test.net8.csproj @@ -28,7 +28,7 @@ - + diff --git a/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/Senparc.Weixin.TenPay.Test.net8.csproj b/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/Senparc.Weixin.TenPay.Test.net8.csproj index bb74a5e9d9..835e947fc6 100644 --- a/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/Senparc.Weixin.TenPay.Test.net8.csproj +++ b/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/Senparc.Weixin.TenPay.Test.net8.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/V3/TenPayV3ResultTest.cs b/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/V3/TenPayV3ResultTest.cs index 7df005eb61..fdf010d8b9 100644 --- a/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/V3/TenPayV3ResultTest.cs +++ b/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay.Test/V3/TenPayV3ResultTest.cs @@ -1,8 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Senparc.Weixin.TenPay.V3; using System; -using System.Collections.Generic; -using System.Text; namespace Senparc.Weixin.TenPay.Test.vs2017.V3 { @@ -35,7 +33,7 @@ public void GetXmlValuesTest() public void GetXmlValuesTest1() { var data = new TenPayV3UnifiedorderRequestData("", "", "test", "test123123", 1, "", "", TenPayV3Type.JSAPI, "", "", "1111"); - TenPayV3.Unifiedorder(data); + Senparc.Weixin.TenPay.V3.TenPayV3.Unifiedorder(data); } } } diff --git a/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3.Test/Senparc.Weixin.TenPayV3.Test.net8.csproj b/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3.Test/Senparc.Weixin.TenPayV3.Test.net8.csproj index e0a35b5d3e..0b00522295 100644 --- a/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3.Test/Senparc.Weixin.TenPayV3.Test.net8.csproj +++ b/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3.Test/Senparc.Weixin.TenPayV3.Test.net8.csproj @@ -41,7 +41,7 @@ - + diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Senparc.Weixin.Work.Test.net8.csproj b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Senparc.Weixin.Work.Test.net8.csproj index 90834f7767..e4efded0fe 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Senparc.Weixin.Work.Test.net8.csproj +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Senparc.Weixin.Work.Test.net8.csproj @@ -24,7 +24,7 @@ - + diff --git a/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen.Tests/Senparc.Weixin.WxOpen.Tests.net8.csproj b/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen.Tests/Senparc.Weixin.WxOpen.Tests.net8.csproj index a0ed81c3db..92a0379f67 100644 --- a/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen.Tests/Senparc.Weixin.WxOpen.Tests.net8.csproj +++ b/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen.Tests/Senparc.Weixin.WxOpen.Tests.net8.csproj @@ -28,7 +28,7 @@ - + diff --git a/src/Senparc.Weixin/Senparc.WeixinTests/BaseTest.cs b/src/Senparc.Weixin/Senparc.WeixinTests/BaseTest.cs index 629cd80dcb..5ee23e15d9 100644 --- a/src/Senparc.Weixin/Senparc.WeixinTests/BaseTest.cs +++ b/src/Senparc.Weixin/Senparc.WeixinTests/BaseTest.cs @@ -21,6 +21,7 @@ public class BaseTest protected IServiceProvider _serviceProvider; protected SenparcSetting _senparcSetting; protected SenparcWeixinSetting _senparcWeixinSetting; + protected ServiceCollection _serviceCollection; protected IConfiguration _config; @@ -35,6 +36,9 @@ public BaseTest() protected void RegisterStart() { var builder = new ConfigurationBuilder(); + + _serviceCollection = new ServiceCollection(); + //var environment = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production"; builder.AddJsonFile("appsettings.json", false, true); @@ -50,15 +54,24 @@ protected void RegisterStart() RegisterService register; //注册 CON2ET 全局 - var senparcSetting = _config.GetSection("SenparcSetting").Get(); - var senparcWeixinSetting = _config.GetSection("SenparcWeixinSetting").Get(); + _senparcSetting = _config.GetSection("SenparcSetting").Get(); + _senparcWeixinSetting = _config.GetSection("SenparcWeixinSetting").Get(); + + #region 注册 IServiceCollection 和 MemoryCache + + _serviceCollection.AddMemoryCache();//使用内存缓存 + + //已经包含 AddSenparcGlobalServices(),注意:必须在所有注册完成后执行 + _serviceCollection.AddSenparcWeixin(_config); + + _serviceProvider = _serviceCollection.BuildServiceProvider(); + + #endregion var mockEnv = new Mock(); mockEnv.Setup(z => z.ContentRootPath).Returns(() => UnitTestHelper.RootPath); - register = Senparc.CO2NET.AspNet.RegisterServices.RegisterService.Start(mockEnv.Object, senparcSetting); - - RegisterServiceCollection(); + register = Senparc.CO2NET.AspNet.RegisterServices.RegisterService.Start(mockEnv.Object, _senparcSetting); //Func> func = () => //{ @@ -72,54 +85,11 @@ protected void RegisterStart() register.UseSenparcGlobal(false); //注册微信 - Senparc.Weixin.All.WeixinEntensions.use - register.UseSenparcWeixin(senparcWeixinSetting, senparcSetting); + Senparc.Weixin.All.WeixinEntensions.UseSenparcWeixin(register, _senparcWeixinSetting, (r, s) => { }, true, _serviceProvider); + register.UseSenparcWeixin(_senparcWeixinSetting, _senparcSetting); register.ChangeDefaultCacheNamespace("Senparc.Weixin Test Cache"); } - /// - /// 注册 IServiceCollection 和 MemoryCache - /// - public void RegisterServiceCollection() - { - var serviceCollection = new ServiceCollection(); - var configBuilder = new ConfigurationBuilder(); - - var appSettingsTestFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, UnitTestHelper.RootPath, "appsettings.Test.json")); - var appSettingsFileExisted = File.Exists(appSettingsTestFilePath); - - if (appSettingsFileExisted) - { - configBuilder.AddJsonFile("appsettings.Test.json", false, false);//此文件可能包含敏感信息,不可上传至公共库 - } - else - { - if (File.Exists(appSettingsTestFilePath.Replace(".Test", ""))) - { - configBuilder.AddJsonFile("appsettings.json", false, false);//默认使用 appsettings.json - appSettingsFileExisted = true; - } - } - - var config = configBuilder.Build(); - - _senparcSetting = new SenparcSetting() { IsDebug = true }; - _senparcWeixinSetting = new SenparcWeixinSetting() { IsDebug = true }; - - if (appSettingsFileExisted) - { - config.GetSection("SenparcSetting").Bind(_senparcSetting); - config.GetSection("SenparcWeixinSetting").Bind(_senparcWeixinSetting); - } - - serviceCollection.AddMemoryCache();//使用内存缓存 - - //已经包含 AddSenparcGlobalServices(),注意:必须在所有注册完成后执行 - serviceCollection.AddSenparcWeixin(config); - - _serviceProvider = serviceCollection.BuildServiceProvider(); - } - /// /// 获取到达项目根目录的相对路径 /// From 0b81272694a60a7eb000dcdc3d849bc25d32399d Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Mon, 30 Sep 2024 01:34:51 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=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 --- .../CommonApis/CommonApiTest.Menu.cs | 12 ++-- .../CommonApis/CommonApiTest.cs | 71 ++++++++++--------- .../Containers/AccessTokenContainerTest.cs | 2 +- .../Containers/JsApiTicketContainerTest.cs | 2 +- ...rkMessageHandlers_OmitRepeatMessageTest.cs | 6 +- 5 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.Menu.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.Menu.cs index 3685306820..a2e8aeb883 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.Menu.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.Menu.cs @@ -30,7 +30,7 @@ namespace Senparc.Weixin.Work.Test.CommonApis { public partial class CommonApiTest { - private int _agentId = 7; + private int _agentId = 1000009; [TestMethod] public async Task CreateMenuTest() @@ -88,11 +88,14 @@ public async Task CreateMenuTest() Assert.IsNotNull(result); Assert.AreEqual("ok", result.errmsg); + + GetMenuTest(); + + DeleteMenuTest(); } - [TestMethod] - public void GetMenuTest() + private void GetMenuTest() { //return;//已经通过测试 var accessToken = AccessTokenContainer.GetToken(_corpId, _corpSecret); @@ -104,8 +107,7 @@ public void GetMenuTest() Assert.IsTrue(result.menu.button.Count > 0); } - [TestMethod] - public void DeleteMenuTest() + private void DeleteMenuTest() { var accessToken = AccessTokenContainer.GetToken(_corpId, _corpSecret); diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs index 325750f9eb..f4dc69d091 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs @@ -47,47 +47,47 @@ namespace Senparc.Weixin.Work.Test.CommonApis [TestClass] public partial class CommonApiTest : BaseTest { - private dynamic _appConfig; - protected dynamic AppConfig - { - get - { - if (_appConfig == null) - { - var filePath = "../../../Config/test.config"; - if (File.Exists(filePath)) - { - var stream = new FileStream(filePath, FileMode.Open); - var doc = XDocument.Load(stream); - stream.Dispose(); - - _appConfig = new - { - CorpId = doc.Root.Element("CorpId").Value, - CorpSecret = doc.Root.Element("CorpSecret").Value, - }; - } - else - { - _appConfig = new - { - CorpId = "YourAppId", //换成你的信息 - CorpSecret = "YourSecret",//换成你的信息 - }; - } - } - return _appConfig; - } - } + //private dynamic _appConfig; + //protected dynamic AppConfig + //{ + // get + // { + // if (_appConfig == null) + // { + // var filePath = "../../../Config/test.config"; + // if (File.Exists(filePath)) + // { + // var stream = new FileStream(filePath, FileMode.Open); + // var doc = XDocument.Load(stream); + // stream.Dispose(); + + // _appConfig = new + // { + // CorpId = doc.Root.Element("CorpId").Value, + // CorpSecret = doc.Root.Element("CorpSecret").Value, + // }; + // } + // else + // { + // _appConfig = new + // { + // CorpId = "YourAppId", //换成你的信息 + // CorpSecret = "YourSecret",//换成你的信息 + // }; + // } + // } + // return _appConfig; + // } + //} protected string _corpId { - get { return AppConfig.CorpId; } + get { return base._senparcWeixinSetting.WorkSetting.WeixinCorpId; } } protected string _corpSecret { - get { return AppConfig.CorpSecret; } + get { return base._senparcWeixinSetting.WorkSetting.WeixinCorpSecret; } } @@ -129,8 +129,9 @@ public void GetTokenFailTest() } catch (ErrorJsonResultException ex) { + //Assert.AreEqual(0, ex.JsonResult.errcode); //实际返回的信息(错误信息) - Assert.AreEqual(ex.JsonResult.errcode, ReturnCode_Work.不合法的corpid); + Assert.AreEqual((int)ex.JsonResult.errcode, (int)ReturnCode_Work.不合法的corpid); } } diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/AccessTokenContainerTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/AccessTokenContainerTest.cs index 4bf1fa7f3f..f9dde13a93 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/AccessTokenContainerTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/AccessTokenContainerTest.cs @@ -39,7 +39,7 @@ public class AccessTokenContainerTest : CommonApiTest public void ContainerTest() { //注册 - AccessTokenContainer.Register(base._corpId, base._corpSecret); + //AccessTokenContainer.Register(base._corpId, base._corpSecret); //获取Token完整结果(包括当前过期秒数) var tokenResult = AccessTokenContainer.GetTokenResult(base._corpId,base._corpSecret); diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/JsApiTicketContainerTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/JsApiTicketContainerTest.cs index 81ad206d9a..0ba5463ff0 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/JsApiTicketContainerTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/Containers/JsApiTicketContainerTest.cs @@ -54,7 +54,7 @@ public void ContainerTest() Assert.AreEqual(ticketResult.ticket, ticket); ticket = JsApiTicketContainer.TryGetTicket(base._corpId, base._corpSecret, true); - Assert.AreEqual(ticketResult.ticket, ticket);//现在微信服务器有Ticket缓存,短时间内一致 + Assert.AreNotEqual(ticketResult.ticket, ticket);//现在微信服务器有Ticket缓存,短时间内一致(2024年测试,已实现实时刷新) Console.WriteLine(ticketResult.ticket); } diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlers_OmitRepeatMessageTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlers_OmitRepeatMessageTest.cs index 0a3fc516b3..1a6c58a32a 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlers_OmitRepeatMessageTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlers_OmitRepeatMessageTest.cs @@ -85,19 +85,19 @@ public class WorkMessageHandlers_OmitRepeatMessageTest "; [TestMethod] - public void OmitMessageTest() + public async Task OmitMessageTest() { { //发送两条响同MsgId的消息 var messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(xmlText)); messageHandler.OmitRepeatedMessage = true; - messageHandler.Execute(); + await messageHandler.ExecuteAsync(new CancellationToken()); Assert.IsNotNull(messageHandler.ResponseMessage); Assert.AreEqual("末", (messageHandler.ResponseMessage as ResponseMessageText).Content); messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(xmlText)); messageHandler.OmitRepeatedMessage = true; - messageHandler.Execute(); + await messageHandler.ExecuteAsync(new CancellationToken()); Assert.IsNull(messageHandler.ResponseMessage); } From 05e5fa735db4cd695708c0183285baa940e02e9d Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Tue, 1 Oct 2024 00:12:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkMessageHandlerTest.Approval.cs | 2 +- .../WorkMessageHandlerTest.Change_Contact.cs | 5 ++-- .../MessageHandlers/WorkMessageHandlerTest.cs | 24 +++++++------------ 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Approval.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Approval.cs index cbcb325155..ccaae4d7bd 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Approval.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Approval.cs @@ -332,7 +332,7 @@ public void RequestMessageEvent_OpenApprovalChangeTest() Assert.IsNotNull(requestMessage.ApprovalInfo); Assert.AreEqual("thirdNoxxx", requestMessage.ApprovalInfo.ThirdNo); - Assert.AreEqual((uint)1234567111, requestMessage.ApprovalInfo.OpenTemplateId); + Assert.AreEqual("1234567111", requestMessage.ApprovalInfo.OpenTemplateId); Assert.AreEqual("产品部", requestMessage.ApprovalInfo.ApplyUserParty); diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs index a5a1ba76a8..293bb0ba1b 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Xml.Linq; @@ -21,7 +22,7 @@ public partial class WorkMessageHandlersTest /// 创建成员 /// [TestMethod] - public void RequestMessageEvent_Change_Contact_User_Create() + public async Task RequestMessageEvent_Change_Contact_User_Create() { //官方提供 var xml = @" @@ -78,7 +79,7 @@ public void RequestMessageEvent_Change_Contact_User_Create() }; var messageHandler = new CustomMessageHandlers(XDocument.Parse(xml), postModel, 10); - messageHandler.Execute(); + await messageHandler.ExecuteAsync(new CancellationToken()); var responseMessage = messageHandler.ResponseDocument; Assert.IsNotNull(messageHandler.RequestMessage); diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs index 92f3c8f2ff..8851069e3a 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs @@ -18,27 +18,19 @@ and limitations under the License. ----------------------------------------------------------------*/ #endregion Apache License Version 2.0 +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Senparc.Weixin.Work.Entities; +using Senparc.Weixin.Work.Test.CommonApis; +using Senparc.Weixin.Work.Test.net6.MessageHandlers; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using System.Xml; using System.Xml.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Senparc.NeuChar; -using Senparc.NeuChar.Context; -using Senparc.Weixin.Work.Entities; -using Senparc.Weixin.Work.Helpers; -using Senparc.Weixin.Work.MessageHandlers; -using Senparc.Weixin.Work.Test.net6.MessageHandlers; -using Senparc.WeixinTests; namespace Senparc.Weixin.Work.Test.MessageHandlers { [TestClass] - public partial class WorkMessageHandlersTest:BaseTest + public partial class WorkMessageHandlersTest : CommonApiTest { private string testXml = @" @@ -76,7 +68,7 @@ public void TextTest() } [TestMethod] - public void TextTest2() + public async Task TextTest2() { var postModel = new PostModel() { @@ -86,7 +78,7 @@ public void TextTest2() Token = "3J5JTpb4j8Yfk", EncodingAESKey = "XtJUgDlFYncPP3z4V7W6Jv4ietcIFveUn6LP1KzOBNf", - CorpId = "" + CorpId = base._corpId }; var messageHandler = new CustomMessageHandlers(XDocument.Parse(testFileXml), postModel, 10); Assert.IsNotNull(messageHandler.RequestDocument); @@ -94,7 +86,7 @@ public void TextTest2() Assert.IsNotNull(messageHandler.EncryptPostData); Assert.IsTrue(messageHandler.AgentId == 2); - messageHandler.Execute(); + await messageHandler.ExecuteAsync(new CancellationToken()); Assert.IsNotNull(messageHandler.ResponseDocument); Assert.IsNotNull(messageHandler.ResponseMessage); From 4855e623b6137d3f86cf5ad135dda639af0ab908 Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Wed, 2 Oct 2024 02:41:23 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=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/App/AppTest.cs | 81 +++++++------------ .../AdvancedAPIs/MailList/MailListApiTests.cs | 5 +- .../CommonApis/CommonApiTest.cs | 2 + .../MessageHandlers/WorkMessageHandlerTest.cs | 16 ++-- 4 files changed, 42 insertions(+), 62 deletions(-) diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/App/AppTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/App/AppTest.cs index 4054e65bcf..4948bda7d9 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/App/AppTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/App/AppTest.cs @@ -18,18 +18,13 @@ and limitations under the License. ----------------------------------------------------------------*/ #endregion Apache License Version 2.0 -using System; -using System.Text; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Senparc.Weixin.Exceptions; using Senparc.Weixin.Work.AdvancedAPIs; using Senparc.Weixin.Work.AdvancedAPIs.App; -using Senparc.Weixin.Work.AdvancedAPIs.MailList; -using Senparc.Weixin.Work.CommonAPIs; using Senparc.Weixin.Work.Containers; using Senparc.Weixin.Work.Test.CommonApis; +using System; +using System.Threading.Tasks; namespace Senparc.Weixin.Work.Test.AdvancedAPIs { @@ -39,6 +34,8 @@ namespace Senparc.Weixin.Work.Test.AdvancedAPIs [TestClass] public partial class AppTest : CommonApiTest { + const int AGENT_ID = 1000009; + [TestMethod] public void GetAppInfoTest() { @@ -46,70 +43,50 @@ public void GetAppInfoTest() //使用AppKey测试 //常规AccessToken测试 var appKey = AccessTokenContainer.BuildingKey(_corpId, base._corpSecret); - var result = AppApi.GetAppInfo(appKey, 2); + var result = AppApi.GetAppInfo(appKey, AGENT_ID); Assert.IsNotNull(result.agentid); - Assert.AreEqual(result.agentid, "2"); + Assert.AreEqual(result.agentid, AGENT_ID.ToString()); Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result)); } { //常规AccessToken测试 var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret); - var result = AppApi.GetAppInfo(accessToken, 2); + var result = AppApi.GetAppInfo(accessToken, AGENT_ID); Assert.IsNotNull(result.agentid); - Assert.AreEqual(result.agentid, "2"); + Assert.AreEqual(result.agentid, AGENT_ID.ToString()); Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result)); } } [TestMethod] - public void GetAppInfoAsyncTest() + public async Task GetAppInfoAsyncTest() { - var finishedCount = 0; - { - Task.Factory.StartNew(async () => - { - //使用AppKey测试 - //常规AccessToken测试 - var appKey = AccessTokenContainer.BuildingKey(_corpId, base._corpSecret); - var result = await AppApi.GetAppInfoAsync(appKey, 2); - - Assert.IsNotNull(result.agentid); - Assert.AreEqual(result.agentid, "2"); - - Console.WriteLine("1.Ticket:" + SystemTime.Now.Ticks); - Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result)); - finishedCount++; - }); + //使用AppKey测试 + //常规AccessToken测试 + var appKey = AccessTokenContainer.BuildingKey(_corpId, base._corpSecret); + var result = await AppApi.GetAppInfoAsync(appKey, AGENT_ID); - while (finishedCount < 1) - { + Assert.IsNotNull(result.agentid); + Assert.AreEqual(result.agentid, AGENT_ID.ToString()); - } + Console.WriteLine("1.Ticket:" + SystemTime.Now.Ticks); + Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result)); } { - Task.Factory.StartNew(async () => - { - //常规AccessToken测试 - var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret); - var result = await AppApi.GetAppInfoAsync(accessToken, 2); - - Assert.IsNotNull(result.agentid); - Assert.AreEqual(result.agentid, "2"); - - Console.WriteLine("2.Ticket:" + SystemTime.Now.Ticks); - Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result)); - finishedCount++; - }); + //常规AccessToken测试 + var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret); + var result = await AppApi.GetAppInfoAsync(accessToken, AGENT_ID); - while (finishedCount < 2) - { + Assert.IsNotNull(result.agentid); + Assert.AreEqual(result.agentid, AGENT_ID.ToString()); - } + Console.WriteLine("2.Ticket:" + SystemTime.Now.Ticks); + Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result)); } } @@ -120,15 +97,15 @@ public void SetAppTest() SetAppPostData date = new SetAppPostData() { - agentid = "2",//"100" + SystemTime.Now.ToString("yyMMddHHMM"), + agentid = AGENT_ID.ToString(),//"100" + SystemTime.Now.ToString("yyMMddHHMM"), report_location_flag = "1", //logo_mediaid = "1muvdK7W8cjLfNqj0hWP89-CEhZNOVsktCE1JHSTSNpzTf7cGOXyDin_ozluwNZqi", - name = "单元测试添加" + SystemTime.Now.ToString("yyMMddHHMM"), - description = "test", - redirect_domain = "https://sdk.weixin.senparc.com", + name = "微信 SDK 单元测试添加" + SystemTime.Now.ToString("yyyyMMdd HH:mm"), + description = "微信 SDK 单元测试", + redirect_domain = "sdk.weixin.senparc.com", //isreportenter = 0, isreportuser = 1, - home_url = "weixin.senparc.com" + home_url = "https://weixin.senparc.com", }; var result = AppApi.SetApp(accessToken, date); diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/MailList/MailListApiTests.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/MailList/MailListApiTests.cs index ba629d036a..bbef123e8e 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/MailList/MailListApiTests.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/AdvancedAPIs/MailList/MailListApiTests.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Senparc.Weixin.Work.Test.CommonApis; +using Senparc.Weixin.Work.Containers; namespace Senparc.Weixin.Work.AdvancedAPIs.Tests { @@ -15,8 +16,8 @@ public class MailListApiTests : CommonApiTest [TestMethod()] public void GetDepartmentMemberInfoTest() { - var appKeyOrAccessToken = ""; - var result = MailListApi.GetDepartmentMemberInfo(appKeyOrAccessToken, 1, 1/*, Int32.MaxValue*/); + var appKey = AccessTokenContainer.BuildingKey(_corpId, _corpSecret); + var result = MailListApi.GetDepartmentMemberInfo(appKey, 1, 1/*, Int32.MaxValue*/); Assert.IsNotNull(result); } } diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs index f4dc69d091..c3107096f9 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/CommonApis/CommonApiTest.cs @@ -37,6 +37,7 @@ and limitations under the License. using Senparc.WeixinTests; using Microsoft.AspNetCore.Hosting; using Senparc.CO2NET.Cache.CsRedis; +using Senparc.CO2NET.Extensions; namespace Senparc.Weixin.Work.Test.CommonApis @@ -143,6 +144,7 @@ public void GetCallBackIpTest() var result = CommonApi.GetCallBackIp(accessToken); Assert.IsNotNull(result); Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功); + Console.WriteLine(result.ToJson(true)); } } } diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs index 8851069e3a..02069cfe3b 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.cs @@ -41,17 +41,17 @@ public partial class WorkMessageHandlersTest : CommonApiTest private string testXml2 = @""; [TestMethod] - public void TextTest() + public async Task TextTest() { var postModel = new PostModel() { - Msg_Signature = "Fill Your Setting", - Timestamp = "Fill Your Setting", - Nonce = "Fill Your Setting", + Msg_Signature = "118b034be74c917464f833cd32fc3f74958b2c93", + Timestamp = "1505643268", + Nonce = "1504921331", - Token = "Fill Your Setting", - EncodingAESKey = "Fill Your Setting", - CorpId = "Fill Your Setting" + Token = "3J5JTpb4j8Yfk", + EncodingAESKey = "XtJUgDlFYncPP3z4V7W6Jv4ietcIFveUn6LP1KzOBNf", + CorpId = base._corpId }; var messageHandler = new CustomMessageHandlers(XDocument.Parse(testXml), postModel, 10); Assert.IsNotNull(messageHandler.RequestDocument); @@ -59,7 +59,7 @@ public void TextTest() Assert.IsNotNull(messageHandler.EncryptPostData); Assert.IsTrue(messageHandler.AgentId == 2); - messageHandler.Execute(); + await messageHandler.ExecuteAsync(new CancellationToken()); Assert.IsNotNull(messageHandler.ResponseDocument); Assert.IsNotNull(messageHandler.ResponseMessage);