protected void btnSave_Click(object sender, EventArgs e) { if (null == Session["strSiteName"] || null == Session["strSiteCode"] || null == Session["strLoginName"]) { Response.Write("<script language=JavaScript>;parent.location.href='../Index.aspx';</script>"); Response.End(); } if (keyword.Text.Trim() != null && keyword.Text.Trim() != "") { MsgAutoRule model = new MsgAutoRule(); MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); model.MatchPattern = keyword.Text; model.Order = Convert.ToInt32(sort.Text); model.MsgValue = repmsgcontent.Value; model.ID = strID; model.Enabled = 1; model.LastModTime = DateTime.Now; //model.MatchType = "keywords"; //model.MsgType = "text"; //model.Handle = "Mozart.WeiXin.SubscribeCouponActHandle"; if (dal.UpdateMsgAutoRule(model)) { MessageBox.Show(this, "操作成功!"); } else { MessageBox.Show(this, "操作失败!"); } } else { MessageBox.Show(this, "请输入信息名称后再操作!"); } }
/// <summary> /// 文本消息处理 /// </summary> /// <param name="msg"></param> /// <returns></returns> public string TextMsgReceive(TextRequestMsgModel msg) { string res = string.Empty; MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); MsgAutoRule rule = dal.GetKeywordsRule(wxConfig.ID, msg.Content); if (rule != null) { res = ProcessReply(msg, rule.MsgType, rule.MsgValue); } else { rule = dal.GetRegexRule(wxConfig.ID, msg.Content); if (rule != null) { res = ProcessReply(msg, rule.MsgType, rule.MsgValue); } else { rule = dal.GetDefaultRule(wxConfig.ID); if (rule != null) { res = ProcessReply(msg, rule.MsgType, rule.MsgValue); } } }//启用默认消息回复 return(res); }
protected void Page_Load(object sender, EventArgs e) { if (null != Common.Common.NoHtml(Request.QueryString["action"])) { strAction = Common.Common.NoHtml(Request.QueryString["action"]); } if (null != Common.Common.NoHtml(Request.QueryString["id"])) { strID = Common.Common.NoHtml(Request.QueryString["id"]); } MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); switch (strAction) { case "del": if (dal.UpdateMsgAutoRuleEnable(strID)) { strMessage = "操作成功!"; } else { strMessage = "操作失败!"; } break; default: break; } Response.Write(strMessage); Response.End(); }
public void ShowActivityInfo(string strID) { MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); DataSet ds = dal.GetMsuAutoRuleDetail(strID); MsgAutoRule model = DataConvert.DataRowToModel <MsgAutoRule>(ds.Tables[0].Rows[0]); keyword.Text = model.MatchPattern; repmsgcontent.Value = model.MsgValue; sort.Text = model.Order.ToString(); if (strAction == "show") { this.btnReset.Visible = false; this.btnSave.Visible = false; keyword.ReadOnly = true; sort.ReadOnly = true; } }
/// <summary> /// 加载数据 /// </summary> /// <param name="strWhere">条件</param> void LoadData(string strWhere) { txtName.Text = ""; MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); DataSet ds = dal.GetKeywordTextMsgAutoRuleList(strWhere); DataView dv = ds.Tables[0].DefaultView; AspNetPager1.RecordCount = dv.Count; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dv; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; pds.PageSize = AspNetPager1.PageSize; Repeater1.DataSource = pds; Repeater1.DataBind(); }
/// <summary> /// 事件单击事件消息处理 /// </summary> /// <param name="msg"></param> /// <returns></returns> public string MenuClickProcess(ClickEventRequestMsgModel msg) { string res = string.Empty; MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); MsgAutoRule rule = dal.GetClickEventRule(wxConfig.ID, msg.EventKey); if (rule != null) { res = ProcessReply(msg, rule.MsgType, rule.MsgValue); } else { rule = dal.GetDefaultRule(wxConfig.ID); if (rule != null) { res = ProcessReply(msg, rule.MsgType, rule.MsgValue); } }//启用默认消息回复 return(res); }
protected void btnSave_Click(object sender, EventArgs e) { if (null == Session["strSiteName"] || null == Session["strSiteCode"] || null == Session["strLoginName"]) { Response.Write("<script language=JavaScript>;parent.location.href='../Index.aspx';</script>"); Response.End(); } if (keyword.Text.Trim() != null && keyword.Text.Trim() != "") { WXConfigDAL configdal = new WXConfigDAL(); DataSet wxconfigds = configdal.GetWXConfigDataList(Session["strSiteCode"].ToString()); MsgAutoRule model = new MsgAutoRule(); MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); model.MatchPattern = keyword.Text; model.Order = Convert.ToInt32(sort.Text); model.MsgValue = repmsgcontent.Value; model.ID = Guid.NewGuid().ToString("N").ToUpper(); model.Enabled = 1; model.LastModTime = DateTime.Now; model.MatchType = "keywords"; model.MsgType = "text"; if (wxconfigds != null && wxconfigds.Tables.Count > 0 && wxconfigds.Tables[0].Rows.Count > 0) { model.WXConfigID = wxconfigds.Tables[0].Rows[0]["ID"].ToString(); } model.Handle = "Mozart.WeiXin.SubscribeCouponActHandle"; if (dal.AddMsgAutoRule(model)) { MessageBox.Show(this, "操作成功!"); } else { MessageBox.Show(this, "操作失败!"); } } else { MessageBox.Show(this, "请输入信息名称后再操作!"); } }
protected void Page_Load(object sender, EventArgs e) { if (string.IsNullOrEmpty(Session["strSiteCode"].ToString()) && Session["strRoleCode"].ToString() != "ADMIN") { Response.Write("<script language=JavaScript>parent.location.href='../Index.aspx';</script>"); Response.End(); } if (!IsPostBack) { if (null != Common.Common.NoHtml(Request.QueryString["action"])) { strAction = Common.Common.NoHtml(Request.QueryString["action"]); } if (null != Common.Common.NoHtml(Request.QueryString["id"])) { strID = Common.Common.NoHtml(Request.QueryString["id"]); } MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); switch (strAction) { case "del": if (dal.UpdateMsgAutoRuleEnable(strID)) { strMessage = "操作成功!"; } else { strMessage = "操作失败!"; } Response.Write(strMessage); Response.End(); break; default: break; } } }
/// <summary> /// 图片消息处理 /// </summary> /// <param name="msg"></param> /// <returns></returns> public string ImageMsgReceive(ImageRequestMsgModel msg) { string res = string.Empty; MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); MsgAutoRule rule = dal.GetImageRule(wxConfig.ID); if (rule != null) { switch (rule.MsgType.ToLower()) { case "hp_photo": try { string fileDir = HttpContext.Current.Server.MapPath("/HP_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } ExceptionLog log = new ExceptionLog(); log.Message = weixin.WeiXinConfig.AppId + "}{" + weixin.WeiXinConfig.AppSecret + "}{" + msg.MediaId; ExceptionLogDAL.InsertExceptionLog(log); //string fileName = weixin.SaveAsMedia(msg.MediaId, fileDir); string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { Photo p = new Photo() { SiteCode = siteCode, OpenId = msg.FromUserName, Img = fileName }; PhotoDAL photoDal = new PhotoDAL(); photoDal.SaveInfo(p); //回复文本消息 string url = string.Format("{0}/WebService/ImageEdit.aspx?id={1}", GetSiteUrl(), p.ID); string content = string.Format("<a href='{0}'>点击编辑</a>", url); TextResponseMsgModel textMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = content }; res = textMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; case "user_photo": try { string fileDir = HttpContext.Current.Server.MapPath("/USER_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } //string fileName = weixin.SaveAsMedia(msg.MediaId, fileDir); string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { UserPhoto photo = new UserPhoto() { Name = fileName, SiteCode = siteCode, OpenId = msg.FromUserName, FilePath = fileName }; UserPhotoDAL uPhotoDal = new UserPhotoDAL(); uPhotoDal.Insert(photo); //回复文本消息 TextResponseMsgModel textMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = rule.MsgValue == null ? string.Empty : TransformText(rule.MsgValue, msg) }; res = textMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; case "user_photo_url": try { string fileDir = HttpContext.Current.Server.MapPath("/USER_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { UserPhoto photox = new UserPhoto() { Name = fileName, SiteCode = siteCode, OpenId = msg.FromUserName, FilePath = fileName }; UserPhotoDAL uPhotoDal = new UserPhotoDAL(); uPhotoDal.Insert(photox); //回复文本消息 string url = string.Format("{0}/MicroSite/PhotoPrint.aspx?id={1}", GetSiteUrl(), photox.ID); string content = string.Format("<a href='{0}'>开始打印</a>", url); TextResponseMsgModel textUrlMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = content }; res = textUrlMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; case "user_printphoto_stepone": try { string fileDir = HttpContext.Current.Server.MapPath("/USER_PHOTO/"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } string fileName = weixin.SaveAsFile(msg.PicUrl, fileDir); if (!string.IsNullOrEmpty(fileName)) { UserPhoto photox = new UserPhoto() { Name = fileName, SiteCode = siteCode, OpenId = msg.FromUserName, FilePath = fileName }; UserPhotoDAL uPhotoDal = new UserPhotoDAL(); uPhotoDal.Insert(photox); //回复文本消息 string url = string.Format("{0}/MicroSite/PhotoPrintStepOne.aspx?id={1}", GetSiteUrl(), photox.ID); string content = string.Format("<a href='{0}'>开始打印</a>", url); TextResponseMsgModel textUrlMsg = new TextResponseMsgModel() { ToUserName = msg.FromUserName, FromUserName = msg.ToUserName, CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(), Content = content }; res = textUrlMsg.ToString(); } } catch (Exception ex) { ExceptionLogDAL.InsertExceptionLog(ex); } break; default: rule = dal.GetDefaultRule(wxConfig.ID); if (rule != null) { res = ProcessReply(msg, rule.MsgType, rule.MsgValue); } break; } } return(res); }
protected void btnSave_Click(object sender, EventArgs e) { if (null == Session["strSiteName"] || null == Session["strSiteCode"] || null == Session["strLoginName"]) { Response.Write("<script language=JavaScript>;parent.location.href='../Index.aspx';</script>"); Response.End(); } if (!string.IsNullOrEmpty(keyword.Text.Trim()) && fudVoice.HasFile && fudVoice.PostedFile.ContentLength <= 1024 * 1024 * 2 && (fudVoice.PostedFile.FileName.ToLower().Contains(".mp3") || fudVoice.PostedFile.FileName.ToLower().Contains(".amr"))) {//语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式 try { //先上传并插入微信媒体表 string fileDir = string.Format("/Uploads/{0}/", DateTime.Now.ToString("yyyyMM")); if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(fileDir))) { System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(fileDir)); } string ext = System.IO.Path.GetExtension(fudVoice.FileName); string fileName = string.Format("{0}{1}", Guid.NewGuid().ToString("N"), ext); string filePath = fileDir + fileName; fudVoice.SaveAs(HttpContext.Current.Server.MapPath(filePath)); Media media = new Media() { MediaName = fudVoice.FileName, MediaFile = filePath, MediaType = MediaUploadType.Voice.ToString().ToLower() }; //选中自动同步时,将语音文件自动同步至微信服务器 if (cboIsSyn.Checked) { WXConfigDAL cdal = new WXConfigDAL(); Model.WeiXin.WXConfig wxConfig = cdal.GetWXConfigBySiteCode(Session["strSiteCode"].ToString()); if (wxConfig != null) { WeiXinCore.Models.WeiXinConfig weixinConfig = new WeiXinCore.Models.WeiXinConfig() { ID = wxConfig.WXID, Name = wxConfig.WXName, Token = wxConfig.WXToken, AppId = wxConfig.WXAppID, AppSecret = wxConfig.WXAppSecret }; WeiXinCore.WeiXin weixin = new WeiXinCore.WeiXin(weixinConfig); MediaUploadResult obj = weixin.PostMedia(HttpContext.Current.Server.MapPath(filePath), MediaUploadType.Voice); media.MediaID = obj.MediaID; media.LastSynTime = DateTime.Now; } } MediaDAL.CreateInstance().InsertInfo(media); //插入自动回复匹配表 WXConfigDAL configdal = new WXConfigDAL(); DataSet wxconfigds = configdal.GetWXConfigDataList(Session["strSiteCode"].ToString()); MsgAutoRule model = new MsgAutoRule(); MsgAutoRuleDAL dal = new MsgAutoRuleDAL(); model.MatchPattern = keyword.Text; model.Order = Convert.ToInt32(sort.Text); model.MsgValue = media.ID;//对应微信媒体文件ID,因微信上传文件有效期为两天,所以需要调度程序定期自动上传 model.ID = Guid.NewGuid().ToString("N").ToUpper(); model.Enabled = 1; model.LastModTime = DateTime.Now; model.MatchType = "keywords"; model.MsgType = "voice"; if (wxconfigds != null && wxconfigds.Tables.Count > 0 && wxconfigds.Tables[0].Rows.Count > 0) { model.WXConfigID = wxconfigds.Tables[0].Rows[0]["ID"].ToString(); } if (dal.AddMsgAutoRule(model)) { MessageBox.Show(this, "操作成功!"); } else { MessageBox.Show(this, "操作失败!"); } } catch (Exception ex) { MessageBox.Show(this, ex.Message); } } else { MessageBox.Show(this, "请核对信息后再操作!"); } }