From ed47497d8cf5368ed124cb9631a9515bc2f9006a Mon Sep 17 00:00:00 2001 From: yuyubo <1870149533@qq.com> Date: Sat, 30 Aug 2025 13:53:59 +0800 Subject: [PATCH] 11 --- Fleck/Samples/ConsoleApp/App.config | 17 ++++++----- MyCode.Project.Domain/App.config | 6 +++- MyCode.Project.GenerateCode/App.config | 4 +++ .../Fakes/System.Net.Http.fakes | Bin 0 -> 246 bytes .../MyCode.Project.Infrastructure.csproj | 28 +++++++++++++++++- .../WebPost/WebUtils.cs | 9 +++++- MyCode.Project.Infrastructure/app.config | 4 +++ MyCode.Project.Infrastructure/packages.config | 5 ++++ .../Implementation/EnterpriseWechatService.cs | 1 + MyCode.Project.OutSideService/app.config | 4 +++ MyCode.Project.Repositories/App.config | 4 +++ MyCode.Project.ScheduleTask/App.config | 7 ++--- .../MyCode.Project.ScheduleTask.csproj | 16 ++++++++-- MyCode.Project.ScheduleTask/Program.cs | 19 +++++++++++- MyCode.Project.ScheduleTask/packages.config | 5 ++++ MyCode.Project.Services/App.config | 4 +++ .../StaffDataEnterpriseWechatService.cs | 1 + 17 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 MyCode.Project.Infrastructure/Fakes/System.Net.Http.fakes diff --git a/Fleck/Samples/ConsoleApp/App.config b/Fleck/Samples/ConsoleApp/App.config index cf15644..065d603 100644 --- a/Fleck/Samples/ConsoleApp/App.config +++ b/Fleck/Samples/ConsoleApp/App.config @@ -36,7 +36,7 @@ - + @@ -73,7 +73,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -126,12 +126,9 @@ - + - + @@ -252,6 +249,10 @@ + + + + diff --git a/MyCode.Project.Domain/App.config b/MyCode.Project.Domain/App.config index 1008bb1..b2200cc 100644 --- a/MyCode.Project.Domain/App.config +++ b/MyCode.Project.Domain/App.config @@ -9,7 +9,7 @@ - + @@ -24,6 +24,10 @@ + + + + diff --git a/MyCode.Project.GenerateCode/App.config b/MyCode.Project.GenerateCode/App.config index f346b22..408b1cd 100644 --- a/MyCode.Project.GenerateCode/App.config +++ b/MyCode.Project.GenerateCode/App.config @@ -126,6 +126,10 @@ + + + + diff --git a/MyCode.Project.Infrastructure/Fakes/System.Net.Http.fakes b/MyCode.Project.Infrastructure/Fakes/System.Net.Http.fakes new file mode 100644 index 0000000000000000000000000000000000000000..cdd0418df2580b4b6221533da65d759546fc60e7 GIT binary patch literal 246 zcmYL^!3x4K5JcxJ_z$HYkksNyV!?}e@*;Sz60v9-X*}r9t1l6eWs}|6*_q`1a$2j^ zMP5;b9_n?~K)qC{v+l%A3t1xS2;yP1)P}nQ85QV)PB0C90Jn5MO{-d!W`sqt(Nq(B z3OTLVi&^i0=M!wpRu7WAcOVhXq|FXNlw2&r$t< G+2{k80Vv1- literal 0 HcmV?d00001 diff --git a/MyCode.Project.Infrastructure/MyCode.Project.Infrastructure.csproj b/MyCode.Project.Infrastructure/MyCode.Project.Infrastructure.csproj index 20f6c65..ee1edeb 100644 --- a/MyCode.Project.Infrastructure/MyCode.Project.Infrastructure.csproj +++ b/MyCode.Project.Infrastructure/MyCode.Project.Infrastructure.csproj @@ -94,6 +94,9 @@ ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll True + + False + False ..\Lib\Newtonsoft.Json.dll @@ -136,7 +139,9 @@ ..\Lib\System.Memory.dll - + + FakesAssemblies\System.Net.Http.4.2.0.0.Fakes.dll + ..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll @@ -151,6 +156,26 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + True + True + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + True + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + True + True + ..\Lib\System.Threading.Tasks.Extensions.dll @@ -355,6 +380,7 @@ + Designer diff --git a/MyCode.Project.Infrastructure/WebPost/WebUtils.cs b/MyCode.Project.Infrastructure/WebPost/WebUtils.cs index 10ba3e5..460ba29 100644 --- a/MyCode.Project.Infrastructure/WebPost/WebUtils.cs +++ b/MyCode.Project.Infrastructure/WebPost/WebUtils.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using System.Web; using MyCode.Project.Infrastructure.Common; using MyCode.Project.Infrastructure.Exceptions; +using Org.BouncyCastle.Asn1.Ocsp; namespace MyCode.Project.Infrastructure.WebPost { @@ -531,12 +532,18 @@ namespace MyCode.Project.Infrastructure.WebPost /// public string DoPostJson(string url, string jsonData) { + // 在应用程序启动时设置(如Main方法或Application_Start) + System.Net.ServicePointManager.SecurityProtocol = + SecurityProtocolType.Tls12; string result = ""; - HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.Timeout = 60*1000;//设置请求超时时间,单位为毫秒 req.ContentType = "application/json"; + req.ProtocolVersion = HttpVersion.Version11; + req.ServicePoint.Expect100Continue = true; + //req.ServicePoint.SecurityProtocol = SecurityProtocolType.Tls12; + byte[] data = Encoding.UTF8.GetBytes(jsonData); req.ContentLength = data.Length; diff --git a/MyCode.Project.Infrastructure/app.config b/MyCode.Project.Infrastructure/app.config index 83a9a78..36c4091 100644 --- a/MyCode.Project.Infrastructure/app.config +++ b/MyCode.Project.Infrastructure/app.config @@ -23,6 +23,10 @@ + + + + diff --git a/MyCode.Project.Infrastructure/packages.config b/MyCode.Project.Infrastructure/packages.config index 44487bb..4e52170 100644 --- a/MyCode.Project.Infrastructure/packages.config +++ b/MyCode.Project.Infrastructure/packages.config @@ -14,9 +14,14 @@ + + + + + diff --git a/MyCode.Project.OutSideService/Implementation/EnterpriseWechatService.cs b/MyCode.Project.OutSideService/Implementation/EnterpriseWechatService.cs index 11b02be..7268349 100644 --- a/MyCode.Project.OutSideService/Implementation/EnterpriseWechatService.cs +++ b/MyCode.Project.OutSideService/Implementation/EnterpriseWechatService.cs @@ -465,6 +465,7 @@ namespace MyCode.Project.OutSideService.Implementation }}"; var webUtils = new WebUtils(); var resp = webUtils.DoPostJson(url, json); + LogHelper.Info(userId+"企业微信官方信息:" +resp); UserIdChangeOpenIdResp resut = JsonHelper.ToObject(resp); return resut; } diff --git a/MyCode.Project.OutSideService/app.config b/MyCode.Project.OutSideService/app.config index fc4f0e6..ed18e00 100644 --- a/MyCode.Project.OutSideService/app.config +++ b/MyCode.Project.OutSideService/app.config @@ -19,6 +19,10 @@ + + + + diff --git a/MyCode.Project.Repositories/App.config b/MyCode.Project.Repositories/App.config index 802eaff..19951ee 100644 --- a/MyCode.Project.Repositories/App.config +++ b/MyCode.Project.Repositories/App.config @@ -23,6 +23,10 @@ + + + + diff --git a/MyCode.Project.ScheduleTask/App.config b/MyCode.Project.ScheduleTask/App.config index ee733e6..18dd45c 100644 --- a/MyCode.Project.ScheduleTask/App.config +++ b/MyCode.Project.ScheduleTask/App.config @@ -16,7 +16,7 @@ - + @@ -102,8 +102,7 @@ - + @@ -228,7 +227,7 @@ - + diff --git a/MyCode.Project.ScheduleTask/MyCode.Project.ScheduleTask.csproj b/MyCode.Project.ScheduleTask/MyCode.Project.ScheduleTask.csproj index 77955da..1b4ab05 100644 --- a/MyCode.Project.ScheduleTask/MyCode.Project.ScheduleTask.csproj +++ b/MyCode.Project.ScheduleTask/MyCode.Project.ScheduleTask.csproj @@ -73,8 +73,8 @@ - - ..\Lib\System.Net.Http.dll + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll ..\Lib\System.Runtime.dll @@ -83,6 +83,18 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + diff --git a/MyCode.Project.ScheduleTask/Program.cs b/MyCode.Project.ScheduleTask/Program.cs index 643225d..e191b4e 100644 --- a/MyCode.Project.ScheduleTask/Program.cs +++ b/MyCode.Project.ScheduleTask/Program.cs @@ -8,6 +8,7 @@ using MyCode.Project.Infrastructure.UnityExtensions; using MyCode.Project.Infrastructure.Common; using MyCode.Project.Services; using System.Threading; +using System.Net; namespace MyCode.Project.ScheduleTask { @@ -16,7 +17,23 @@ namespace MyCode.Project.ScheduleTask static void Main(string[] args) { - + // 在应用程序启动时设置(如Main方法或Application_Start) + System.Net.ServicePointManager.SecurityProtocol = + SecurityProtocolType.Tls12; + // 检查.NET版本并做相应处理 + if (Environment.Version.Major >= 4) // .NET 4.0+ + { + try + { + // 尝试设置TLS 1.2 + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + } + catch (NotSupportedException) + { + // 如果失败,可能需要安装系统更新 + Console.WriteLine("您的系统需要更新以支持TLS 1.2"); + } + } JobsHelp.start(AppDomain.CurrentDomain.BaseDirectory + "/JobConfig.xml"); diff --git a/MyCode.Project.ScheduleTask/packages.config b/MyCode.Project.ScheduleTask/packages.config index 3d3ceea..0ab5e43 100644 --- a/MyCode.Project.ScheduleTask/packages.config +++ b/MyCode.Project.ScheduleTask/packages.config @@ -4,5 +4,10 @@ + + + + + \ No newline at end of file diff --git a/MyCode.Project.Services/App.config b/MyCode.Project.Services/App.config index d9609dc..1340f9f 100644 --- a/MyCode.Project.Services/App.config +++ b/MyCode.Project.Services/App.config @@ -23,6 +23,10 @@ + + + + diff --git a/MyCode.Project.Services/Implementation/StaffData/StaffDataEnterpriseWechatService.cs b/MyCode.Project.Services/Implementation/StaffData/StaffDataEnterpriseWechatService.cs index 5e50ab6..140d049 100644 --- a/MyCode.Project.Services/Implementation/StaffData/StaffDataEnterpriseWechatService.cs +++ b/MyCode.Project.Services/Implementation/StaffData/StaffDataEnterpriseWechatService.cs @@ -84,6 +84,7 @@ namespace MyCode.Project.Services.Implementation { return; } + //config.FSecret = "gb2VUPGalzEgH9iIWeI7u9GUAlFA3-hXzl2GESRxX-U"; var infoList = _enterpriseWechatService.GetDepartmentList("", config.FAppid, config.FSecret); var ids = infoList.Select(x => long.Parse(x.Id.ToString())).ToList(); var existsDepartList = _basDepartmentRepository.Queryable().Where(x => 1 == 1).ToList();