/// <summary> /// 处理小视频请求 /// </summary> /// <param name="requestMessage"></param> /// <returns></returns> public override IResponseMessageBase OnShortVideoRequest(RequestMessageShortVideo requestMessage) { Task.Run(() => { try { string openId = requestMessage.FromUserName; var replyItem = MpEventBll.GetByKey("ych_automsg"); if (replyItem != null) { switch (replyItem.ReplyType) { case "text": CustomApi.SendText(BaseClass.AppId, openId, EConvert.ConvertEmojiHtml(Senparc.Weixin.HttpUtility.RequestUtility.UrlDecode(replyItem.ReplyContent))); break; case "img": CustomApi.SendImage(BaseClass.AppId, openId, replyItem.ReplyContent); break; } } } catch (Exception e) { LogHandler.Error($"错误位置:微信图片消息回复\n请求数据:{JsonConvert.SerializeObject(requestMessage)}\n错误信息:{e.StackTrace}"); } }); //将消息转发到客服 var responseMessage = CreateResponseMessage <ResponseMessageTransfer_Customer_Service>(); return(responseMessage); }
/// <summary> /// 订阅(关注)事件 /// </summary> /// <returns></returns> public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage) { Task.Run(() => { string openId = requestMessage.FromUserName; var replyItem = MpEventBll.GetByKey("ych_subscribe"); if (replyItem != null) { switch (replyItem.ReplyType) { case "text": CustomApi.SendText(BaseClass.AppId, openId, EConvert.ConvertEmojiHtml(Senparc.Weixin.HttpUtility.RequestUtility.UrlDecode(replyItem.ReplyContent))); break; case "img": CustomApi.SendImage(BaseClass.AppId, openId, replyItem.ReplyContent); break; } } }); //将消息转发到客服 var responseMessage = new SuccessResponseMessage(); return(responseMessage); }
//创建菜单 protected void PublishMenu() { if (Request["menu"] == null) { Json(new { state = false }); return; } string publishJson = EConvert.ConvertEmojiHtml(HttpContext.Current.Server.UrlDecode(Request["menu"])); publishJson = publishJson.Replace("&", "&"); var menu = JsonConvert.DeserializeObject <YchButtonGroup>(publishJson); MpEventBll.SaveAllButtonEvent(menu); var tmp = AccessTokenContainer.TryGetAccessToken(BaseClass.AppId, BaseClass.Secret); //tmp = "weiphp"; var result = MenuWeChatApi.CreateMenu(tmp, publishJson); //var result = new WxJsonResult(); if (result.errcode == 0) { //记录菜单保存记录 MpMenuLogBll.WriteLog(Request["menu"], "cs"); Json(new { state = true }); return; } Json(new { state = false }); }
/// <summary> /// 删除规则 /// </summary> protected void DeleteMsgRule() { int msgId = EConvert.ConvertTo <int>(Request["msgId"]); bool result = MsgReplyBll.DeleteMsgRule(msgId); Json(new { state = result }); }
public string GetString(string key) { object data = this.content[key]; if (data == null) { return(null); } return(EConvert.ToString(data)); }
public bool SaveMmaterialData() { try { var count = MediaApi.GetMediaCount(BaseClass.AppId); var listDto = new List <mpmateriallib>(); if (count.image_count > 0) { var imglist = GetMediaList(AccessTokenContainer.TryGetAccessToken(BaseClass.AppId, BaseClass.Secret), UploadMediaFileType.image, 0, count.image_count); foreach (var imgItem in imglist.item) { mpmateriallib dto = new mpmateriallib() { MType = UploadMediaFileType.image.ToString(), MName = imgItem.name, MediaId = imgItem.media_id, MUrl = imgItem.url, UpdateTime = EConvert.ConvertToDateTime(imgItem.update_time) }; listDto.Add(dto); } } if (count.news_count > 0) { var newslist = GetNewsMediaList(AccessTokenContainer.TryGetAccessToken(BaseClass.AppId, BaseClass.Secret), 0, count.news_count); foreach (var newsItem in newslist.item) { mpmateriallib dto = new mpmateriallib() { MType = UploadMediaFileType.news.ToString(), MName = newsItem.content.news_item[0].title, MediaId = newsItem.media_id, NewsContent = JsonConvert.SerializeObject(newsItem.content), UpdateTime = EConvert.ConvertToDateTime(newsItem.update_time) }; listDto.Add(dto); } } //MpMaterialLibDal.Instantiation.SyncMpData(EConvert.ListToDataTable(listDto)); return(new MpMaterialLibBll().SyncMpData(listDto)); //return true; } catch (Exception ex) { LogHandler.Error(ex); LogHandler.Error("请检查微信同步素材接口使用次数"); return(false); } }
/// <summary> /// 将原公众号菜单按钮调整为自定义click类型 /// </summary> /// <param name="item"></param> private Button ChangeButton(MpButtonJsonResult item) { //需要转换的按钮类型 string btnType = item.type; List <string> typeList = new List <string>() { "img", "news", "text", "voice", "video" }; if (typeList.Contains(btnType.ToLower())) { item.type = "click"; item.key = Guid.NewGuid().ToString("N"); } Button btn = new Button() { name = item.name, type = item.type, key = item.key, replyType = btnType }; switch (btnType) { case "text": btn.replyContent = EConvert.DConvertEmojiHtml(item.value).UrlEncode().Replace("+", "%20"); break; case "view": btn.replyContent = item.url; break; default: btn.replyContent = item.value; break; } if (btn.type == "click") { MpEventBll.SaveEventInfo(new mpeventreply() { EventKey = item.key, EventType = "click", ReplyType = btnType, ReplyContent = item.value }); } return(btn); }
public static string escape(object data) { string text = EConvert.ToString(data); if (text.Contains(@"\")) { text = text.Replace(@"\", @"\\"); } if (text.Contains("'")) { text = text.Replace("'", @"\'"); } if (text.Contains("\r\n")) { text = text.Replace("\r\n", @"\r\n"); } return(text); }
//获取图文、图片永久素材列表 protected void GetMediaList() { bool useSync = EConvert.ConvertTo <bool>(Request["mode"]); string type = Request["type"]; try { if (useSync) { MpDataSyncApi api = new MpDataSyncApi(); api.SaveMmaterialData(); } List <mpmateriallib> newsList = null; List <mpmateriallib> imgList = null; int imgNum = EConvert.ConvertTo <int>(ConfigurationManager.AppSettings["WeChatImgDefaultCount"]); int newsNum = EConvert.ConvertTo <int>(ConfigurationManager.AppSettings["WeChatNewsDefaultCount"]); if (type == "img") { imgList = MpMaterialLibBll.GetMaterialList(UploadMediaFileType.image.ToString(), imgNum); } else if (type == "news") { newsList = MpMaterialLibBll.GetMaterialList(UploadMediaFileType.news.ToString(), newsNum); } else { imgList = MpMaterialLibBll.GetMaterialList(UploadMediaFileType.image.ToString(), imgNum); newsList = MpMaterialLibBll.GetMaterialList(UploadMediaFileType.news.ToString(), newsNum); } Json(new { state = true, newsList = newsList, imgList = imgList }); } catch (Exception e) { Json(new { state = false }); } }
public long GetLong(string key) { return(EConvert.ToLong(this.m_content[key])); }
public int GetInt(string key) { return(EConvert.ToInt(this.m_content[key])); }
public float GetFloat(string key) { return(EConvert.ToFloat(this.m_content[key])); }
public string GetString(string key) { return(EConvert.ToString(this.m_content[key])); }
private static void visit_json_object(StringBuilder sb, string key, object data) { string type_name = null; if (data != null) { type_name = data.GetType().Name; } switch (type_name) { case "SortedList": case "Hashtable": visit_json_dictionary(sb, key, data as IDictionary); break; case "ArrayList": visit_json_list(sb, key, data as IList); break; case "Byte": case "Int16": case "Int32": case "Int64": case "Single": case "Double": if (key == null) { sb.AppendFormat("'{0}'", data); } else { sb.AppendFormat("'{0}':{1}", key, data); } break; case "Boolean": if (key == null) { sb.AppendFormat("'{0}'", data); } else { sb.AppendFormat("'{0}':{1}", key, EConvert.ToBoolean(data) ? "true" : "false"); } break; case "DateTime": if (key == null) { sb.AppendFormat("'{0}'", data); } else { sb.AppendFormat("'{0}':'{1}'", key, data); } break; default: if (key == null) { sb.AppendFormat("'{0}'", escape(data)); } else { sb.AppendFormat("'{0}':'{1}'", key, escape(data)); } break; } }
public bool SaveMsgReplyData() { var mpMsgData = AutoReplyApi.GetCurrentAutoreplyInfo(BaseClass.AppId); if (mpMsgData.errcode == 0) { //初始化关注回复 if (mpMsgData.add_friend_autoreply_info != null) { var sereply = mpMsgData.add_friend_autoreply_info; if (sereply.type.ToString() == "text") { sereply.content = EConvert.DConvertEmojiHtml(sereply.content).UrlEncode().Replace("+", "%20"); } MpEventBll.SaveEventInfo(new mpeventreply() { EventType = WxEventTypeEnum.subscribe.ToString(), EventKey = "ych_subscribe", ReplyType = sereply.type.ToString(), ReplyContent = sereply.content, }); } //初始化自动消息回复 if (mpMsgData.message_default_autoreply_info != null) { var autoreply = mpMsgData.message_default_autoreply_info; if (autoreply.type.ToString() == "text") { autoreply.content = EConvert.DConvertEmojiHtml(autoreply.content).UrlEncode().Replace("+", "%20"); } MpEventBll.SaveEventInfo(new mpeventreply() { EventType = WxEventTypeEnum.automsg.ToString(), EventKey = "ych_automsg", ReplyType = autoreply.type.ToString(), ReplyContent = autoreply.content }); } //初始化关键字回复 if (mpMsgData.keyword_autoreply_info?.list != null && mpMsgData.keyword_autoreply_info.list.Count > 0) { mpMsgData.keyword_autoreply_info.list.Reverse(); foreach (var ruleItem in mpMsgData.keyword_autoreply_info.list) { var dto = new MsgReplyResult { Msg = { RuleName = ruleItem.rule_name, ReplyMode = ruleItem.reply_mode.ToString() } }; if (ruleItem.keyword_list_info != null && ruleItem.keyword_list_info.Count > 0) { foreach (var keyItem in ruleItem.keyword_list_info) { mpmsgreplykey key = new mpmsgreplykey { KeyVal = keyItem.content, MatchMode = keyItem.match_mode.ToString() }; dto.Keys.Add(key); } } if (ruleItem.reply_list_info != null && ruleItem.reply_list_info.Count > 0) { foreach (var contentItem in ruleItem.reply_list_info) { if (contentItem.type.ToString() == "text") { contentItem.content = EConvert.DConvertEmojiHtml(contentItem.content).UrlEncode().Replace("+", "%20"); } mpmsgreplycontent content = new mpmsgreplycontent { ReplyType = contentItem.type.ToString(), ReplyContent = contentItem.content }; dto.Contents.Add(content); } } MsgReplyBll.SaveMsgRule(dto); } } } return(true); }
public bool GetBoolean(string key) { return(EConvert.ToBoolean(this.m_content[key])); }
public DateTime GetDateTime(string key) { return(EConvert.ToDateTime(this.m_content[key])); }
/// <summary> /// 处理文字请求 /// </summary> /// <returns></returns> public override Senparc.Weixin.MP.Entities.IResponseMessageBase OnTextRequest(RequestMessageText requestMessage) { Task.Run(() => { try { string openId = requestMessage.FromUserName; string replyMode; LogHandler.Info(JsonConvert.SerializeObject(requestMessage)); var contentList = MsgReplyBll.GetReplyInfo(requestMessage.Content, out replyMode); LogHandler.Info(JsonConvert.SerializeObject(contentList)); LogHandler.Info("replyMode" + replyMode); if (contentList != null && contentList.Count > 0) { if (replyMode == AutoReplyMode.random_one.ToString()) { contentList = new List <mpmsgreplycontent>() { contentList[0] }; } foreach (var replyContent in contentList) { switch (replyContent.ReplyType) { //类型枚举参照 Senparc.Weixin.MP.AutoReplyType 枚举 case "text": CustomApi.SendText(BaseClass.AppId, openId, EConvert.ConvertEmojiHtml(Senparc.Weixin.HttpUtility.RequestUtility.UrlDecode(replyContent.ReplyContent))); break; case "img": CustomApi.SendImage(BaseClass.AppId, openId, replyContent.ReplyContent); break; case "news": CustomApi.SendMpNews(BaseClass.AppId, openId, replyContent.ReplyContent); break; } } } else { var replyItem = MpEventBll.GetByKey("ych_automsg"); if (replyItem != null) { switch (replyItem.ReplyType) { case "text": CustomApi.SendText(BaseClass.AppId, openId, EConvert.ConvertEmojiHtml(Senparc.Weixin.HttpUtility.RequestUtility.UrlDecode(replyItem.ReplyContent))); break; case "img": CustomApi.SendImage(BaseClass.AppId, openId, replyItem.ReplyContent); break; } } } } catch (Exception e) { LogHandler.Error($"错误位置:微信文字请求回复\n请求数据:{JsonConvert.SerializeObject(requestMessage)}\n错误信息:{e.StackTrace}"); } }); //将消息转发到客服 var responseMessage = CreateResponseMessage <ResponseMessageTransfer_Customer_Service>(); return(responseMessage); }