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"]); } UserPhotoDAL dal = new UserPhotoDAL(); switch (strAction) { case "del": if (dal.UpdateUserPhotoState(strID)) { strMessage = "操作成功!"; } else { strMessage = "操作失败!"; } break; default: break; } Response.Write(strMessage); Response.End(); }
/// <summary> /// 加载数据 /// </summary> /// <param name="strWhere">条件</param> void LoadData(string strWhere) { txtTitle.Text = ""; UserPhotoDAL dal = new UserPhotoDAL(); DataSet ds = dal.GetPhotoList(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 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); }