From 318ce3ae0dfbff30dbd6a5f1c9e1b5e0a6b726c6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Fri, 6 Jul 2018 16:10:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2mysql=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Core/COMCMS.Core.csproj | 2 +- COMCMS.Web/COMCMS.Web.csproj | 18 ++++---- .../Common/WebAPIHandleErrorAttribute.cs | 2 +- .../ResultExceptionHandler.cs | 4 +- COMCMS.Web/Filter/CheckFilter.cs | 8 ++-- COMCMS.Web/Startup.cs | 43 ++++++++++++++++++- COMCMS.Web/app.config | 2 +- COMCMS.Web/appsettings.json | 2 +- COMCMS_NETCORE.sln | 8 +++- 9 files changed, 67 insertions(+), 22 deletions(-) diff --git a/COMCMS.Core/COMCMS.Core.csproj b/COMCMS.Core/COMCMS.Core.csproj index 80a3766..9e28b9c 100644 --- a/COMCMS.Core/COMCMS.Core.csproj +++ b/COMCMS.Core/COMCMS.Core.csproj @@ -5,7 +5,7 @@ - + diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj index 0632c1a..a42f220 100644 --- a/COMCMS.Web/COMCMS.Web.csproj +++ b/COMCMS.Web/COMCMS.Web.csproj @@ -5,23 +5,21 @@ - - - - + + + + - - - + + + - - - + diff --git a/COMCMS.Web/Common/WebAPIHandleErrorAttribute.cs b/COMCMS.Web/Common/WebAPIHandleErrorAttribute.cs index a8890a8..703cecc 100644 --- a/COMCMS.Web/Common/WebAPIHandleErrorAttribute.cs +++ b/COMCMS.Web/Common/WebAPIHandleErrorAttribute.cs @@ -16,7 +16,7 @@ namespace COMCMS.Web.Common { context.HttpContext.Request.ContentType = "application/json"; context.HttpContext.Request.Headers["Accept"] = "application/json"; - ReJSON model = new ReJSON(5001, "执行错误:" + context.Exception.Message); + ReJson model = new ReJson(5001, "执行错误:" + context.Exception.Message); context.Result = new JsonResult(model); base.OnException(context); } diff --git a/COMCMS.Web/ExceptionHandler/ResultExceptionHandler.cs b/COMCMS.Web/ExceptionHandler/ResultExceptionHandler.cs index b7d13ed..66ceeff 100644 --- a/COMCMS.Web/ExceptionHandler/ResultExceptionHandler.cs +++ b/COMCMS.Web/ExceptionHandler/ResultExceptionHandler.cs @@ -15,8 +15,8 @@ namespace COMCMS.Web.ExceptionHandler { string message = exception.Message; - ReJSON error = new ReJSON(message); - + ReJson error = new ReJson(message); + context.Response.ContentType = "text/json"; await context.Response.WriteAsync(error.ToJson()); } } diff --git a/COMCMS.Web/Filter/CheckFilter.cs b/COMCMS.Web/Filter/CheckFilter.cs index 9691e60..022423d 100644 --- a/COMCMS.Web/Filter/CheckFilter.cs +++ b/COMCMS.Web/Filter/CheckFilter.cs @@ -8,6 +8,8 @@ using COMCMS.Web.Controllers.api; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Filters; + + namespace COMCMS.Web.Filter { public class CheckFilterAttribute : ActionFilterAttribute @@ -41,7 +43,7 @@ namespace COMCMS.Web.Filter } } - private ReJSON ValiSignature(HttpContext context) + private ReJson ValiSignature(HttpContext context) { var Request = context.Request; @@ -77,7 +79,7 @@ namespace COMCMS.Web.Filter if (!MySign.CheckSign(pars, signature)) { - return new ReJSON(40004, "signature 错误!"); + return new ReJson(40004, "signature 错误!"); } //判断是否超时 string timeStamp = pars["timeStamp"]; @@ -85,7 +87,7 @@ namespace COMCMS.Web.Filter DateTime postTime = Utils.StampToDateTime(timeStamp); if (postTime < DateTime.Now.AddSeconds(-120))//30秒有效期 { - return new ReJSON(40004, "signature 错误!", 1); + return new ReJson(40004, "signature 错误!", 1); } return null; diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs index 2c675e4..a762b29 100644 --- a/COMCMS.Web/Startup.cs +++ b/COMCMS.Web/Startup.cs @@ -17,6 +17,13 @@ using COMCMS.Web.Models; using COMCMS.Web.Common; using COMCMS.Web.ExceptionHandler; using Lib.Core.MiddlewareExtension.Extension; +using Senparc.Weixin.Entities; +using Senparc.CO2NET; +using Senparc.CO2NET.RegisterServices; +using Senparc.Weixin; +using Senparc.CO2NET.Cache; +using System.Configuration; +using Microsoft.Extensions.Options; namespace COMCMS.Web { @@ -70,7 +77,7 @@ namespace COMCMS.Web } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp, IOptions senparcSetting, IOptions senparcWeixinSetting) { app.Use(async (context, next) => { @@ -121,9 +128,41 @@ namespace COMCMS.Web }); app.UseMiddlewareExtension(new ResultExceptionHandler()); - + RegisterService.Start(env, senparcSetting.Value) + .UseSenparcWeixin(senparcWeixinSetting.Value, false/*此处为单独用于微信的调试状态*/, () => GetExContainerCacheStrategies()); //加入HttpContext //MyHttpContext.ServiceProvider = svp; } + + #region Senparc 缓存扩展策略 + /// + /// 获取Container扩展缓存策略 + /// + /// + private IList GetExContainerCacheStrategies() + { + var exContainerCacheStrategies = new List(); + + //如果有配置,可以去掉下面注释 + + ////判断Redis是否可用 + //var redisConfiguration = ConfigurationManager.AppSettings["Cache_Redis_Configuration"]; + //if ((!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置")) + //{ + // exContainerCacheStrategies.Add(RedisContainerCacheStrategy.Instance); + //} + + ////判断Memcached是否可用 + //var memcachedConfiguration = ConfigurationManager.AppSettings["Cache_Memcached_Configuration"]; + //if ((!string.IsNullOrEmpty(memcachedConfiguration) && memcachedConfiguration != "Memcached配置")) + //{ + // exContainerCacheStrategies.Add(MemcachedContainerCacheStrategy.Instance); + //} + + //也可扩展自定义的缓存策略 + + return exContainerCacheStrategies; + } + #endregion } } diff --git a/COMCMS.Web/app.config b/COMCMS.Web/app.config index e7d399c..4327f0a 100644 --- a/COMCMS.Web/app.config +++ b/COMCMS.Web/app.config @@ -5,7 +5,7 @@ - + diff --git a/COMCMS.Web/appsettings.json b/COMCMS.Web/appsettings.json index 587197e..e27ad96 100644 --- a/COMCMS.Web/appsettings.json +++ b/COMCMS.Web/appsettings.json @@ -13,7 +13,7 @@ }, "connectionStrings": { "dbconn": { - "connectionString": "Server=.;Port=3306;Database=comcms2;Uid=root;Pwd=root;", + "connectionString": "Server=.;Port=3306;Database=comcms2;Uid=root;Pwd=root;SslMode=None", "providerName": "MySql.Data.MySqlClient" }, "mssqlconnon": { diff --git a/COMCMS_NETCORE.sln b/COMCMS_NETCORE.sln index da57a05..6671f35 100644 --- a/COMCMS_NETCORE.sln +++ b/COMCMS_NETCORE.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COMCMS.Common", "COMCMS.Com EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XCoder(代码生成器)", "XCoder\XCoder(代码生成器).csproj", "{71539325-194B-4D56-8D88-562B33004406}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COMCMS.API", "COMCMS.API\COMCMS.API.csproj", "{ED1581D0-7E94-4ADC-B2B4-0A523EA3B512}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COMCMS.API", "COMCMS.API\COMCMS.API.csproj", "{ED1581D0-7E94-4ADC-B2B4-0A523EA3B512}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib.Core", "Lib.Core\Lib.Core.csproj", "{1957CA2B-3008-46A3-8EE4-38B2F06466A8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {ED1581D0-7E94-4ADC-B2B4-0A523EA3B512}.Debug|Any CPU.Build.0 = Debug|Any CPU {ED1581D0-7E94-4ADC-B2B4-0A523EA3B512}.Release|Any CPU.ActiveCfg = Release|Any CPU {ED1581D0-7E94-4ADC-B2B4-0A523EA3B512}.Release|Any CPU.Build.0 = Release|Any CPU + {1957CA2B-3008-46A3-8EE4-38B2F06466A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1957CA2B-3008-46A3-8EE4-38B2F06466A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1957CA2B-3008-46A3-8EE4-38B2F06466A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1957CA2B-3008-46A3-8EE4-38B2F06466A8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE