From 0d20117bf7df7ee9985ae54e6de1ca27be6ea63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Mon, 28 Oct 2024 10:57:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E3=80=90=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E3=80=91=EF=BC=9A=E6=9B=B4=E6=96=B0=E6=89=80=E6=9C=89=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E7=BB=84=E4=BB=B6=E5=88=B0=E6=9C=80=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E8=B0=83=E6=95=B4initq=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=98=9F=E5=88=97=E7=9A=84=E4=BD=BF=E7=94=A8=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4skit=E5=BE=AE=E4=BF=A1=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E7=BB=84=E4=BB=B6=E7=9A=84=E4=BD=BF=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreCms.Net.Caching.csproj | 2 +- .../CoreCms.Net.CodeGenerator.csproj | 2 +- .../Config/RedisMessageQueueSetup.cs | 19 +++++++ CoreCms.Net.Core/CoreCms.Net.Core.csproj | 12 ++-- CoreCms.Net.Loging/CoreCms.Net.Loging.csproj | 2 +- CoreCms.Net.Model/CoreCms.Net.Model.csproj | 4 +- .../CoreCms.Net.RedisMQ.csproj | 4 +- .../CoreCms.Net.Services.csproj | 4 +- .../Share/CoreCmsShareServices.cs | 4 +- CoreCms.Net.Task/CoreCms.Net.Task.csproj | 2 +- .../RefreshWeChatAccessTokenJob.cs | 4 +- .../CoreCms.Net.Utility.csproj | 4 +- .../CoreCms.Net.WeChat.Service.csproj | 2 +- .../HttpClients/WechatApiHttpClientFactory.cs | 56 ++++++------------- .../Controllers/Com/ToolsController.cs | 30 +++++----- .../CoreCms.Net.Web.Admin.csproj | 12 ++-- .../CoreCms.Net.Web.Admin.xml | 2 +- .../CoreCms.Net.Web.WebApi.csproj | 14 ++--- 18 files changed, 88 insertions(+), 91 deletions(-) diff --git a/CoreCms.Net.Caching/CoreCms.Net.Caching.csproj b/CoreCms.Net.Caching/CoreCms.Net.Caching.csproj index 2ba0e748..62851c91 100644 --- a/CoreCms.Net.Caching/CoreCms.Net.Caching.csproj +++ b/CoreCms.Net.Caching/CoreCms.Net.Caching.csproj @@ -7,7 +7,7 @@ - + diff --git a/CoreCms.Net.CodeGenerator/CoreCms.Net.CodeGenerator.csproj b/CoreCms.Net.CodeGenerator/CoreCms.Net.CodeGenerator.csproj index 2ffadc5f..5768355a 100644 --- a/CoreCms.Net.CodeGenerator/CoreCms.Net.CodeGenerator.csproj +++ b/CoreCms.Net.CodeGenerator/CoreCms.Net.CodeGenerator.csproj @@ -48,7 +48,7 @@ - + diff --git a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs index 06826257..33499b9a 100644 --- a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs +++ b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.Linq; using CoreCms.Net.Configuration; using CoreCms.Net.RedisMQ; using InitQ; using Microsoft.Extensions.DependencyInjection; +using SqlSugar.Extensions; namespace CoreCms.Net.Core.Config { @@ -61,6 +63,21 @@ namespace CoreCms.Net.Core.Config { if (services == null) throw new ArgumentNullException(nameof(services)); + var dbIndex = 0; + var ConnectionString = AppSettingsConstVars.RedisConfigConnectionString; + if (!string.IsNullOrEmpty(ConnectionString)) + { + var arr = ConnectionString.ToLower().Split(','); + if (arr.Length > 1) + { + var defaultDataBaseStr = arr.FirstOrDefault(p => p.Contains("defaultdatabase")); + if (!string.IsNullOrEmpty(defaultDataBaseStr)) + { + dbIndex = defaultDataBaseStr.Split('=').LastOrDefault("0").ObjToInt(0); + } + } + } + services.AddInitQ(m => { //没消息时挂起时长(毫秒) @@ -77,6 +94,8 @@ namespace CoreCms.Net.Core.Config }; //显示日志 m.ShowLog = false; + //新增自定redis驱动器 + m.DbIndex = dbIndex; }); } diff --git a/CoreCms.Net.Core/CoreCms.Net.Core.csproj b/CoreCms.Net.Core/CoreCms.Net.Core.csproj index 8801c656..26135df7 100644 --- a/CoreCms.Net.Core/CoreCms.Net.Core.csproj +++ b/CoreCms.Net.Core/CoreCms.Net.Core.csproj @@ -11,21 +11,21 @@ - + - - - + + + - + - + diff --git a/CoreCms.Net.Loging/CoreCms.Net.Loging.csproj b/CoreCms.Net.Loging/CoreCms.Net.Loging.csproj index 70ee0287..6cce29b4 100644 --- a/CoreCms.Net.Loging/CoreCms.Net.Loging.csproj +++ b/CoreCms.Net.Loging/CoreCms.Net.Loging.csproj @@ -7,7 +7,7 @@ - + diff --git a/CoreCms.Net.Model/CoreCms.Net.Model.csproj b/CoreCms.Net.Model/CoreCms.Net.Model.csproj index c3e84b3c..f4de9f2a 100644 --- a/CoreCms.Net.Model/CoreCms.Net.Model.csproj +++ b/CoreCms.Net.Model/CoreCms.Net.Model.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj b/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj index 903e4635..8dd72dd9 100644 --- a/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj +++ b/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/CoreCms.Net.Services/CoreCms.Net.Services.csproj b/CoreCms.Net.Services/CoreCms.Net.Services.csproj index 726663d3..12e26b59 100644 --- a/CoreCms.Net.Services/CoreCms.Net.Services.csproj +++ b/CoreCms.Net.Services/CoreCms.Net.Services.csproj @@ -5,12 +5,12 @@ - + - + diff --git a/CoreCms.Net.Services/Share/CoreCmsShareServices.cs b/CoreCms.Net.Services/Share/CoreCmsShareServices.cs index 1928e47c..f670501d 100644 --- a/CoreCms.Net.Services/Share/CoreCmsShareServices.cs +++ b/CoreCms.Net.Services/Share/CoreCmsShareServices.cs @@ -232,7 +232,7 @@ namespace CoreCms.Net.Services var response = await client.ExecuteWxaGetWxaCodeUnlimitAsync(request); if (response.IsSuccessful()) { - ms = new MemoryStream(response.RawBytes); + ms = new MemoryStream(response.GetRawBytes()); } else { @@ -348,7 +348,7 @@ namespace CoreCms.Net.Services } else { - ms = new MemoryStream(response.RawBytes); + ms = new MemoryStream(response.GetRawBytes()); } //QrCode 根目录 diff --git a/CoreCms.Net.Task/CoreCms.Net.Task.csproj b/CoreCms.Net.Task/CoreCms.Net.Task.csproj index 00d624d6..996582f1 100644 --- a/CoreCms.Net.Task/CoreCms.Net.Task.csproj +++ b/CoreCms.Net.Task/CoreCms.Net.Task.csproj @@ -5,7 +5,7 @@ - + diff --git a/CoreCms.Net.Task/RefreshWeChatAccessTokenJob.cs b/CoreCms.Net.Task/RefreshWeChatAccessTokenJob.cs index 08d09046..62633ed2 100644 --- a/CoreCms.Net.Task/RefreshWeChatAccessTokenJob.cs +++ b/CoreCms.Net.Task/RefreshWeChatAccessTokenJob.cs @@ -72,7 +72,7 @@ namespace CoreCms.Net.Task createTime = DateTime.Now, isSuccess = false, name = "定时刷新获取微信AccessToken", - parameters = $"刷新 AppId 为 {_weChatOptions.WeiXinAppId} 微信 AccessToken 失败(状态码:{response.RawStatus},错误代码:{response.ErrorCode},错误描述:{response.ErrorMessage})。" + parameters = $"刷新 AppId 为 {_weChatOptions.WeiXinAppId} 微信 AccessToken 失败(错误代码:{response.ErrorCode},错误描述:{response.ErrorMessage})。" }; await _taskLogServices.InsertAsync(log); } @@ -208,7 +208,7 @@ namespace CoreCms.Net.Task createTime = DateTime.Now, isSuccess = false, name = "定时刷新获取微信AccessToken", - parameters = $"刷新 AppId 为 {_weChatOptions.WeiXinAppId} 微信 AccessToken 失败(状态码:{response.RawStatus},错误代码:{response.ErrorCode},错误描述:{response.ErrorMessage})。" + parameters = $"刷新 AppId 为 {_weChatOptions.WeiXinAppId} 微信 AccessToken 失败(错误代码:{response.ErrorCode},错误描述:{response.ErrorMessage})。" }; await _taskLogServices.InsertAsync(log); } diff --git a/CoreCms.Net.Utility/CoreCms.Net.Utility.csproj b/CoreCms.Net.Utility/CoreCms.Net.Utility.csproj index 193fc792..1e6de4e2 100644 --- a/CoreCms.Net.Utility/CoreCms.Net.Utility.csproj +++ b/CoreCms.Net.Utility/CoreCms.Net.Utility.csproj @@ -5,9 +5,9 @@ - + - + diff --git a/CoreCms.Net.WeChat.Service/CoreCms.Net.WeChat.Service.csproj b/CoreCms.Net.WeChat.Service/CoreCms.Net.WeChat.Service.csproj index 1975bba5..c985fca2 100644 --- a/CoreCms.Net.WeChat.Service/CoreCms.Net.WeChat.Service.csproj +++ b/CoreCms.Net.WeChat.Service/CoreCms.Net.WeChat.Service.csproj @@ -9,7 +9,7 @@ - + diff --git a/CoreCms.Net.WeChat.Service/Services/HttpClients/WechatApiHttpClientFactory.cs b/CoreCms.Net.WeChat.Service/Services/HttpClients/WechatApiHttpClientFactory.cs index c646dbe1..923ab41c 100644 --- a/CoreCms.Net.WeChat.Service/Services/HttpClients/WechatApiHttpClientFactory.cs +++ b/CoreCms.Net.WeChat.Service/Services/HttpClients/WechatApiHttpClientFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; using Flurl; using Flurl.Http; @@ -22,8 +23,6 @@ namespace CoreCms.Net.WeChat.Service.HttpClients { _httpClientFactory = httpClientFactory; _weChatOptions = weChatOptions.Value; - - FlurlHttp.GlobalSettings.FlurlClientFactory = new DelegatingFlurlClientFactory(_httpClientFactory); } /// @@ -35,16 +34,17 @@ namespace CoreCms.Net.WeChat.Service.HttpClients if (string.IsNullOrEmpty(_weChatOptions.WeiXinAppId) || string.IsNullOrEmpty(_weChatOptions.WeiXinAppSecret)) throw new Exception("未在配置项中找到微信公众号配置讯息。"); - var wechatApiClient = new WechatApiClient(new WechatApiClientOptions() + var wechatApiClientOptions = new WechatApiClientOptions() { AppId = _weChatOptions.WeiXinAppId, AppSecret = _weChatOptions.WeiXinAppSecret, - }); + PushEncodingAESKey = _weChatOptions.WeiXinEncodingAesKey, + PushToken = _weChatOptions.WeiXinToken + }; - wechatApiClient.Configure(settings => - { - settings.JsonSerializer = new FlurlNewtonsoftJsonSerializer(); - }); + var wechatApiClient = WechatApiClientBuilder.Create(wechatApiClientOptions) + .UseHttpClient(_httpClientFactory.CreateClient(), disposeClient: false) + .Build(); return wechatApiClient; } @@ -58,41 +58,19 @@ namespace CoreCms.Net.WeChat.Service.HttpClients if (string.IsNullOrEmpty(_weChatOptions.WxOpenAppId) || string.IsNullOrEmpty(_weChatOptions.WxOpenAppSecret)) throw new Exception("未在配置项中找到微信小程序配置讯息。"); - var WechatApiClient = new WechatApiClient(new WechatApiClientOptions() + var wechatApiClientOptions = new WechatApiClientOptions() { AppId = _weChatOptions.WxOpenAppId, - AppSecret = _weChatOptions.WxOpenAppSecret - }); + AppSecret = _weChatOptions.WxOpenAppSecret, + PushEncodingAESKey = _weChatOptions.WxOpenEncodingAESKey, + PushToken = _weChatOptions.WxOpenToken + }; - WechatApiClient.Configure(settings => - { - settings.JsonSerializer = new FlurlNewtonsoftJsonSerializer(); - }); + var wechatApiClient = WechatApiClientBuilder.Create(wechatApiClientOptions) + .UseHttpClient(_httpClientFactory.CreateClient(), disposeClient: false) + .Build(); - return WechatApiClient; - } - } - - public partial class WeChatApiHttpClientFactory - { - internal class DelegatingFlurlClientFactory : IFlurlClientFactory - { - private readonly System.Net.Http.IHttpClientFactory _httpClientFactory; - - public DelegatingFlurlClientFactory(System.Net.Http.IHttpClientFactory httpClientFactory) - { - _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); - } - - public IFlurlClient Get(Url url) - { - return new FlurlClient(_httpClientFactory.CreateClient(url.ToUri().Host)); - } - - public void Dispose() - { - // Do Nothing - } + return wechatApiClient; } } } diff --git a/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs b/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs index ddea392f..3bd5622b 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs @@ -638,7 +638,7 @@ namespace CoreCms.Net.Web.Admin.Controllers var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request); if (response.IsSuccessful()) { - var memStream = new MemoryStream(response.RawBytes); + var memStream = new MemoryStream(response.GetRawBytes()); string url = string.Empty; if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString()) @@ -653,12 +653,12 @@ namespace CoreCms.Net.Web.Admin.Controllers else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString()) { //上传到腾讯云OSS - url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.GetRawBytes()); } else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString()) { //上传到七牛云kodo - url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.GetRawBytes()); } var bl = !string.IsNullOrEmpty(url); @@ -720,7 +720,7 @@ namespace CoreCms.Net.Web.Admin.Controllers var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request); if (response.IsSuccessful()) { - var memStream = new MemoryStream(response.RawBytes); + var memStream = new MemoryStream(response.GetRawBytes()); string url = string.Empty; if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString()) @@ -735,12 +735,12 @@ namespace CoreCms.Net.Web.Admin.Controllers else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString()) { //上传到腾讯云OSS - url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.GetRawBytes()); } else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString()) { //上传到七牛云kodo - url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.GetRawBytes()); } var bl = !string.IsNullOrEmpty(url); @@ -802,7 +802,7 @@ namespace CoreCms.Net.Web.Admin.Controllers var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request); if (response.IsSuccessful()) { - var memStream = new MemoryStream(response.RawBytes); + var memStream = new MemoryStream(response.GetRawBytes()); string url = string.Empty; if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString()) @@ -818,12 +818,12 @@ namespace CoreCms.Net.Web.Admin.Controllers else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString()) { //上传到腾讯云OSS - url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.GetRawBytes()); } else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString()) { //上传到七牛云kodo - url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.GetRawBytes()); } var bl = !string.IsNullOrEmpty(url); @@ -887,7 +887,7 @@ namespace CoreCms.Net.Web.Admin.Controllers var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request); if (response.IsSuccessful()) { - var memStream = new MemoryStream(response.RawBytes); + var memStream = new MemoryStream(response.GetRawBytes()); string url = string.Empty; if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString()) @@ -902,12 +902,12 @@ namespace CoreCms.Net.Web.Admin.Controllers else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString()) { //上传到腾讯云OSS - url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.GetRawBytes()); } else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString()) { //上传到七牛云kodo - url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.GetRawBytes()); } var bl = !string.IsNullOrEmpty(url); @@ -972,7 +972,7 @@ namespace CoreCms.Net.Web.Admin.Controllers var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request); if (response.IsSuccessful()) { - var memStream = new MemoryStream(response.RawBytes); + var memStream = new MemoryStream(response.GetRawBytes()); string url = string.Empty; if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString()) @@ -987,12 +987,12 @@ namespace CoreCms.Net.Web.Admin.Controllers else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString()) { //上传到腾讯云OSS - url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.GetRawBytes()); } else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString()) { //上传到七牛云kodo - url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes); + url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.GetRawBytes()); } var bl = !string.IsNullOrEmpty(url); diff --git a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj index b722227a..18a85554 100644 --- a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj +++ b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj @@ -47,12 +47,12 @@ - + - + @@ -62,10 +62,10 @@ - - - - + + + + diff --git a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml index 5bf798fd..76b0d2e5 100644 --- a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml +++ b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml @@ -747,7 +747,7 @@ - 后台生成小程序码 + 后台生成万能表单小程序码 diff --git a/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj b/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj index e80b08b0..3f02097c 100644 --- a/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj +++ b/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj @@ -51,14 +51,14 @@ - + - - - + + + @@ -69,9 +69,9 @@ - - - + + +