/// <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> /// <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); }