From f28c84f3bb9670ce003191b04352bf3a072963e7 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Wed, 19 Feb 2020 18:16:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BE=AE=E4=BF=A1=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=E5=9F=BA=E6=9C=AC=E5=AF=B9=E6=8E=A5=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Common/Utils.cs | 31 + COMCMS.Core/COMCMS.Core.csproj | 3 - .../Weixin/公众平台回复信息.Biz.cs | 114 + .../Weixin/公众平台回复信息.cs | 219 + .../Weixin/微信公众号回复规则.Biz.cs | 235 + .../Weixin/微信公众号回复规则.cs | 257 + .../Weixin/请求回复的内容.Biz.cs | 123 + COMCMS.Core/Weixin/请求回复的内容.cs | 333 + .../AdminCP/Controllers/IndexController.cs | 1 - .../Controllers/PermissionController.cs | 2 +- .../AdminCP/Controllers/WeixinController.cs | 1110 +- .../Areas/AdminCP/Views/Index/Index.cshtml | 4 +- .../Views/Weixin/AddClickReplyRule.cshtml | 186 + .../Views/Weixin/AddTextReplyRule.cshtml | 191 + .../Views/Weixin/ClickReplyRule.cshtml | 170 + .../Views/Weixin/EditClickReplyRule.cshtml | 225 + .../Views/Weixin/EditTextReplyRule.cshtml | 229 + .../Areas/AdminCP/Views/Weixin/Menu.cshtml | 194 + .../Weixin/NotFindKeywordAutoReply.cshtml | 221 + .../AdminCP/Views/Weixin/ReplyRule.cshtml | 175 + .../Views/Weixin/SubscribeReply.cshtml | 220 + COMCMS.Web/Controllers/WeixinController.cs | 136 + COMCMS.Web/Startup.cs | 2 + COMCMS.Web/wwwroot/hplus/css/style.css | 2 +- COMCMS.Web/wwwroot/js/axios.js | 1668 +++ COMCMS.Web/wwwroot/js/axios.min.js | 9 + COMCMS.Web/wwwroot/js/vue/vue.common.dev.js | 11959 +++++++++++++++ COMCMS.Web/wwwroot/js/vue/vue.common.js | 5 + COMCMS.Web/wwwroot/js/vue/vue.common.prod.js | 6 + COMCMS.Web/wwwroot/js/vue/vue.esm.browser.js | 12016 ++++++++++++++++ .../wwwroot/js/vue/vue.esm.browser.min.js | 6 + COMCMS.Web/wwwroot/js/vue/vue.esm.js | 11993 +++++++++++++++ COMCMS.Web/wwwroot/js/vue/vue.js | 11965 +++++++++++++++ COMCMS.Web/wwwroot/js/vue/vue.min.js | 6 + .../wwwroot/js/vue/vue.runtime.common.dev.js | 8423 +++++++++++ .../wwwroot/js/vue/vue.runtime.common.js | 5 + .../wwwroot/js/vue/vue.runtime.common.prod.js | 6 + COMCMS.Web/wwwroot/js/vue/vue.runtime.esm.js | 8451 +++++++++++ COMCMS.Web/wwwroot/js/vue/vue.runtime.js | 8429 +++++++++++ COMCMS.Web/wwwroot/js/vue/vue.runtime.min.js | 6 + XCoder/Entity/data.project.xml | 44 + XCoder/Entity/公众平台回复信息.Biz.cs | 114 + XCoder/Entity/公众平台回复信息.cs | 219 + .../Entity/微信公众号回复规则.Biz.cs | 119 + XCoder/Entity/微信公众号回复规则.cs | 257 + XCoder/Entity/请求回复的内容.Biz.cs | 123 + XCoder/Entity/请求回复的内容.cs | 333 + 47 files changed, 80536 insertions(+), 9 deletions(-) create mode 100644 COMCMS.Core/Weixin/公众平台回复信息.Biz.cs create mode 100644 COMCMS.Core/Weixin/公众平台回复信息.cs create mode 100644 COMCMS.Core/Weixin/微信公众号回复规则.Biz.cs create mode 100644 COMCMS.Core/Weixin/微信公众号回复规则.cs create mode 100644 COMCMS.Core/Weixin/请求回复的内容.Biz.cs create mode 100644 COMCMS.Core/Weixin/请求回复的内容.cs create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/AddClickReplyRule.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/AddTextReplyRule.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/ClickReplyRule.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/EditClickReplyRule.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/EditTextReplyRule.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/Menu.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/NotFindKeywordAutoReply.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/ReplyRule.cshtml create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Weixin/SubscribeReply.cshtml create mode 100644 COMCMS.Web/Controllers/WeixinController.cs create mode 100644 COMCMS.Web/wwwroot/js/axios.js create mode 100644 COMCMS.Web/wwwroot/js/axios.min.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.common.dev.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.common.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.common.prod.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.esm.browser.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.esm.browser.min.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.esm.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.min.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.runtime.common.dev.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.runtime.common.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.runtime.common.prod.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.runtime.esm.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.runtime.js create mode 100644 COMCMS.Web/wwwroot/js/vue/vue.runtime.min.js create mode 100644 XCoder/Entity/公众平台回复信息.Biz.cs create mode 100644 XCoder/Entity/公众平台回复信息.cs create mode 100644 XCoder/Entity/微信公众号回复规则.Biz.cs create mode 100644 XCoder/Entity/微信公众号回复规则.cs create mode 100644 XCoder/Entity/请求回复的内容.Biz.cs create mode 100644 XCoder/Entity/请求回复的内容.cs diff --git a/COMCMS.Common/Utils.cs b/COMCMS.Common/Utils.cs index c730f45..01eb5ee 100644 --- a/COMCMS.Common/Utils.cs +++ b/COMCMS.Common/Utils.cs @@ -1053,6 +1053,37 @@ namespace COMCMS.Common return ""; } } + + /// + /// 将对象转换为Int32类型 + /// + /// 要转换的字符串 + /// 缺省值 + /// 转换后的int类型结果 + public static int StrToInt(string str, int defValue) + { + if (string.IsNullOrEmpty(str) || str.Trim().Length >= 11 || !Regex.IsMatch(str.Trim(), @"^([-]|[0-9])[0-9]*(\.\w*)?$")) + return defValue; + + int rv; + if (Int32.TryParse(str, out rv)) + return rv; + + return Convert.ToInt32(StrToFloat(str, defValue)); + } + /// + /// string型转换为float型 + /// + /// 要转换的字符串 + /// 缺省值 + /// 转换后的int类型结果 + public static float StrToFloat(object strValue, float defValue) + { + if ((strValue == null)) + return defValue; + + return StrToFloat(strValue.ToString(), defValue); + } #endregion #region COMCMS类型 diff --git a/COMCMS.Core/COMCMS.Core.csproj b/COMCMS.Core/COMCMS.Core.csproj index 1520cf1..52d92fd 100644 --- a/COMCMS.Core/COMCMS.Core.csproj +++ b/COMCMS.Core/COMCMS.Core.csproj @@ -13,7 +13,4 @@ - - - diff --git a/COMCMS.Core/Weixin/公众平台回复信息.Biz.cs b/COMCMS.Core/Weixin/公众平台回复信息.Biz.cs new file mode 100644 index 0000000..2aac82d --- /dev/null +++ b/COMCMS.Core/Weixin/公众平台回复信息.Biz.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Xml.Serialization; +using NewLife; +using NewLife.Data; +using NewLife.Log; +using NewLife.Model; +using NewLife.Reflection; +using NewLife.Threading; +using NewLife.Web; +using XCode; +using XCode.Cache; +using XCode.Configuration; +using XCode.DataAccessLayer; +using XCode.Membership; + +namespace COMCMS.Core +{ + /// 公众平台回复信息 + public partial class WeixinResponseContent : Entity + { + #region 对象操作 + static WeixinResponseContent() + { + + // 过滤器 UserModule、TimeModule、IPModule + Meta.Modules.Add(); + } + + /// 验证数据,通过抛出异常的方式提示验证失败。 + /// 是否插入 + public override void Valid(Boolean isNew) + { + // 如果没有脏数据,则不需要进行任何处理 + if (!HasDirty) return; + + // 在新插入数据或者修改了指定字段时进行修正 + //if (!Dirtys[nameof(UpdateTime)]) UpdateTime = DateTime.Now; + } + + ///// 首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法 + //[EditorBrowsable(EditorBrowsableState.Never)] + //protected override void InitData() + //{ + // // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用 + // if (Meta.Session.Count > 0) return; + + // if (XTrace.Debug) XTrace.WriteLine("开始初始化WeixinResponseContent[公众平台回复信息]数据……"); + + // var entity = new WeixinResponseContent(); + // entity.Id = 0; + // entity.OpenId = "abc"; + // entity.RequestType = "abc"; + // entity.RequestContent = "abc"; + // entity.ResponseType = "abc"; + // entity.ReponseContent = "abc"; + // entity.XmlContent = "abc"; + // entity.UpdateTime = DateTime.Now; + // entity.Insert(); + + // if (XTrace.Debug) XTrace.WriteLine("完成初始化WeixinResponseContent[公众平台回复信息]数据!"); + //} + + ///// 已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert + ///// + //public override Int32 Insert() + //{ + // return base.Insert(); + //} + + ///// 已重载。在事务保护范围内处理业务,位于Valid之后 + ///// + //protected override Int32 OnDelete() + //{ + // return base.OnDelete(); + //} + #endregion + + #region 扩展属性 + #endregion + + #region 扩展查询 + /// 根据编号查找 + /// 编号 + /// 实体对象 + public static WeixinResponseContent FindById(Int32 id) + { + if (id <= 0) return null; + + // 实体缓存 + if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id); + + // 单对象缓存 + return Meta.SingleCache[id]; + + //return Find(_.Id == id); + } + #endregion + + #region 高级查询 + #endregion + + #region 业务操作 + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Core/Weixin/公众平台回复信息.cs b/COMCMS.Core/Weixin/公众平台回复信息.cs new file mode 100644 index 0000000..abd10fb --- /dev/null +++ b/COMCMS.Core/Weixin/公众平台回复信息.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using XCode; +using XCode.Configuration; +using XCode.DataAccessLayer; + +namespace COMCMS.Core +{ + /// 公众平台回复信息 + [Serializable] + [DataObject] + [Description("公众平台回复信息")] + [BindTable("WeixinResponseContent", Description = "公众平台回复信息", ConnName = "dbconn", DbType = DatabaseType.SqlServer)] + public partial class WeixinResponseContent : IWeixinResponseContent + { + #region 属性 + private Int32 _Id; + /// 编号 + [DisplayName("编号")] + [Description("编号")] + [DataObjectField(true, true, false, 0)] + [BindColumn("Id", "编号", "")] + public Int32 Id { get { return _Id; } set { if (OnPropertyChanging(__.Id, value)) { _Id = value; OnPropertyChanged(__.Id); } } } + + private String _OpenId; + /// 用户OpenId + [DisplayName("用户OpenId")] + [Description("用户OpenId")] + [DataObjectField(false, false, true, 50)] + [BindColumn("OpenId", "用户OpenId", "")] + public String OpenId { get { return _OpenId; } set { if (OnPropertyChanging(__.OpenId, value)) { _OpenId = value; OnPropertyChanged(__.OpenId); } } } + + private String _RequestType; + /// 请求类型 + [DisplayName("请求类型")] + [Description("请求类型")] + [DataObjectField(false, false, true, 50)] + [BindColumn("RequestType", "请求类型", "")] + public String RequestType { get { return _RequestType; } set { if (OnPropertyChanging(__.RequestType, value)) { _RequestType = value; OnPropertyChanged(__.RequestType); } } } + + private String _RequestContent; + /// 内容 + [DisplayName("内容")] + [Description("内容")] + [DataObjectField(false, false, true, -1)] + [BindColumn("RequestContent", "内容", "")] + public String RequestContent { get { return _RequestContent; } set { if (OnPropertyChanging(__.RequestContent, value)) { _RequestContent = value; OnPropertyChanged(__.RequestContent); } } } + + private String _ResponseType; + /// 回复的类型 文本消息:text 图片消息:image 地理位置消息:location 链接消息:link + [DisplayName("回复的类型文本消息:text图片消息:image地理位置消息:location链接消息:link")] + [Description("回复的类型 文本消息:text 图片消息:image 地理位置消息:location 链接消息:link")] + [DataObjectField(false, false, true, 50)] + [BindColumn("ResponseType", "回复的类型 文本消息:text 图片消息:image 地理位置消息:location 链接消息:link", "")] + public String ResponseType { get { return _ResponseType; } set { if (OnPropertyChanging(__.ResponseType, value)) { _ResponseType = value; OnPropertyChanged(__.ResponseType); } } } + + private String _ReponseContent; + /// 系统回复的内容 + [DisplayName("系统回复的内容")] + [Description("系统回复的内容")] + [DataObjectField(false, false, true, -1)] + [BindColumn("ReponseContent", "系统回复的内容", "")] + public String ReponseContent { get { return _ReponseContent; } set { if (OnPropertyChanging(__.ReponseContent, value)) { _ReponseContent = value; OnPropertyChanged(__.ReponseContent); } } } + + private String _XmlContent; + /// xml原始内容 + [DisplayName("xml原始内容")] + [Description("xml原始内容")] + [DataObjectField(false, false, true, -1)] + [BindColumn("XmlContent", "xml原始内容", "")] + public String XmlContent { get { return _XmlContent; } set { if (OnPropertyChanging(__.XmlContent, value)) { _XmlContent = value; OnPropertyChanged(__.XmlContent); } } } + + private DateTime _UpdateTime; + /// 修改时间 + [DisplayName("修改时间")] + [Description("修改时间")] + [DataObjectField(false, false, true, 0)] + [BindColumn("UpdateTime", "修改时间", "")] + public DateTime UpdateTime { get { return _UpdateTime; } set { if (OnPropertyChanging(__.UpdateTime, value)) { _UpdateTime = value; OnPropertyChanged(__.UpdateTime); } } } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + public override Object this[String name] + { + get + { + switch (name) + { + case __.Id : return _Id; + case __.OpenId : return _OpenId; + case __.RequestType : return _RequestType; + case __.RequestContent : return _RequestContent; + case __.ResponseType : return _ResponseType; + case __.ReponseContent : return _ReponseContent; + case __.XmlContent : return _XmlContent; + case __.UpdateTime : return _UpdateTime; + default: return base[name]; + } + } + set + { + switch (name) + { + case __.Id : _Id = value.ToInt(); break; + case __.OpenId : _OpenId = Convert.ToString(value); break; + case __.RequestType : _RequestType = Convert.ToString(value); break; + case __.RequestContent : _RequestContent = Convert.ToString(value); break; + case __.ResponseType : _ResponseType = Convert.ToString(value); break; + case __.ReponseContent : _ReponseContent = Convert.ToString(value); break; + case __.XmlContent : _XmlContent = Convert.ToString(value); break; + case __.UpdateTime : _UpdateTime = value.ToDateTime(); break; + default: base[name] = value; break; + } + } + } + #endregion + + #region 字段名 + /// 取得公众平台回复信息字段信息的快捷方式 + public partial class _ + { + /// 编号 + public static readonly Field Id = FindByName(__.Id); + + /// 用户OpenId + public static readonly Field OpenId = FindByName(__.OpenId); + + /// 请求类型 + public static readonly Field RequestType = FindByName(__.RequestType); + + /// 内容 + public static readonly Field RequestContent = FindByName(__.RequestContent); + + /// 回复的类型 文本消息:text 图片消息:image 地理位置消息:location 链接消息:link + public static readonly Field ResponseType = FindByName(__.ResponseType); + + /// 系统回复的内容 + public static readonly Field ReponseContent = FindByName(__.ReponseContent); + + /// xml原始内容 + public static readonly Field XmlContent = FindByName(__.XmlContent); + + /// 修改时间 + public static readonly Field UpdateTime = FindByName(__.UpdateTime); + + static Field FindByName(String name) { return Meta.Table.FindByName(name); } + } + + /// 取得公众平台回复信息字段名称的快捷方式 + public partial class __ + { + /// 编号 + public const String Id = "Id"; + + /// 用户OpenId + public const String OpenId = "OpenId"; + + /// 请求类型 + public const String RequestType = "RequestType"; + + /// 内容 + public const String RequestContent = "RequestContent"; + + /// 回复的类型 文本消息:text 图片消息:image 地理位置消息:location 链接消息:link + public const String ResponseType = "ResponseType"; + + /// 系统回复的内容 + public const String ReponseContent = "ReponseContent"; + + /// xml原始内容 + public const String XmlContent = "XmlContent"; + + /// 修改时间 + public const String UpdateTime = "UpdateTime"; + } + #endregion + } + + /// 公众平台回复信息接口 + public partial interface IWeixinResponseContent + { + #region 属性 + /// 编号 + Int32 Id { get; set; } + + /// 用户OpenId + String OpenId { get; set; } + + /// 请求类型 + String RequestType { get; set; } + + /// 内容 + String RequestContent { get; set; } + + /// 回复的类型 文本消息:text 图片消息:image 地理位置消息:location 链接消息:link + String ResponseType { get; set; } + + /// 系统回复的内容 + String ReponseContent { get; set; } + + /// xml原始内容 + String XmlContent { get; set; } + + /// 修改时间 + DateTime UpdateTime { get; set; } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + Object this[String name] { get; set; } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Core/Weixin/微信公众号回复规则.Biz.cs b/COMCMS.Core/Weixin/微信公众号回复规则.Biz.cs new file mode 100644 index 0000000..f98b29d --- /dev/null +++ b/COMCMS.Core/Weixin/微信公众号回复规则.Biz.cs @@ -0,0 +1,235 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Xml.Serialization; +using NewLife; +using NewLife.Data; +using NewLife.Log; +using NewLife.Model; +using NewLife.Reflection; +using NewLife.Threading; +using NewLife.Web; +using XCode; +using XCode.Cache; +using XCode.Configuration; +using XCode.DataAccessLayer; +using XCode.Membership; + +namespace COMCMS.Core +{ + /// 微信公众号回复规则 + public partial class WeixinRequestRule : Entity + { + #region 对象操作 + static WeixinRequestRule() + { + // 累加字段 + //var df = Meta.Factory.AdditionalFields; + //df.Add(__.RequestType); + + // 过滤器 UserModule、TimeModule、IPModule + Meta.Modules.Add(); + } + + /// 验证数据,通过抛出异常的方式提示验证失败。 + /// 是否插入 + public override void Valid(Boolean isNew) + { + // 如果没有脏数据,则不需要进行任何处理 + if (!HasDirty) return; + + // 在新插入数据或者修改了指定字段时进行修正 + //if (!Dirtys[nameof(UpdateTime)]) UpdateTime = DateTime.Now; + } + + ///// 首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法 + //[EditorBrowsable(EditorBrowsableState.Never)] + //protected override void InitData() + //{ + // // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用 + // if (Meta.Session.Count > 0) return; + + // if (XTrace.Debug) XTrace.WriteLine("开始初始化WeixinRequestRule[微信公众号回复规则]数据……"); + + // var entity = new WeixinRequestRule(); + // entity.Id = 0; + // entity.RuleName = "abc"; + // entity.Keywords = "abc"; + // entity.RequestType = 0; + // entity.ResponseType = 0; + // entity.IsLikeQuery = 0; + // entity.IsDefault = 0; + // entity.Rank = 0; + // entity.AddTime = DateTime.Now; + // entity.UpdateTime = DateTime.Now; + // entity.Insert(); + + // if (XTrace.Debug) XTrace.WriteLine("完成初始化WeixinRequestRule[微信公众号回复规则]数据!"); + //} + + ///// 已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert + ///// + //public override Int32 Insert() + //{ + // return base.Insert(); + //} + + ///// 已重载。在事务保护范围内处理业务,位于Valid之后 + ///// + //protected override Int32 OnDelete() + //{ + // return base.OnDelete(); + //} + #endregion + + #region 扩展属性 + private IList _ListContent; + /// + /// 详细规则列表 + /// + public IList ListContent + { + get + { + if (_ListContent == null && Id > 0 && !Dirtys["ListWechatRequestContent_" + Id]) + { + _ListContent = WeixinRequestContent.FindAll(WeixinRequestContent._.RuleId == Id, WeixinRequestContent._.Rank.Asc(), null, 0, 0); + + Dirtys["ListWechatRequestContent_" + Id] = true; + } + return _ListContent; + } + set { _ListContent = value; } + } + #endregion + + #region 扩展查询 + /// 根据编号查找 + /// 编号 + /// 实体对象 + public static WeixinRequestRule FindById(Int32 id) + { + if (id <= 0) return null; + + // 实体缓存 + if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id); + + // 单对象缓存 + return Meta.SingleCache[id]; + + //return Find(_.Id == id); + } + #endregion + + #region 高级查询 + #endregion + + #region 业务操作 + #endregion + + #region 业务 + /// + /// 微信请求类型 + /// 0默认回复1文字2图片3语音4链接5地理位置6关注7取消关注8扫描带参数二维码事件9上报地理位置事件10自定义菜单事件 + /// + public enum XRequestType + { + /// 默认回复 + Default = 0, + /// + /// 文本请求 + /// + Text = 1, + /// + /// 图片 + /// + Image = 2, + /// + /// 语音 + /// + Voice = 3, + /// + /// 链接 + /// + Link = 4, + /// + /// 地理位置 + /// + Location = 5, + /// + /// 关注 + /// + Flow = 6, + /// + /// 取消关注 + /// + Unflow = 7, + /// + /// 扫描二维码 + /// + Scan = 8, + /// + /// 上报地理位置 + /// + ReportingLocation = 9, + /// + /// 自定义菜单 + /// + CustomMenu = 10, + /// + /// 没找到关键字 + /// + NotFindKeyword = 11 + } + /// + /// 回复类型 + /// + public enum XResponseType + { + /// + /// 文本 + /// + Text = 0, + /// + /// 地理位置 + /// + Location = 1, + /// + /// 图片 + /// + Image = 2, + /// + /// 语音 + /// + Voice = 3, + /// + /// 视频 + /// + Video = 4, + /// + /// 链接 + /// + Link = 5, + /// + /// 短片 + /// + ShortVideo = 6, + /// + /// 自定义事件 + /// + Event = 7, + /// + /// 单张图片 + /// + SingleImage = 8, + } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Core/Weixin/微信公众号回复规则.cs b/COMCMS.Core/Weixin/微信公众号回复规则.cs new file mode 100644 index 0000000..0034813 --- /dev/null +++ b/COMCMS.Core/Weixin/微信公众号回复规则.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using XCode; +using XCode.Configuration; +using XCode.DataAccessLayer; + +namespace COMCMS.Core +{ + /// 微信公众号回复规则 + [Serializable] + [DataObject] + [Description("微信公众号回复规则")] + [BindTable("WeixinRequestRule", Description = "微信公众号回复规则", ConnName = "dbconn", DbType = DatabaseType.SqlServer)] + public partial class WeixinRequestRule : IWeixinRequestRule + { + #region 属性 + private Int32 _Id; + /// 编号 + [DisplayName("编号")] + [Description("编号")] + [DataObjectField(true, true, false, 0)] + [BindColumn("Id", "编号", "")] + public Int32 Id { get { return _Id; } set { if (OnPropertyChanging(__.Id, value)) { _Id = value; OnPropertyChanged(__.Id); } } } + + private String _RuleName; + /// 规则名称 + [DisplayName("规则名称")] + [Description("规则名称")] + [DataObjectField(false, false, true, 50)] + [BindColumn("RuleName", "规则名称", "")] + public String RuleName { get { return _RuleName; } set { if (OnPropertyChanging(__.RuleName, value)) { _RuleName = value; OnPropertyChanged(__.RuleName); } } } + + private String _Keywords; + /// 请求关键词,逗号分隔 + [DisplayName("请求关键词")] + [Description("请求关键词,逗号分隔")] + [DataObjectField(false, false, true, 200)] + [BindColumn("Keywords", "请求关键词,逗号分隔", "")] + public String Keywords { get { return _Keywords; } set { if (OnPropertyChanging(__.Keywords, value)) { _Keywords = value; OnPropertyChanged(__.Keywords); } } } + + private Int32 _RequestType; + /// 请求类型(0默认回复1文字2图片3语音4链接5地理位置6关注7取消关注8扫描带参数二维码事件9上报地理位置事件10自定义菜单事件) + [DisplayName("请求类型")] + [Description("请求类型(0默认回复1文字2图片3语音4链接5地理位置6关注7取消关注8扫描带参数二维码事件9上报地理位置事件10自定义菜单事件)")] + [DataObjectField(false, false, false, 0)] + [BindColumn("RequestType", "请求类型(0默认回复1文字2图片3语音4链接5地理位置6关注7取消关注8扫描带参数二维码事件9上报地理位置事件10自定义菜单事件)", "")] + public Int32 RequestType { get { return _RequestType; } set { if (OnPropertyChanging(__.RequestType, value)) { _RequestType = value; OnPropertyChanged(__.RequestType); } } } + + private Int32 _ResponseType; + /// 回复类型(1文本2图文3语音4视频5第三方接口) + [DisplayName("回复类型")] + [Description("回复类型(1文本2图文3语音4视频5第三方接口)")] + [DataObjectField(false, false, false, 0)] + [BindColumn("ResponseType", "回复类型(1文本2图文3语音4视频5第三方接口)", "")] + public Int32 ResponseType { get { return _ResponseType; } set { if (OnPropertyChanging(__.ResponseType, value)) { _ResponseType = value; OnPropertyChanged(__.ResponseType); } } } + + private Int32 _IsLikeQuery; + /// 是否模糊查询 0 是完全匹配;1是模糊匹配 + [DisplayName("是否模糊查询0是完全匹配;1是模糊匹配")] + [Description("是否模糊查询 0 是完全匹配;1是模糊匹配")] + [DataObjectField(false, false, false, 0)] + [BindColumn("IsLikeQuery", "是否模糊查询 0 是完全匹配;1是模糊匹配", "")] + public Int32 IsLikeQuery { get { return _IsLikeQuery; } set { if (OnPropertyChanging(__.IsLikeQuery, value)) { _IsLikeQuery = value; OnPropertyChanged(__.IsLikeQuery); } } } + + private Int32 _IsDefault; + /// 是否是默认回复 + [DisplayName("是否是默认回复")] + [Description("是否是默认回复")] + [DataObjectField(false, false, false, 0)] + [BindColumn("IsDefault", "是否是默认回复", "")] + public Int32 IsDefault { get { return _IsDefault; } set { if (OnPropertyChanging(__.IsDefault, value)) { _IsDefault = value; OnPropertyChanged(__.IsDefault); } } } + + private Int32 _Rank; + /// 排序 + [DisplayName("排序")] + [Description("排序")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Rank", "排序", "")] + public Int32 Rank { get { return _Rank; } set { if (OnPropertyChanging(__.Rank, value)) { _Rank = value; OnPropertyChanged(__.Rank); } } } + + private DateTime _AddTime; + /// 添加时间 + [DisplayName("添加时间")] + [Description("添加时间")] + [DataObjectField(false, false, true, 0)] + [BindColumn("AddTime", "添加时间", "")] + public DateTime AddTime { get { return _AddTime; } set { if (OnPropertyChanging(__.AddTime, value)) { _AddTime = value; OnPropertyChanged(__.AddTime); } } } + + private DateTime _UpdateTime; + /// 修改时间 + [DisplayName("修改时间")] + [Description("修改时间")] + [DataObjectField(false, false, true, 0)] + [BindColumn("UpdateTime", "修改时间", "")] + public DateTime UpdateTime { get { return _UpdateTime; } set { if (OnPropertyChanging(__.UpdateTime, value)) { _UpdateTime = value; OnPropertyChanged(__.UpdateTime); } } } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + public override Object this[String name] + { + get + { + switch (name) + { + case __.Id : return _Id; + case __.RuleName : return _RuleName; + case __.Keywords : return _Keywords; + case __.RequestType : return _RequestType; + case __.ResponseType : return _ResponseType; + case __.IsLikeQuery : return _IsLikeQuery; + case __.IsDefault : return _IsDefault; + case __.Rank : return _Rank; + case __.AddTime : return _AddTime; + case __.UpdateTime : return _UpdateTime; + default: return base[name]; + } + } + set + { + switch (name) + { + case __.Id : _Id = value.ToInt(); break; + case __.RuleName : _RuleName = Convert.ToString(value); break; + case __.Keywords : _Keywords = Convert.ToString(value); break; + case __.RequestType : _RequestType = value.ToInt(); break; + case __.ResponseType : _ResponseType = value.ToInt(); break; + case __.IsLikeQuery : _IsLikeQuery = value.ToInt(); break; + case __.IsDefault : _IsDefault = value.ToInt(); break; + case __.Rank : _Rank = value.ToInt(); break; + case __.AddTime : _AddTime = value.ToDateTime(); break; + case __.UpdateTime : _UpdateTime = value.ToDateTime(); break; + default: base[name] = value; break; + } + } + } + #endregion + + #region 字段名 + /// 取得微信公众号回复规则字段信息的快捷方式 + public partial class _ + { + /// 编号 + public static readonly Field Id = FindByName(__.Id); + + /// 规则名称 + public static readonly Field RuleName = FindByName(__.RuleName); + + /// 请求关键词,逗号分隔 + public static readonly Field Keywords = FindByName(__.Keywords); + + /// 请求类型(0默认回复1文字2图片3语音4链接5地理位置6关注7取消关注8扫描带参数二维码事件9上报地理位置事件10自定义菜单事件) + public static readonly Field RequestType = FindByName(__.RequestType); + + /// 回复类型(1文本2图文3语音4视频5第三方接口) + public static readonly Field ResponseType = FindByName(__.ResponseType); + + /// 是否模糊查询 0 是完全匹配;1是模糊匹配 + public static readonly Field IsLikeQuery = FindByName(__.IsLikeQuery); + + /// 是否是默认回复 + public static readonly Field IsDefault = FindByName(__.IsDefault); + + /// 排序 + public static readonly Field Rank = FindByName(__.Rank); + + /// 添加时间 + public static readonly Field AddTime = FindByName(__.AddTime); + + /// 修改时间 + public static readonly Field UpdateTime = FindByName(__.UpdateTime); + + static Field FindByName(String name) { return Meta.Table.FindByName(name); } + } + + /// 取得微信公众号回复规则字段名称的快捷方式 + public partial class __ + { + /// 编号 + public const String Id = "Id"; + + /// 规则名称 + public const String RuleName = "RuleName"; + + /// 请求关键词,逗号分隔 + public const String Keywords = "Keywords"; + + /// 请求类型(0默认回复1文字2图片3语音4链接5地理位置6关注7取消关注8扫描带参数二维码事件9上报地理位置事件10自定义菜单事件) + public const String RequestType = "RequestType"; + + /// 回复类型(1文本2图文3语音4视频5第三方接口) + public const String ResponseType = "ResponseType"; + + /// 是否模糊查询 0 是完全匹配;1是模糊匹配 + public const String IsLikeQuery = "IsLikeQuery"; + + /// 是否是默认回复 + public const String IsDefault = "IsDefault"; + + /// 排序 + public const String Rank = "Rank"; + + /// 添加时间 + public const String AddTime = "AddTime"; + + /// 修改时间 + public const String UpdateTime = "UpdateTime"; + } + #endregion + } + + /// 微信公众号回复规则接口 + public partial interface IWeixinRequestRule + { + #region 属性 + /// 编号 + Int32 Id { get; set; } + + /// 规则名称 + String RuleName { get; set; } + + /// 请求关键词,逗号分隔 + String Keywords { get; set; } + + /// 请求类型(0默认回复1文字2图片3语音4链接5地理位置6关注7取消关注8扫描带参数二维码事件9上报地理位置事件10自定义菜单事件) + Int32 RequestType { get; set; } + + /// 回复类型(1文本2图文3语音4视频5第三方接口) + Int32 ResponseType { get; set; } + + /// 是否模糊查询 0 是完全匹配;1是模糊匹配 + Int32 IsLikeQuery { get; set; } + + /// 是否是默认回复 + Int32 IsDefault { get; set; } + + /// 排序 + Int32 Rank { get; set; } + + /// 添加时间 + DateTime AddTime { get; set; } + + /// 修改时间 + DateTime UpdateTime { get; set; } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + Object this[String name] { get; set; } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Core/Weixin/请求回复的内容.Biz.cs b/COMCMS.Core/Weixin/请求回复的内容.Biz.cs new file mode 100644 index 0000000..07ab3a0 --- /dev/null +++ b/COMCMS.Core/Weixin/请求回复的内容.Biz.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Xml.Serialization; +using NewLife; +using NewLife.Data; +using NewLife.Log; +using NewLife.Model; +using NewLife.Reflection; +using NewLife.Threading; +using NewLife.Web; +using XCode; +using XCode.Cache; +using XCode.Configuration; +using XCode.DataAccessLayer; +using XCode.Membership; + +namespace COMCMS.Core +{ + /// 请求回复的内容 + public partial class WeixinRequestContent : Entity + { + #region 对象操作 + static WeixinRequestContent() + { + // 累加字段 + //var df = Meta.Factory.AdditionalFields; + //df.Add(__.RuleId); + + // 过滤器 UserModule、TimeModule、IPModule + Meta.Modules.Add(); + } + + /// 验证数据,通过抛出异常的方式提示验证失败。 + /// 是否插入 + public override void Valid(Boolean isNew) + { + // 如果没有脏数据,则不需要进行任何处理 + if (!HasDirty) return; + + // 在新插入数据或者修改了指定字段时进行修正 + //if (!Dirtys[nameof(UpdateTime)]) UpdateTime = DateTime.Now; + } + + ///// 首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法 + //[EditorBrowsable(EditorBrowsableState.Never)] + //protected override void InitData() + //{ + // // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用 + // if (Meta.Session.Count > 0) return; + + // if (XTrace.Debug) XTrace.WriteLine("开始初始化WeixinRequestContent[请求回复的内容]数据……"); + + // var entity = new WeixinRequestContent(); + // entity.Id = 0; + // entity.RuleId = 0; + // entity.Title = "abc"; + // entity.Content = "abc"; + // entity.LinkUrl = "abc"; + // entity.ImgURL = "abc"; + // entity.MediaURL = "abc"; + // entity.MeidaHdURL = "abc"; + // entity.MediaID = "abc"; + // entity.WXAppAppId = "abc"; + // entity.WXAppPage = "abc"; + // entity.Rank = 0; + // entity.AddTime = DateTime.Now; + // entity.UpdateTime = DateTime.Now; + // entity.Insert(); + + // if (XTrace.Debug) XTrace.WriteLine("完成初始化WeixinRequestContent[请求回复的内容]数据!"); + //} + + ///// 已重载。基类先调用Valid(true)验证数据,然后在事务保护内调用OnInsert + ///// + //public override Int32 Insert() + //{ + // return base.Insert(); + //} + + ///// 已重载。在事务保护范围内处理业务,位于Valid之后 + ///// + //protected override Int32 OnDelete() + //{ + // return base.OnDelete(); + //} + #endregion + + #region 扩展属性 + #endregion + + #region 扩展查询 + /// 根据编号查找 + /// 编号 + /// 实体对象 + public static WeixinRequestContent FindById(Int32 id) + { + if (id <= 0) return null; + + // 实体缓存 + if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id); + + // 单对象缓存 + return Meta.SingleCache[id]; + + //return Find(_.Id == id); + } + #endregion + + #region 高级查询 + #endregion + + #region 业务操作 + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Core/Weixin/请求回复的内容.cs b/COMCMS.Core/Weixin/请求回复的内容.cs new file mode 100644 index 0000000..552c085 --- /dev/null +++ b/COMCMS.Core/Weixin/请求回复的内容.cs @@ -0,0 +1,333 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using XCode; +using XCode.Configuration; +using XCode.DataAccessLayer; + +namespace COMCMS.Core +{ + /// 请求回复的内容 + [Serializable] + [DataObject] + [Description("请求回复的内容")] + [BindTable("WeixinRequestContent", Description = "请求回复的内容", ConnName = "dbconn", DbType = DatabaseType.SqlServer)] + public partial class WeixinRequestContent : IWeixinRequestContent + { + #region 属性 + private Int32 _Id; + /// 编号 + [DisplayName("编号")] + [Description("编号")] + [DataObjectField(true, true, false, 0)] + [BindColumn("Id", "编号", "")] + public Int32 Id { get { return _Id; } set { if (OnPropertyChanging(__.Id, value)) { _Id = value; OnPropertyChanged(__.Id); } } } + + private Int32 _RuleId; + /// 规则名称 + [DisplayName("规则名称")] + [Description("规则名称")] + [DataObjectField(false, false, false, 0)] + [BindColumn("RuleId", "规则名称", "")] + public Int32 RuleId { get { return _RuleId; } set { if (OnPropertyChanging(__.RuleId, value)) { _RuleId = value; OnPropertyChanged(__.RuleId); } } } + + private String _Title; + /// 回复标题 + [DisplayName("回复标题")] + [Description("回复标题")] + [DataObjectField(false, false, true, 250)] + [BindColumn("Title", "回复标题", "", Master = true)] + public String Title { get { return _Title; } set { if (OnPropertyChanging(__.Title, value)) { _Title = value; OnPropertyChanged(__.Title); } } } + + private String _Content; + /// 回复内容 + [DisplayName("回复内容")] + [Description("回复内容")] + [DataObjectField(false, false, true, -1)] + [BindColumn("Content", "回复内容", "")] + public String Content { get { return _Content; } set { if (OnPropertyChanging(__.Content, value)) { _Content = value; OnPropertyChanged(__.Content); } } } + + private String _LinkUrl; + /// 详情链接地址 + [DisplayName("详情链接地址")] + [Description("详情链接地址")] + [DataObjectField(false, false, true, 250)] + [BindColumn("LinkUrl", "详情链接地址", "")] + public String LinkUrl { get { return _LinkUrl; } set { if (OnPropertyChanging(__.LinkUrl, value)) { _LinkUrl = value; OnPropertyChanged(__.LinkUrl); } } } + + private String _ImgURL; + /// 图片地址 + [DisplayName("图片地址")] + [Description("图片地址")] + [DataObjectField(false, false, true, 250)] + [BindColumn("ImgURL", "图片地址", "")] + public String ImgURL { get { return _ImgURL; } set { if (OnPropertyChanging(__.ImgURL, value)) { _ImgURL = value; OnPropertyChanged(__.ImgURL); } } } + + private String _MediaURL; + /// 语音或视频地址 + [DisplayName("语音或视频地址")] + [Description("语音或视频地址")] + [DataObjectField(false, false, true, 250)] + [BindColumn("MediaURL", "语音或视频地址", "")] + public String MediaURL { get { return _MediaURL; } set { if (OnPropertyChanging(__.MediaURL, value)) { _MediaURL = value; OnPropertyChanged(__.MediaURL); } } } + + private String _MeidaHdURL; + /// 高清语音或者视频地址 + [DisplayName("高清语音或者视频地址")] + [Description("高清语音或者视频地址")] + [DataObjectField(false, false, true, 250)] + [BindColumn("MeidaHdURL", "高清语音或者视频地址", "")] + public String MeidaHdURL { get { return _MeidaHdURL; } set { if (OnPropertyChanging(__.MeidaHdURL, value)) { _MeidaHdURL = value; OnPropertyChanged(__.MeidaHdURL); } } } + + private String _MediaID; + /// 返回的素材ID + [DisplayName("返回的素材ID")] + [Description("返回的素材ID")] + [DataObjectField(false, false, true, 100)] + [BindColumn("MediaID", "返回的素材ID", "")] + public String MediaID { get { return _MediaID; } set { if (OnPropertyChanging(__.MediaID, value)) { _MediaID = value; OnPropertyChanged(__.MediaID); } } } + + private String _WXAppAppId; + /// 小程序APPId + [DisplayName("小程序APPId")] + [Description("小程序APPId")] + [DataObjectField(false, false, true, 100)] + [BindColumn("WXAppAppId", "小程序APPId", "")] + public String WXAppAppId { get { return _WXAppAppId; } set { if (OnPropertyChanging(__.WXAppAppId, value)) { _WXAppAppId = value; OnPropertyChanged(__.WXAppAppId); } } } + + private String _WXAppPage; + /// 小程序页面 + [DisplayName("小程序页面")] + [Description("小程序页面")] + [DataObjectField(false, false, true, 100)] + [BindColumn("WXAppPage", "小程序页面", "")] + public String WXAppPage { get { return _WXAppPage; } set { if (OnPropertyChanging(__.WXAppPage, value)) { _WXAppPage = value; OnPropertyChanged(__.WXAppPage); } } } + + private Int32 _Rank; + /// 排序 + [DisplayName("排序")] + [Description("排序")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Rank", "排序", "")] + public Int32 Rank { get { return _Rank; } set { if (OnPropertyChanging(__.Rank, value)) { _Rank = value; OnPropertyChanged(__.Rank); } } } + + private DateTime _AddTime; + /// 添加时间 + [DisplayName("添加时间")] + [Description("添加时间")] + [DataObjectField(false, false, true, 0)] + [BindColumn("AddTime", "添加时间", "")] + public DateTime AddTime { get { return _AddTime; } set { if (OnPropertyChanging(__.AddTime, value)) { _AddTime = value; OnPropertyChanged(__.AddTime); } } } + + private DateTime _UpdateTime; + /// 修改时间 + [DisplayName("修改时间")] + [Description("修改时间")] + [DataObjectField(false, false, true, 0)] + [BindColumn("UpdateTime", "修改时间", "")] + public DateTime UpdateTime { get { return _UpdateTime; } set { if (OnPropertyChanging(__.UpdateTime, value)) { _UpdateTime = value; OnPropertyChanged(__.UpdateTime); } } } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + public override Object this[String name] + { + get + { + switch (name) + { + case __.Id : return _Id; + case __.RuleId : return _RuleId; + case __.Title : return _Title; + case __.Content : return _Content; + case __.LinkUrl : return _LinkUrl; + case __.ImgURL : return _ImgURL; + case __.MediaURL : return _MediaURL; + case __.MeidaHdURL : return _MeidaHdURL; + case __.MediaID : return _MediaID; + case __.WXAppAppId : return _WXAppAppId; + case __.WXAppPage : return _WXAppPage; + case __.Rank : return _Rank; + case __.AddTime : return _AddTime; + case __.UpdateTime : return _UpdateTime; + default: return base[name]; + } + } + set + { + switch (name) + { + case __.Id : _Id = value.ToInt(); break; + case __.RuleId : _RuleId = value.ToInt(); break; + case __.Title : _Title = Convert.ToString(value); break; + case __.Content : _Content = Convert.ToString(value); break; + case __.LinkUrl : _LinkUrl = Convert.ToString(value); break; + case __.ImgURL : _ImgURL = Convert.ToString(value); break; + case __.MediaURL : _MediaURL = Convert.ToString(value); break; + case __.MeidaHdURL : _MeidaHdURL = Convert.ToString(value); break; + case __.MediaID : _MediaID = Convert.ToString(value); break; + case __.WXAppAppId : _WXAppAppId = Convert.ToString(value); break; + case __.WXAppPage : _WXAppPage = Convert.ToString(value); break; + case __.Rank : _Rank = value.ToInt(); break; + case __.AddTime : _AddTime = value.ToDateTime(); break; + case __.UpdateTime : _UpdateTime = value.ToDateTime(); break; + default: base[name] = value; break; + } + } + } + #endregion + + #region 字段名 + /// 取得请求回复的内容字段信息的快捷方式 + public partial class _ + { + /// 编号 + public static readonly Field Id = FindByName(__.Id); + + /// 规则名称 + public static readonly Field RuleId = FindByName(__.RuleId); + + /// 回复标题 + public static readonly Field Title = FindByName(__.Title); + + /// 回复内容 + public static readonly Field Content = FindByName(__.Content); + + /// 详情链接地址 + public static readonly Field LinkUrl = FindByName(__.LinkUrl); + + /// 图片地址 + public static readonly Field ImgURL = FindByName(__.ImgURL); + + /// 语音或视频地址 + public static readonly Field MediaURL = FindByName(__.MediaURL); + + /// 高清语音或者视频地址 + public static readonly Field MeidaHdURL = FindByName(__.MeidaHdURL); + + /// 返回的素材ID + public static readonly Field MediaID = FindByName(__.MediaID); + + /// 小程序APPId + public static readonly Field WXAppAppId = FindByName(__.WXAppAppId); + + /// 小程序页面 + public static readonly Field WXAppPage = FindByName(__.WXAppPage); + + /// 排序 + public static readonly Field Rank = FindByName(__.Rank); + + /// 添加时间 + public static readonly Field AddTime = FindByName(__.AddTime); + + /// 修改时间 + public static readonly Field UpdateTime = FindByName(__.UpdateTime); + + static Field FindByName(String name) { return Meta.Table.FindByName(name); } + } + + /// 取得请求回复的内容字段名称的快捷方式 + public partial class __ + { + /// 编号 + public const String Id = "Id"; + + /// 规则名称 + public const String RuleId = "RuleId"; + + /// 回复标题 + public const String Title = "Title"; + + /// 回复内容 + public const String Content = "Content"; + + /// 详情链接地址 + public const String LinkUrl = "LinkUrl"; + + /// 图片地址 + public const String ImgURL = "ImgURL"; + + /// 语音或视频地址 + public const String MediaURL = "MediaURL"; + + /// 高清语音或者视频地址 + public const String MeidaHdURL = "MeidaHdURL"; + + /// 返回的素材ID + public const String MediaID = "MediaID"; + + /// 小程序APPId + public const String WXAppAppId = "WXAppAppId"; + + /// 小程序页面 + public const String WXAppPage = "WXAppPage"; + + /// 排序 + public const String Rank = "Rank"; + + /// 添加时间 + public const String AddTime = "AddTime"; + + /// 修改时间 + public const String UpdateTime = "UpdateTime"; + } + #endregion + } + + /// 请求回复的内容接口 + public partial interface IWeixinRequestContent + { + #region 属性 + /// 编号 + Int32 Id { get; set; } + + /// 规则名称 + Int32 RuleId { get; set; } + + /// 回复标题 + String Title { get; set; } + + /// 回复内容 + String Content { get; set; } + + /// 详情链接地址 + String LinkUrl { get; set; } + + /// 图片地址 + String ImgURL { get; set; } + + /// 语音或视频地址 + String MediaURL { get; set; } + + /// 高清语音或者视频地址 + String MeidaHdURL { get; set; } + + /// 返回的素材ID + String MediaID { get; set; } + + /// 小程序APPId + String WXAppAppId { get; set; } + + /// 小程序页面 + String WXAppPage { get; set; } + + /// 排序 + Int32 Rank { get; set; } + + /// 添加时间 + DateTime AddTime { get; set; } + + /// 修改时间 + DateTime UpdateTime { get; set; } + #endregion + + #region 获取/设置 字段值 + /// 获取/设置 字段值 + /// 字段名 + /// + Object this[String name] { get; set; } + #endregion + } +} \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs index 1113862..9074c0c 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs @@ -32,7 +32,6 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers Admin admin = Admin.GetMyInfo(); ViewBag.admin = admin; - //获取菜单 List list = new List(); //这里需要获取权限,暂时先所有 diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs index 3c0dc97..536d6d7 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs @@ -391,7 +391,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers { return Content("系统找不到本日志文件!"); } - XTrace.WriteLine("查看日志:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //XTrace.WriteLine("查看日志:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); IFileProvider fileProvider = new PhysicalFileProvider(logPath); StringBuilder detail = new StringBuilder(); diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/WeixinController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/WeixinController.cs index 1927793..1584cf2 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/WeixinController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/WeixinController.cs @@ -10,6 +10,12 @@ using XCode; using Newtonsoft.Json; using COMCMS.Web.Common; using Microsoft.AspNetCore.Http; +using Senparc.Weixin.MP.Entities; +using NewLife.Log; +using Senparc.Weixin.MP.Containers; +using Senparc.Weixin.MP.Entities.Menu; +using System.IO; +using System.Text; namespace COMCMS.Web.Areas.AdminCP.Controllers { @@ -17,9 +23,1111 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers [Description("微信公众号系统,包括关注自动回复、自定义菜单、关键字回复")] public class WeixinController : AdminBaseController { - public IActionResult Index() + + #region 自定义菜单 + //自定义菜单 + [MyAuthorize("view", "wxmenu")] + [HttpGet] + public IActionResult Menu() + { + + Config cfg = Config.GetSystemConfig(); + if(string.IsNullOrEmpty(cfg.AppId) || string.IsNullOrEmpty(cfg.AppSecret)) + { + return EchoTipPage("请先到【系统设置】> 【基本设置】 设置公众号AppId和AppSecret!"); + } + string accessToken = ""; + try + { + accessToken = AccessTokenContainer.TryGetAccessToken(cfg.AppId, cfg.AppSecret); + + } + catch (Exception ex) + { + return EchoTipPage(ex.Message); + } + + if (string.IsNullOrEmpty(accessToken)) + { + return EchoTipPage("AccessToken 获取错误,请确认微信配置没错。或者服务器没加入白名单!"); + } + //XTrace.WriteLine("当前AccessToken:" + accessToken); + //获取菜单 + GetMenuResult result = new GetMenuResult(new ButtonGroup()); + try + { + result = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetMenu(accessToken); + if (result == null) + { + result = new GetMenuResult(new ButtonGroup()); + } + } + catch (Exception ex) + { + result = new GetMenuResult(new ButtonGroup()); + XTrace.WriteLine("获取菜单出错:" + ex.Message); + } + Core.Admin.WriteLogActions("查看公众号菜单;"); + return View(result); + } + //修改菜单 + [HttpPost] + [MyAuthorize("edit", "wxmenu", "JSON")] + public IActionResult DoPostMenuData(string allmenu) + { + + Config cfg = Config.GetSystemConfig(); + string accessToken = ""; + try + { + accessToken = AccessTokenContainer.TryGetAccessToken(cfg.AppId, cfg.AppSecret); + + } + catch (Exception ex) + { + tip.Message = ex.Message; + return Json(tip); + } + + if (string.IsNullOrEmpty(accessToken)) + { + tip.Message = "AccessToken 获取错误,请确认微信配置没错。或者服务器没加入白名单!"; + return Json(tip); + } + if (string.IsNullOrEmpty(allmenu)) + { + tip.Message = "请填写自定义菜单"; + return Json(tip); + } + //Senparc.Weixin.MP.CommonAPIs.CommonApi.CreateMenu() + string posturl = $"https://api.weixin.qq.com/cgi-bin/menu/create?access_token={accessToken}"; + + Stream retunStream = Utils.HttpPost(posturl, allmenu); + + StreamReader reader = new StreamReader(retunStream, Encoding.UTF8); + string value = reader.ReadToEnd(); + + reader.Close(); + + XTrace.WriteLine("创建公众号菜单回传:" + value); + + dynamic rejson = Newtonsoft.Json.Linq.JToken.Parse(value) as dynamic; + if (rejson != null && rejson.errcode == 0) + { + tip.Status = JsonTip.SUCCESS; + tip.Message = "创建/修改公众号菜单成功!"; + return Json(tip); + } + tip.Message = rejson.errmsg; + Core.Admin.WriteLogActions("修改公众号菜单;"); + return Json(tip); + } + #endregion + + #region 关注自动回复 + [HttpGet] + [MyAuthorize("edit", "wxautoreply")] + public IActionResult SubscribeReply() + { + + WeixinRequestRule ruleModel = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.Flow);//获取规则 + if (ruleModel == null) + { + ruleModel = new WeixinRequestRule(); + ruleModel.RequestType = (int)WeixinRequestRule.XRequestType.Flow; + ruleModel.ResponseType = (int)WeixinRequestRule.XResponseType.Text; + ruleModel.RuleName = "关注自动回复"; + ruleModel.IsDefault = 1; + ruleModel.Insert(); + //增加Response + WeixinRequestContent content = new WeixinRequestContent() + { + RuleId = ruleModel.Id, + Content = "关注公众号自动回复文本" + + }; + content.Insert(); + } + switch (ruleModel.ResponseType) + { + case 0://文本 + ViewBag.txtContent = ruleModel.ListContent[0].Content; + break; + case 1://多图 + break; + case 2://语音 + ViewBag.txtSoundTitle = ruleModel.ListContent[0].Title; + ViewBag.txtSoundUrl = ruleModel.ListContent[0].MediaURL; + ViewBag.txtSoundContent = ruleModel.ListContent[0].Content; + break; + case 8://单图 + ViewBag.txtSingleImage = ruleModel.ListContent[0].ImgURL; + break; + } + Admin.WriteLogActions("查看公众号关注自动回复;"); + return View(ruleModel); + } + //编辑自动回复规则 + [HttpPost] + [MyAuthorize("edit", "wxautoreply", "JSON")] + public IActionResult SubscribeReply(WeixinRequestRule entity) + { + WeixinRequestRule model = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.Flow);//获取规则 + model.ResponseType = entity.ResponseType; + + model.IsDefault = 1; + int defaultDetailId = int.Parse(Request.Form["hdfTID"]);//默认一条的ID。肯定至少有一条 + int responseType = model.ResponseType; + IList ls = new List(); + if (responseType == 0) //纯文本 + { + string txtContent = Request.Form["txtContent"]; + if (string.IsNullOrEmpty(txtContent)) + { + tip.Message = "文本回复,文本不能为空!"; + return Json(tip); + } + model.ResponseType = (int)WeixinRequestRule.XResponseType.Text;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 + ls.Add(new WeixinRequestContent { RuleId = model.Id, Content = txtContent.Trim(), Id = defaultDetailId}); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Image) //图文 + { + #region 赋值规则图片 + + string[] itemIdArr = Request.Form["item_id"]; + string[] itemTitleArr = Request.Form["item_title"]; + string[] itemContentArr = Request.Form["item_imginfo"]; + string[] itemImgUrlArr = Request.Form["item_imgurl"]; + string[] itemLinkUrlArr = Request.Form["item_linkurl"]; + if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemLinkUrlArr != null && itemContentArr != null) + { + if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemLinkUrlArr.Length)) + { + + for (int i = 0; i < itemIdArr.Length; i++) + { + if (!string.IsNullOrEmpty(itemTitleArr[i])) + { + WeixinRequestContent modelt = new WeixinRequestContent(); + modelt.Id = Utils.StrToInt(itemIdArr[i].Trim(), 0); + modelt.Title = itemTitleArr[i].Trim(); + modelt.Content = itemContentArr[i].Trim(); + modelt.ImgURL = itemImgUrlArr[i].Trim(); + modelt.LinkUrl = itemLinkUrlArr[i].Trim(); + modelt.RuleId = model.Id; + ls.Add(modelt); + } + } + //model.contents = ls; + } + } + #endregion + if (ls == null || ls.Count < 1) + { + tip.Message = "图文列表,图文项目不能为空!"; + return Json(tip); + } + + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Video) //语音 + { + string txtSoundTitle = Request.Form["txtSoundTitle"]; + if (string.IsNullOrEmpty(txtSoundTitle)) + { + tip.Message = "语音回复,语音标题不能为空!"; + return Json(tip); + } + string txtSoundUrl = Request.Form["txtSoundUrl"]; + if (string.IsNullOrEmpty(txtSoundUrl)) + { + tip.Message = "语音回复,语音地址不能为空!"; + return Json(tip); + } + string txtSoundContent = Request.Form["txtSoundContent"]; + + ls.Add(new WeixinRequestContent { RuleId = model.Id, MediaURL = txtSoundUrl.Trim(), Title = txtSoundTitle, Id = defaultDetailId, Content = txtSoundContent }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.SingleImage) //单图片 + { + string txtSingleImage = Request.Form["txtSingleImage"]; + if (string.IsNullOrEmpty(txtSingleImage)) + { + tip.Message = "单图片回复,图片地址不能为空!"; + return Json(tip); + } + ls.Add(new WeixinRequestContent { RuleId = model.Id, ImgURL = txtSingleImage.Trim(), Id = defaultDetailId}); + } + model.Save(); + IList oldwc = model.ListContent; + if (oldwc != null && oldwc.Count > 0) + { + foreach (WeixinRequestContent p in ls) + { + if (oldwc.Find(s => s.Id == p.Id) != null) + { + oldwc.Remove(oldwc.Find(s => s.Id == p.Id)); + } + } + if (oldwc != null && oldwc.Count > 0) + { + oldwc.Delete(); + } + } + if (ls != null && ls.Count > 0) + { + foreach (var item in ls) + { + item.RuleId = model.Id; + } + } + ls.Save(); + tip.Message = "修改成功!"; + tip.Status = JsonTip.SUCCESS; + //tip.ReturnUrl = "reload"; + Core.Admin.WriteLogActions("修改公众号关注自动回复;"); + return Json(tip); + } + #endregion + + #region 自定义回复规则列表 + //自定义规则 + [MyAuthorize("viewlist", "wxkeywordreply")] + public IActionResult ReplyRule() { return View(); } + //自定义规则列表 + [MyAuthorize("viewlist", "wxkeywordreply")] + public IActionResult GetReplyRuleList(string keyword, int page = 1, int limit = 20) + { + int numPerPage, currentPage, startRowIndex; + + numPerPage = limit; + currentPage = page; + startRowIndex = (currentPage - 1) * numPerPage; + Expression ex = WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.Text; + + if (!string.IsNullOrWhiteSpace(keyword)) + { + if (Utils.IsInt(keyword)) + { + ex &= (WeixinRequestRule._.Id == int.Parse(keyword) | WeixinRequestRule._.Keywords.Contains(keyword)); + } + else + { + ex &= WeixinRequestRule._.Keywords.Contains(keyword); + } + } + + IList list = WeixinRequestRule.FindAll(ex, null, null, startRowIndex, numPerPage); + long totalCount = WeixinRequestRule.FindCount(ex, null, null, startRowIndex, numPerPage); + Admin.WriteLogActions($"查看公众号自定义回复规则({page});"); + return Content(JsonConvert.SerializeObject(new { total = totalCount, rows = list }), "text/plain"); + } + #endregion + + #region 添加自定义规则 + [MyAuthorize("add", "wxkeywordreply")] + public IActionResult AddTextReplyRule() + { + WeixinRequestRule model = new WeixinRequestRule(); + Core.Admin.WriteLogActions("查看添加自定义回复规则;"); + return View(model); + } + + //执行添加操作 + [HttpPost] + [MyAuthorize("add", "wxkeywordreply", "JSON")] + public IActionResult AddTextReplyRule(WeixinRequestRule model) + { + + model.IsDefault = 1; + + int responseType = model.ResponseType; + model.RequestType = (int)WeixinRequestRule.XRequestType.Text;//文本请求 + IList ls = new List(); + if (responseType == 0) //纯文本 + { + string txtContent = Request.Form["txtContent"]; + if (string.IsNullOrEmpty(txtContent)) + { + tip.Message = "文本回复,文本不能为空!"; + return Json(tip); + } + model.ResponseType = (int)WeixinRequestRule.XResponseType.Text;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 + ls.Add(new WeixinRequestContent { RuleId = model.Id, Content = txtContent.Trim() }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Image) //图文 + { + #region 赋值规则图片 + + string[] itemIdArr = Request.Form["item_id"]; + string[] itemTitleArr = Request.Form["item_title"]; + string[] itemContentArr = Request.Form["item_imginfo"]; + string[] itemImgUrlArr = Request.Form["item_imgurl"]; + string[] itemLinkUrlArr = Request.Form["item_linkurl"]; + if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemLinkUrlArr != null && itemContentArr != null) + { + if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemLinkUrlArr.Length)) + { + + for (int i = 0; i < itemIdArr.Length; i++) + { + if (!string.IsNullOrEmpty(itemTitleArr[i])) + { + WeixinRequestContent modelt = new WeixinRequestContent(); + modelt.Id = Utils.StrToInt(itemIdArr[i].Trim(), 0); + modelt.Title = itemTitleArr[i].Trim(); + modelt.Content = itemContentArr[i].Trim(); + modelt.ImgURL = itemImgUrlArr[i].Trim(); + modelt.LinkUrl = itemLinkUrlArr[i].Trim(); + modelt.RuleId = model.Id; + ls.Add(modelt); + } + } + //model.contents = ls; + } + } + #endregion + if (ls == null || ls.Count < 1) + { + tip.Message = "图文列表,图文项目不能为空!"; + return Json(tip); + } + + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Video) //语音 + { + string txtSoundTitle = Request.Form["txtSoundTitle"]; + if (string.IsNullOrEmpty(txtSoundTitle)) + { + tip.Message = "语音回复,语音标题不能为空!"; + return Json(tip); + } + string txtSoundUrl = Request.Form["txtSoundUrl"]; + if (string.IsNullOrEmpty(txtSoundUrl)) + { + tip.Message = "语音回复,语音地址不能为空!"; + return Json(tip); + } + string txtSoundContent = Request.Form["txtSoundContent"]; + + ls.Add(new WeixinRequestContent { RuleId = model.Id, MediaURL = txtSoundUrl.Trim(), Title = txtSoundTitle, Content = txtSoundContent}); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.SingleImage) //单图片 + { + string txtSingleImage = Request.Form["txtSingleImage"]; + if (string.IsNullOrEmpty(txtSingleImage)) + { + tip.Message = "单图片回复,图片地址不能为空!"; + return Json(tip); + } + ls.Add(new WeixinRequestContent { RuleId = model.Id, ImgURL = txtSingleImage.Trim() }); + } + model.Insert(); + IList oldwc = model.ListContent; + if (oldwc != null && oldwc.Count > 0) + { + foreach (WeixinRequestContent p in ls) + { + if (oldwc.Find(s => s.Id == p.Id) != null) + { + oldwc.Remove(oldwc.Find(s => s.Id == p.Id)); + } + } + if (oldwc != null && oldwc.Count > 0) + { + oldwc.Delete(); + } + } + if (ls != null && ls.Count > 0) + { + foreach (var item in ls) + { + item.RuleId = model.Id; + } + } + ls.Save(); + + tip.Message = "添加文本关键字回复规则成功!"; + tip.Status = JsonTip.SUCCESS; + tip.ReturnUrl = "close"; + Core.Admin.WriteLogActions("添加文本关键字回复规则;"); + return Json(tip); + } + #endregion + + #region 修改文本回复详情 + [MyAuthorize("edit", "wxkeywordreply")] + public IActionResult EditTextReplyRule() + { + WeixinRequestRule ruleModel = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.Text);//获取规则 + if (ruleModel == null) + { + return EchoTipPage("系统找不到本记录!"); + } + switch (ruleModel.ResponseType) + { + case 0://文本 + ViewBag.txtContent = ruleModel.ListContent[0].Content; + break; + case 1://多图 + break; + case 2://语音 + ViewBag.txtSoundTitle = ruleModel.ListContent[0].Title; + ViewBag.txtSoundUrl = ruleModel.ListContent[0].MediaURL; + ViewBag.txtSoundContent = ruleModel.ListContent[0].Content; + break; + case 8://单图 + ViewBag.txtSingleImage = ruleModel.ListContent[0].ImgURL; + break; + } + Core.Admin.WriteLogActions($"查看文本回复规则;"); + return View(ruleModel); + } + [HttpPost] + [MyAuthorize( "edit", "wxkeywordreply", "JSON")] + public IActionResult EditTextReplyRule(WeixinRequestRule entity) + { + WeixinRequestRule model = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.Text & WeixinRequestRule._.Id == entity.Id);//获取规则 + + if (model == null) + { + tip.Message = "系统找不到本记录"; + return Json(tip); + } + + model.ResponseType = entity.ResponseType; + model.Keywords = entity.Keywords; + model.IsLikeQuery = entity.IsLikeQuery; + model.IsDefault = 1; + int defaultDetailId = int.Parse(Request.Form["hdfTID"]);//默认一条的ID。肯定至少有一条 + int responseType = model.ResponseType; + IList ls = new List(); + if (responseType == 0) //纯文本 + { + string txtContent = Request.Form["txtContent"]; + if (string.IsNullOrEmpty(txtContent)) + { + tip.Message = "文本回复,文本不能为空!"; + return Json(tip); + } + model.ResponseType = (int)WeixinRequestRule.XResponseType.Text;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 + ls.Add(new WeixinRequestContent { RuleId = model.Id, Content = txtContent.Trim(), Id = defaultDetailId }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Image) //图文 + { + #region 赋值规则图片 + + string[] itemIdArr = Request.Form["item_id"]; + string[] itemTitleArr = Request.Form["item_title"]; + string[] itemContentArr = Request.Form["item_imginfo"]; + string[] itemImgUrlArr = Request.Form["item_imgurl"]; + string[] itemLinkUrlArr = Request.Form["item_linkurl"]; + if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemLinkUrlArr != null && itemContentArr != null) + { + if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemLinkUrlArr.Length)) + { + + for (int i = 0; i < itemIdArr.Length; i++) + { + if (!string.IsNullOrEmpty(itemTitleArr[i])) + { + WeixinRequestContent modelt = new WeixinRequestContent(); + modelt.Id = Utils.StrToInt(itemIdArr[i].Trim(), 0); + modelt.Title = itemTitleArr[i].Trim(); + modelt.Content = itemContentArr[i].Trim(); + modelt.ImgURL = itemImgUrlArr[i].Trim(); + modelt.LinkUrl = itemLinkUrlArr[i].Trim(); + modelt.RuleId = model.Id; + ls.Add(modelt); + } + } + //model.contents = ls; + } + } + #endregion + if (ls == null || ls.Count < 1) + { + tip.Message = "图文列表,图文项目不能为空!"; + return Json(tip); + } + + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Video) //语音 + { + string txtSoundTitle = Request.Form["txtSoundTitle"]; + if (string.IsNullOrEmpty(txtSoundTitle)) + { + tip.Message = "语音回复,语音标题不能为空!"; + return Json(tip); + } + string txtSoundUrl = Request.Form["txtSoundUrl"]; + if (string.IsNullOrEmpty(txtSoundUrl)) + { + tip.Message = "语音回复,语音地址不能为空!"; + return Json(tip); + } + string txtSoundContent = Request.Form["txtSoundContent"]; + + ls.Add(new WeixinRequestContent { RuleId = model.Id, MediaURL = txtSoundUrl.Trim(), Title = txtSoundTitle, Id = defaultDetailId, Content = txtSoundContent }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.SingleImage) //单图片 + { + string txtSingleImage = Request.Form["txtSingleImage"]; + if (string.IsNullOrEmpty(txtSingleImage)) + { + tip.Message = "单图片回复,图片地址不能为空!"; + return Json(tip); + } + ls.Add(new WeixinRequestContent { RuleId = model.Id, ImgURL = txtSingleImage.Trim(), Id = defaultDetailId }); + } + model.Save(); + IList oldwc = model.ListContent; + if (oldwc != null && oldwc.Count > 0) + { + foreach (WeixinRequestContent p in ls) + { + if (oldwc.Find(s => s.Id == p.Id) != null) + { + oldwc.Remove(oldwc.Find(s => s.Id == p.Id)); + } + } + if (oldwc != null && oldwc.Count > 0) + { + oldwc.Delete(); + } + } + if (ls != null && ls.Count > 0) + { + foreach (var item in ls) + { + item.RuleId = model.Id; + } + } + ls.Save(); + + tip.Message = "修改文本自动回复成功!"; + tip.Status = JsonTip.SUCCESS; + tip.ReturnUrl = "close"; + Admin.WriteLogActions("修改文本自动回复成;"); + return Json(tip); + } + #endregion + + #region 删除关键字回复规则 + [HttpPost] + [MyAuthorize("del", "wxkeywordreply", "JSON")] + public IActionResult DelTextReplyRule(int id) + { + WeixinRequestRule model = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.Text & WeixinRequestRule._.Id == id);//获取规则 + if (model == null) + { + tip.Message = "系统找不到本记录"; + return Json(tip); + } + Admin.WriteLogActions("删除关键字回复规则(id:" + model.Id + ");"); + model.Delete(); + tip.Status = JsonTip.SUCCESS; + tip.Message = "删除规则成功"; + return Json(tip); + } + #endregion + + #region 公众号点击事件回复规则 + //自定义规则 + [MyAuthorize("viewlist", "clickreplyrule")] + public ActionResult ClickReplyRule() + { + return View(); + } + //自定义规则列表 + [MyAuthorize("viewlist", "clickreplyrule")] + public ActionResult GetClickReplyRuleList(string keyword, int page = 1, int limit = 20) + { + int numPerPage, currentPage, startRowIndex; + + numPerPage = limit; + currentPage = page; + startRowIndex = (currentPage - 1) * numPerPage; + Expression ex = WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.CustomMenu;//点击自定义菜单 + + if (!string.IsNullOrWhiteSpace(keyword)) + { + if (Utils.IsInt(keyword)) + { + ex &= (WeixinRequestRule._.Id == int.Parse(keyword) | WeixinRequestRule._.Keywords.Contains(keyword)); + } + else + { + ex &= WeixinRequestRule._.Keywords.Contains(keyword); + } + } + IList list = WeixinRequestRule.FindAll(ex, null, null, startRowIndex, numPerPage); + long totalCount = WeixinRequestRule.FindCount(ex, null, null, startRowIndex, numPerPage); + Admin.WriteLogActions($"查看公众号点击事件自定义回复规则({page});"); + return Content(JsonConvert.SerializeObject(new { total = totalCount, rows = list }), "text/plain"); + } + #endregion + + #region 添加自定义规则 + [MyAuthorize( "add", "clickreplyrule")] + public IActionResult AddClickReplyRule() + { + WeixinRequestRule model = new WeixinRequestRule(); + model.RequestType = (int)WeixinRequestRule.XRequestType.CustomMenu;//文本请求 + Core.Admin.WriteLogActions("查看添加点击菜单事件回复规则;"); + return View(model); + } + + //执行添加操作 + [HttpPost] + [MyAuthorize( "add", "clickreplyrule", "JSON")] + public IActionResult AddClickReplyRule(WeixinRequestRule model) + { + model.IsDefault = 1; + + int responseType = model.ResponseType; + model.RequestType = (int)WeixinRequestRule.XRequestType.CustomMenu;//文本请求 + IList ls = new List(); + if (responseType == 0) //纯文本 + { + string txtContent = Request.Form["txtContent"]; + if (string.IsNullOrEmpty(txtContent)) + { + tip.Message = "文本回复,文本不能为空!"; + return Json(tip); + } + model.ResponseType = (int)WeixinRequestRule.XResponseType.Text;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 + ls.Add(new WeixinRequestContent { RuleId = model.Id, Content = txtContent.Trim() }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Image) //图文 + { + #region 赋值规则图片 + + string[] itemIdArr = Request.Form["item_id"]; + string[] itemTitleArr = Request.Form["item_title"]; + string[] itemContentArr = Request.Form["item_imginfo"]; + string[] itemImgUrlArr = Request.Form["item_imgurl"]; + string[] itemLinkUrlArr = Request.Form["item_linkurl"]; + if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemLinkUrlArr != null && itemContentArr != null) + { + if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemLinkUrlArr.Length)) + { + + for (int i = 0; i < itemIdArr.Length; i++) + { + if (!string.IsNullOrEmpty(itemTitleArr[i])) + { + WeixinRequestContent modelt = new WeixinRequestContent(); + modelt.Id = Utils.StrToInt(itemIdArr[i].Trim(), 0); + modelt.Title = itemTitleArr[i].Trim(); + modelt.Content = itemContentArr[i].Trim(); + modelt.ImgURL = itemImgUrlArr[i].Trim(); + modelt.LinkUrl = itemLinkUrlArr[i].Trim(); + modelt.RuleId = model.Id; + ls.Add(modelt); + } + } + //model.contents = ls; + } + } + #endregion + if (ls == null || ls.Count < 1) + { + tip.Message = "图文列表,图文项目不能为空!"; + return Json(tip); + } + + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Video) //语音 + { + string txtSoundTitle = Request.Form["txtSoundTitle"]; + if (string.IsNullOrEmpty(txtSoundTitle)) + { + tip.Message = "语音回复,语音标题不能为空!"; + return Json(tip); + } + string txtSoundUrl = Request.Form["txtSoundUrl"]; + if (string.IsNullOrEmpty(txtSoundUrl)) + { + tip.Message = "语音回复,语音地址不能为空!"; + return Json(tip); + } + string txtSoundContent = Request.Form["txtSoundContent"]; + + ls.Add(new WeixinRequestContent { RuleId = model.Id, MediaURL = txtSoundUrl.Trim(), Title = txtSoundTitle, Content = txtSoundContent }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.SingleImage) //单图片 + { + string txtSingleImage = Request.Form["txtSingleImage"]; + if (string.IsNullOrEmpty(txtSingleImage)) + { + tip.Message = "单图片回复,图片地址不能为空!"; + return Json(tip); + } + ls.Add(new WeixinRequestContent { RuleId = model.Id, ImgURL = txtSingleImage.Trim() }); + } + model.Insert(); + IList oldwc = model.ListContent; + if (oldwc != null && oldwc.Count > 0) + { + foreach (WeixinRequestContent p in ls) + { + if (oldwc.Find(s => s.Id == p.Id) != null) + { + oldwc.Remove(oldwc.Find(s => s.Id == p.Id)); + } + } + if (oldwc != null && oldwc.Count > 0) + { + oldwc.Delete(); + } + } + if (ls != null && ls.Count > 0) + { + foreach (var item in ls) + { + item.RuleId = model.Id; + } + } + ls.Save(); + + tip.Message = "添加自定义菜单点击事件回复规则成功!"; + tip.Status = JsonTip.SUCCESS; + tip.ReturnUrl = "close"; + Admin.WriteLogActions("添加自定义菜单点击事件回复规则;"); + return Json(tip); + } + #endregion + + #region 修改文点击回复详情 + [MyAuthorize("edit", "clickreplyrule")] + public IActionResult EditClickReplyRule() + { + + WeixinRequestRule ruleModel = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.CustomMenu);//获取规则 + if (ruleModel == null) + { + return EchoTipPage("系统找不到本记录!"); + } + switch (ruleModel.ResponseType) + { + case 0://文本 + ViewBag.txtContent = ruleModel.ListContent[0].Content; + break; + case 1://多图 + break; + case 2://语音 + ViewBag.txtSoundTitle = ruleModel.ListContent[0].Title; + ViewBag.txtSoundUrl = ruleModel.ListContent[0].MediaURL; + ViewBag.txtSoundContent = ruleModel.ListContent[0].Content; + break; + case 8://单图 + ViewBag.txtSingleImage = ruleModel.ListContent[0].ImgURL; + break; + } + Core.Admin.WriteLogActions($"查看点击菜单事件回复规则;"); + return View(ruleModel); + } + + [HttpPost] + [MyAuthorize( "edit", "clickreplyrule", "JSON")] + public IActionResult EditClickReplyRule(WeixinRequestRule entity) + { + WeixinRequestRule model = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.CustomMenu & WeixinRequestRule._.Id == entity.Id);//获取规则 + + if (model == null) + { + tip.Message = "系统找不到本记录"; + return Json(tip); + } + + model.ResponseType = entity.ResponseType; + model.Keywords = entity.Keywords; + model.IsDefault = 1; + int defaultDetailId = int.Parse(Request.Form["hdfTID"]);//默认一条的ID。肯定至少有一条 + int responseType = model.ResponseType; + IList ls = new List(); + if (responseType == 0) //纯文本 + { + string txtContent = Request.Form["txtContent"]; + if (string.IsNullOrEmpty(txtContent)) + { + tip.Message = "文本回复,文本不能为空!"; + return Json(tip); + } + model.ResponseType = (int)WeixinRequestRule.XResponseType.Text;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 + ls.Add(new WeixinRequestContent { RuleId = model.Id, Content = txtContent.Trim(), Id = defaultDetailId }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Image) //图文 + { + #region 赋值规则图片 + + string[] itemIdArr = Request.Form["item_id"]; + string[] itemTitleArr = Request.Form["item_title"]; + string[] itemContentArr = Request.Form["item_imginfo"]; + string[] itemImgUrlArr = Request.Form["item_imgurl"]; + string[] itemLinkUrlArr = Request.Form["item_linkurl"]; + if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemLinkUrlArr != null && itemContentArr != null) + { + if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemLinkUrlArr.Length)) + { + + for (int i = 0; i < itemIdArr.Length; i++) + { + if (!string.IsNullOrEmpty(itemTitleArr[i])) + { + WeixinRequestContent modelt = new WeixinRequestContent(); + modelt.Id = Utils.StrToInt(itemIdArr[i].Trim(), 0); + modelt.Title = itemTitleArr[i].Trim(); + modelt.Content = itemContentArr[i].Trim(); + modelt.ImgURL = itemImgUrlArr[i].Trim(); + modelt.LinkUrl = itemLinkUrlArr[i].Trim(); + modelt.RuleId = model.Id; + ls.Add(modelt); + } + } + //model.contents = ls; + } + } + #endregion + if (ls == null || ls.Count < 1) + { + tip.Message = "图文列表,图文项目不能为空!"; + return Json(tip); + } + + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Video) //语音 + { + string txtSoundTitle = Request.Form["txtSoundTitle"]; + if (string.IsNullOrEmpty(txtSoundTitle)) + { + tip.Message = "语音回复,语音标题不能为空!"; + return Json(tip); + } + string txtSoundUrl = Request.Form["txtSoundUrl"]; + if (string.IsNullOrEmpty(txtSoundUrl)) + { + tip.Message = "语音回复,语音地址不能为空!"; + return Json(tip); + } + string txtSoundContent = Request.Form["txtSoundContent"]; + + ls.Add(new WeixinRequestContent { RuleId = model.Id, MediaURL = txtSoundUrl.Trim(), Title = txtSoundTitle, Id = defaultDetailId, Content = txtSoundContent }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.SingleImage) //单图片 + { + string txtSingleImage = Request.Form["txtSingleImage"]; + if (string.IsNullOrEmpty(txtSingleImage)) + { + tip.Message = "单图片回复,图片地址不能为空!"; + return Json(tip); + } + ls.Add(new WeixinRequestContent { RuleId = model.Id, ImgURL = txtSingleImage.Trim(), Id = defaultDetailId }); + } + model.Save(); + IList oldwc = model.ListContent; + if (oldwc != null && oldwc.Count > 0) + { + foreach (WeixinRequestContent p in ls) + { + if (oldwc.Find(s => s.Id == p.Id) != null) + { + oldwc.Remove(oldwc.Find(s => s.Id == p.Id)); + } + } + if (oldwc != null && oldwc.Count > 0) + { + oldwc.Delete(); + } + } + if (ls != null && ls.Count > 0) + { + foreach (var item in ls) + { + item.RuleId = model.Id; + } + } + ls.Save(); + + tip.Message = "修改点击自定义菜单事件自动回复成功!"; + tip.Status = JsonTip.SUCCESS; + tip.ReturnUrl = "close"; + Admin.WriteLogActions("修改点击自定义菜单事件自动回复;"); + return Json(tip); + } + #endregion + + #region 未找到关键字自动回复 + [HttpGet] + [MyAuthorize("view", "wxnotfindkeywordautoreply")] + public ActionResult NotFindKeywordAutoReply() + { + + WeixinRequestRule ruleModel = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.NotFindKeyword);//获取规则 + if (ruleModel == null) + { + ruleModel = new WeixinRequestRule(); + ruleModel.RequestType = (int)WeixinRequestRule.XRequestType.NotFindKeyword; + ruleModel.ResponseType = (int)WeixinRequestRule.XResponseType.Text; + ruleModel.RuleName = "未找到关键词自动回复"; + ruleModel.IsDefault = 1; + ruleModel.Insert(); + //增加Response + WeixinRequestContent content = new WeixinRequestContent() + { + RuleId = ruleModel.Id, + Content = "未找到关键词自动回复", + + }; + content.Insert(); + ruleModel = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.NotFindKeyword);//重新获取规则 + } + switch (ruleModel.ResponseType) + { + case 0://文本 + ViewBag.txtContent = ruleModel.ListContent[0].Content; + break; + case 1://多图 + break; + case 2://语音 + ViewBag.txtSoundTitle = ruleModel.ListContent[0].Title; + ViewBag.txtSoundUrl = ruleModel.ListContent[0].MediaURL; + ViewBag.txtSoundContent = ruleModel.ListContent[0].Content; + break; + case 8://单图 + ViewBag.txtSingleImage = ruleModel.ListContent[0].ImgURL; + break; + } + + Core.Admin.WriteLogActions("查看公众号未找到关键字自动回复;"); + return View(ruleModel); + } + //编辑自动回复规则 + [HttpPost] + [MyAuthorize("edit", "wxnotfindkeywordautoreply", "JSON")] + public IActionResult NotFindKeywordAutoReply(WeixinRequestRule entity) + { + WeixinRequestRule model = WeixinRequestRule.Find(WeixinRequestRule._.RequestType == (int)WeixinRequestRule.XRequestType.NotFindKeyword );//获取规则 + model.ResponseType = entity.ResponseType; + + model.IsDefault = 1; + int defaultDetailId = int.Parse(Request.Form["hdfTID"]);//默认一条的ID。肯定至少有一条 + int responseType = model.ResponseType; + IList ls = new List(); + if (responseType == 0) //纯文本 + { + string txtContent = Request.Form["txtContent"]; + if (string.IsNullOrEmpty(txtContent)) + { + tip.Message = "文本回复,文本不能为空!"; + return Json(tip); + } + model.ResponseType = (int)WeixinRequestRule.XResponseType.Text;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 + ls.Add(new WeixinRequestContent { RuleId = model.Id, Content = txtContent.Trim(), Id = defaultDetailId }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Image) //图文 + { + #region 赋值规则图片 + + string[] itemIdArr = Request.Form["item_id"]; + string[] itemTitleArr = Request.Form["item_title"]; + string[] itemContentArr = Request.Form["item_imginfo"]; + string[] itemImgUrlArr = Request.Form["item_imgurl"]; + string[] itemLinkUrlArr = Request.Form["item_linkurl"]; + if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemLinkUrlArr != null && itemContentArr != null) + { + if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemLinkUrlArr.Length)) + { + + for (int i = 0; i < itemIdArr.Length; i++) + { + if (!string.IsNullOrEmpty(itemTitleArr[i])) + { + WeixinRequestContent modelt = new WeixinRequestContent(); + modelt.Id = Utils.StrToInt(itemIdArr[i].Trim(), 0); + modelt.Title = itemTitleArr[i].Trim(); + modelt.Content = itemContentArr[i].Trim(); + modelt.ImgURL = itemImgUrlArr[i].Trim(); + modelt.LinkUrl = itemLinkUrlArr[i].Trim(); + modelt.RuleId = model.Id; + ls.Add(modelt); + } + } + //model.contents = ls; + } + } + #endregion + if (ls == null || ls.Count < 1) + { + tip.Message = "图文列表,图文项目不能为空!"; + return Json(tip); + } + + } + else if (responseType == (int)WeixinRequestRule.XResponseType.Video) //语音 + { + string txtSoundTitle = Request.Form["txtSoundTitle"]; + if (string.IsNullOrEmpty(txtSoundTitle)) + { + tip.Message = "语音回复,语音标题不能为空!"; + return Json(tip); + } + string txtSoundUrl = Request.Form["txtSoundUrl"]; + if (string.IsNullOrEmpty(txtSoundUrl)) + { + tip.Message = "语音回复,语音地址不能为空!"; + return Json(tip); + } + string txtSoundContent = Request.Form["txtSoundContent"]; + + ls.Add(new WeixinRequestContent { RuleId = model.Id, MediaURL = txtSoundUrl.Trim(), Title = txtSoundTitle, Id = defaultDetailId, Content = txtSoundContent }); + } + else if (responseType == (int)WeixinRequestRule.XResponseType.SingleImage) //单图片 + { + string txtSingleImage = Request.Form["txtSingleImage"]; + if (string.IsNullOrEmpty(txtSingleImage)) + { + tip.Message = "单图片回复,图片地址不能为空!"; + return Json(tip); + } + ls.Add(new WeixinRequestContent { RuleId = model.Id, ImgURL = txtSingleImage.Trim(), Id = defaultDetailId }); + } + model.Save(); + IList oldwc = model.ListContent; + if (oldwc != null && oldwc.Count > 0) + { + foreach (WeixinRequestContent p in ls) + { + if (oldwc.Find(s => s.Id == p.Id) != null) + { + oldwc.Remove(oldwc.Find(s => s.Id == p.Id)); + } + } + if (oldwc != null && oldwc.Count > 0) + { + oldwc.Delete(); + } + } + if (ls != null && ls.Count > 0) + { + foreach (var item in ls) + { + item.RuleId = model.Id; + } + } + ls.Save(); + + tip.Message = "修改成功!"; + tip.Status = JsonTip.SUCCESS; + //tip.ReturnUrl = "reload"; + Admin.WriteLogActions("修改公众号未找到关键字自动回复;"); + return Json(tip); + } + #endregion + + } } \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Views/Index/Index.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Index/Index.cshtml index ff8c9ee..998eb8b 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Index/Index.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Index/Index.cshtml @@ -113,11 +113,11 @@