Esempio n. 1
0
        /// <summary>
        /// 事件消息解析器
        /// </summary>
        /// <param name="element">消息实体</param>
        /// <returns></returns>
        private RequestMessage GetEventRequestMessage(XElement element)
        {
            Dictionary <string, object> bugobj = new Dictionary <string, object>();
            RequestMessage requestMessage      = null;

            try
            {
                if (element == null)
                {
                    return(null);
                }
                var eventType = (Event)Enum.Parse(typeof(Event), element.Element("Event").Value, true);
                bugobj.Add("eventType", eventType);
                bugobj.Add("element", element);
                switch (eventType)
                {
                case Event.Unsubscribe:
                    return(new RequestEventMessage(element));

                case Event.Location:
                    //  return new RequestLocationEventMessage(element);
                    break;

                case Event.Click:
                    requestMessage = new RequestClickEventMessage(element);
                    break;

                case Event.Scan:
                    requestMessage = new RequestQREventMessage(element);
                    break;

                case Event.Subscribe:
                    requestMessage = GetSubscribeRequestMessageForQR(element);
                    break;

                case Event.View:
                    requestMessage = new RequestViewEventMessage(element);
                    break;
                    //default:
                    //    throw new ArgumentException("event type is error");
                }
            }
            catch (Exception ex)
            {
                this.Log(ex);
            }
            finally
            {
                TxtLogHelper.WriteDebugLog(bugobj);
                TxtLogHelper.WriteLog_Hour(new TxtLogInfoObject()
                {
                    LogMessage = "消息实体",
                    LogObject  = requestMessage,
                    LogType    = EnumLogType.Other
                });
            }

            return(requestMessage);
        }
Esempio n. 2
0
        /// <summary>
        /// 处理请求消息
        /// </summary>
        /// <returns>处理结果</returns>
        public ResponseMessage HandlerRequestMessage()
        {
            Dictionary <string, object> bugobj = new Dictionary <string, object>();

            bugobj.Add("message", this.message);
            var request = new RequestClickEventMessage(this.message.Element);
            /// 返回消息类型
            MsgType msgtype = MsgType.Text;
            // 返回消息
            string result = string.Empty;

            //GetB2CProductInfo getB2CProductInfo = null;
            try
            {
                if (request != null)
                {
                    // 点击菜单事件推送处理
                    bugobj.Add("request", request);
                    switch (request.EventKey)
                    {
                    case "V1001_GOOD":
                        result += "感谢您的支持!";
                        msgtype = MsgType.Text;
                        break;

                    case "V1001_HOT":
                        msgtype = MsgType.Text;
                        MQiushibaike qiushibaike = JsonConvert.DeserializeObject <MQiushibaike>(QiushibaikeHelper.GetJokesByRandom());
                        result = qiushibaike.JokeContent;
                        break;

                    default:
                        break;
                    }
                }

                switch (msgtype)
                {
                case MsgType.Text:
                    return(new ResponseTextMessage(request)
                    {
                        CreateTime = DateTime.Now.Ticks,
                        Content = result,
                    });

                case MsgType.Image:
                    break;

                case MsgType.Voice:
                    break;

                case MsgType.Video:
                    break;

                case MsgType.Location:
                    break;

                case MsgType.Link:
                    break;

                case MsgType.Event:
                    return(new NormalMenuEventMessage(request)
                    {
                        CreateTime = DateTime.Now.Ticks,
                    });

                case MsgType.News:
                case MsgType.Music:
                    break;

                case MsgType.ShortVideo:
                    break;

                case MsgType.transfer_customer_service:
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                TxtLogHelper.WriteLog_Day(new TxtLogInfoObject()
                {
                    LogType    = EnumLogType.Error,
                    LogMessage = string.Format("错误信息{0};堆栈信息{1}", ex.Message, ex.StackTrace),
                });
            }
            finally
            {
                TxtLogHelper.WriteDebugLog(bugobj);
            }

            return(null);
        }
        /// <summary>
        /// 处理请求消息
        /// </summary>
        /// <returns>处理结果</returns>
        public ResponseMessage HandlerRequestMessage()
        {
            Dictionary<string, object> bugobj = new Dictionary<string, object>();
            bugobj.Add("message", this.message);
            var request = new RequestClickEventMessage(this.message.Element);
            /// 返回消息类型
            MsgType msgtype = MsgType.Text;
            // 返回消息
            string result = string.Empty;
            //GetB2CProductInfo getB2CProductInfo = null;
            try
            {
                if (request != null)
                {
                    // 点击菜单事件推送处理
                    bugobj.Add("request", request);
                    switch (request.EventKey)
                    {
                        case "V1001_GOOD":
                            result += "感谢您的支持!";
                            msgtype = MsgType.Text;
                            break;
                        case "V1001_HOT":
                            msgtype = MsgType.Text;
                            MQiushibaike qiushibaike = JsonConvert.DeserializeObject<MQiushibaike>(QiushibaikeHelper.GetJokesByRandom());
                            result = qiushibaike.JokeContent;
                            break;
                        default:
                            break;
                    }
                }

                switch (msgtype)
                {
                    case MsgType.Text:
                        return new ResponseTextMessage(request)
                        {
                            CreateTime = DateTime.Now.Ticks,
                            Content = result,
                        };
                    case MsgType.Image:
                        break;
                    case MsgType.Voice:
                        break;
                    case MsgType.Video:
                        break;
                    case MsgType.Location:
                        break;
                    case MsgType.Link:
                        break;
                    case MsgType.Event:
                        return new NormalMenuEventMessage(request)
                         {
                             CreateTime = DateTime.Now.Ticks,
                         };
                    case MsgType.News:
                    case MsgType.Music:
                        break;
                    case MsgType.ShortVideo:
                        break;
                    case MsgType.transfer_customer_service:
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                TxtLogHelper.WriteLog_Day(new TxtLogInfoObject()
                {
                    LogType = EnumLogType.Error,
                    LogMessage = string.Format("错误信息{0};堆栈信息{1}", ex.Message, ex.StackTrace),
                });
            }
            finally
            {
                TxtLogHelper.WriteDebugLog(bugobj);
            }

            return null;
        }
Esempio n. 4
0
        /// <summary>
        /// 事件消息解析器
        /// </summary>
        /// <param name="element">消息实体</param>
        /// <returns></returns>
        private RequestMessage GetEventRequestMessage(XElement element)
        {
            Dictionary<string, object> bugobj = new Dictionary<string, object>();
            RequestMessage requestMessage = null;
            try
            {
                if (element == null)
                {
                    return null;
                }
                var eventType = (Event)Enum.Parse(typeof(Event), element.Element("Event").Value, true);
                bugobj.Add("eventType", eventType);
                bugobj.Add("element", element);
                switch (eventType)
                {
                    case Event.Unsubscribe:
                        return new RequestEventMessage(element);
                    case Event.Location:
                        //  return new RequestLocationEventMessage(element);
                        break;
                    case Event.Click:
                        requestMessage = new RequestClickEventMessage(element);
                        break;
                    case Event.Scan:
                        requestMessage = new RequestQREventMessage(element);
                        break;
                    case Event.Subscribe:
                        requestMessage = GetSubscribeRequestMessageForQR(element);
                        break;
                    case Event.View:
                        requestMessage = new RequestViewEventMessage(element);
                        break;
                    //default:
                    //    throw new ArgumentException("event type is error");
                }
            }
            catch (Exception ex)
            {
                this.Log(ex);
            }
            finally
            {
                TxtLogHelper.WriteDebugLog(bugobj);
                TxtLogHelper.WriteLog_Hour(new TxtLogInfoObject()
                {
                    LogMessage = "消息实体",
                    LogObject = requestMessage,
                    LogType = EnumLogType.Other
                });
            }

            return requestMessage;
        }