Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        //创建菜单
        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("&amp;", "&");
            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 });
        }
Ejemplo n.º 4
0
        protected void DeleteReplyEvent()
        {
            var  key    = Request["eventKey"];
            bool result = MpEventBll.DeletEventByKey(key);

            Json(new { state = result });
        }
Ejemplo n.º 5
0
        protected void GetReplyEvent()
        {
            string key   = Request["eventKey"];
            var    model = MpEventBll.GetByKey(key);

            if (model != null)
            {
                Json(new { state = true, data = model });
                return;
            }
            Json(new { state = false });
        }
Ejemplo n.º 6
0
        protected void SaveReplyEvent()
        {
            string key          = Request["eventKey"];
            string eventType    = Request["eventType"];
            string replyType    = Request["replyType"];
            string replyContent = Request["replyContent"];
            bool   result       = MpEventBll.SaveEventInfo(new mpeventreply()
            {
                EventKey     = key,
                EventType    = eventType,
                ReplyType    = replyType,
                ReplyContent = replyContent
            });

            Json(new { state = result });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Click事件接收
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            Task.Run(() =>
            {
                try
                {
                    string key    = requestMessage.EventKey;
                    string openId = requestMessage.FromUserName;
                    var replyItem = MpEventBll.GetByKey(key);
                    if (replyItem != null)
                    {
                        switch (replyItem.ReplyType)
                        {
                        case "text":
                            CustomApi.SendText(BaseClass.AppId, openId, replyItem.ReplyContent);
                            break;

                        case "img":
                            CustomApi.SendImage(BaseClass.AppId, openId, replyItem.ReplyContent);
                            break;

                        case "news":
                            CustomApi.SendMpNews(BaseClass.AppId, openId, replyItem.ReplyContent);
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    LogHandler.Error($"错误位置:微信CLIKC事件回复\n请求数据:{JsonConvert.SerializeObject(requestMessage)}\n错误信息:{e.StackTrace}");
                }
            });
            var responseMessage = new SuccessResponseMessage();

            return(responseMessage);
        }
Ejemplo n.º 8
0
        /// <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);
        }