Exemplo n.º 1
0
 public virtual AbstractResponse OnEvent_LocationRequest(LocationEventRequest locationEventRequest)
 {
     return(this.DefaultResponse(locationEventRequest));
 }
Exemplo n.º 2
0
 public override AbstractResponse OnEvent_LocationRequest(LocationEventRequest locationEventRequest)
 {
     return(base.OnEvent_LocationRequest(locationEventRequest));
 }
Exemplo n.º 3
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType  msgType = MsgTypeHelper.GetMsgType(doc);
            AbstractRequest entity  = null;

            switch (msgType)
            {
            case RequestMsgType.Text:
                entity = new TextRequest();
                break;

            case RequestMsgType.Image:
                entity = new ImageRequest();
                break;

            case RequestMsgType.Voice:
                entity = new VoiceRequest();
                break;

            case RequestMsgType.Video:
                entity = new VideoRequest();
                break;

            case RequestMsgType.Location:
                entity = new LocationRequest();
                break;

            case RequestMsgType.Link:
                entity = new LinkRequest();
                break;

            case RequestMsgType.Event:
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                    entity = new SubscribeEventRequest();
                    goto Label_00D7;

                case RequestEventType.UnSubscribe:
                    entity = new UnSubscribeEventRequest();
                    goto Label_00D7;

                case RequestEventType.Scan:
                    entity = new ScanEventRequest();
                    goto Label_00D7;

                case RequestEventType.Location:
                    entity = new LocationEventRequest();
                    goto Label_00D7;

                case RequestEventType.Click:
                    entity = new ClickEventRequest();
                    goto Label_00D7;

                case RequestEventType.MASSSENDJOBFINISH:
                    entity = new MassendJobFinishEventRequest();
                    goto Label_00D7;
                }
                throw new ArgumentOutOfRangeException();

            default:
                throw new ArgumentOutOfRangeException();
            }
Label_00D7:
            EntityHelper.FillEntityWithXml <AbstractRequest>(entity, doc);
            Regex regex = new Regex(@"<MsgID>(?<url>\d+)</MsgID>");

            if (entity.MsgId == 0L)
            {
                Match match = Regex.Match(doc.Root.ToString(), @"<MsgID>(?<msgid>\d+)</MsgID>", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    entity.MsgId      = long.Parse(match.Groups["msgid"].Value);
                    entity.CreateTime = DateTime.Now;
                }
            }
            return(entity);
        }
Exemplo n.º 4
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType  msgType = MsgTypeHelper.GetMsgType(doc);
            AbstractRequest entity  = null;

            switch (msgType)
            {
            case RequestMsgType.Text:
                entity = new TextRequest();
                break;

            case RequestMsgType.Image:
                entity = new ImageRequest();
                break;

            case RequestMsgType.Voice:
                entity = new VoiceRequest();
                break;

            case RequestMsgType.Video:
                entity = new VideoRequest();
                break;

            case RequestMsgType.Location:
                entity = new LocationRequest();
                break;

            case RequestMsgType.Link:
                entity = new LinkRequest();
                break;

            case RequestMsgType.Event:
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                    entity = new SubscribeEventRequest();
                    goto Label_00C5;

                case RequestEventType.UnSubscribe:
                    entity = new UnSubscribeEventRequest();
                    goto Label_00C5;

                case RequestEventType.Scan:
                    entity = new ScanEventRequest();
                    goto Label_00C5;

                case RequestEventType.Location:
                    entity = new LocationEventRequest();
                    goto Label_00C5;

                case RequestEventType.Click:
                    entity = new ClickEventRequest();
                    goto Label_00C5;
                }
                throw new ArgumentOutOfRangeException();

            default:
                throw new ArgumentOutOfRangeException();
            }
Label_00C5:
            EntityHelper.FillEntityWithXml <AbstractRequest>(entity, doc);
            return(entity);
        }
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType  msgType     = MsgTypeHelper.GetMsgType(doc);
            AbstractRequest textRequest = null;

            switch (msgType)
            {
            case RequestMsgType.Text:
            {
                textRequest = new TextRequest();
                break;
            }

            case RequestMsgType.Image:
            {
                textRequest = new ImageRequest();
                break;
            }

            case RequestMsgType.Voice:
            {
                textRequest = new VoiceRequest();
                break;
            }

            case RequestMsgType.Video:
            {
                textRequest = new VideoRequest();
                break;
            }

            case RequestMsgType.Location:
            {
                textRequest = new LocationRequest();
                break;
            }

            case RequestMsgType.Link:
            {
                textRequest = new LinkRequest();
                break;
            }

            case RequestMsgType.Event:
            {
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                {
                    textRequest = new SubscribeEventRequest();
                    break;
                }

                case RequestEventType.UnSubscribe:
                {
                    textRequest = new UnSubscribeEventRequest();
                    break;
                }

                case RequestEventType.Scan:
                {
                    textRequest = new ScanEventRequest();
                    break;
                }

                case RequestEventType.Location:
                {
                    textRequest = new LocationEventRequest();
                    break;
                }

                case RequestEventType.Click:
                {
                    textRequest = new ClickEventRequest();
                    break;
                }

                default:
                {
                    throw new ArgumentOutOfRangeException();
                }
                }
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }
            EntityHelper.FillEntityWithXml <AbstractRequest>(textRequest, doc);
            return(textRequest);

            throw new ArgumentOutOfRangeException();
        }
Exemplo n.º 6
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            AbstractRequest abstractRequest;

            switch (MsgTypeHelper.GetMsgType(doc))
            {
            case RequestMsgType.Text:
                abstractRequest = new TextRequest();
                break;

            case RequestMsgType.Image:
                abstractRequest = new ImageRequest();
                break;

            case RequestMsgType.Voice:
                abstractRequest = new VoiceRequest();
                break;

            case RequestMsgType.Video:
                abstractRequest = new VideoRequest();
                break;

            case RequestMsgType.Location:
                abstractRequest = new LocationRequest();
                break;

            case RequestMsgType.Link:
                abstractRequest = new LinkRequest();
                break;

            case RequestMsgType.Event:
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                    abstractRequest = new SubscribeEventRequest();
                    break;

                case RequestEventType.UnSubscribe:
                    abstractRequest = new UnSubscribeEventRequest();
                    break;

                case RequestEventType.Scan:
                    abstractRequest = new ScanEventRequest();
                    break;

                case RequestEventType.Location:
                    abstractRequest = new LocationEventRequest();
                    break;

                case RequestEventType.Click:
                    abstractRequest = new ClickEventRequest();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            EntityHelper.FillEntityWithXml <AbstractRequest>(abstractRequest, doc);
            return(abstractRequest);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 从文本信息中, 获取事件数据.
        /// </summary>
        /// <param name="weixin"></param>
        /// <returns></returns>
        public AbstractRequest ReadEvent(string weixin)
        {
            XmlDocument doc = new XmlDocument();

            //读取xml字符串
            doc.LoadXml(weixin);
            XmlElement root = doc.DocumentElement;

            // 获取收到的消息类型。文本(text),图片(image),语音等。
            XmlNode MsgType     = root.SelectSingleNode("MsgType");
            string  messageType = MsgType.InnerText;

            if (messageType != "event")
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("不是事件,忽略处理。");
                }
                return(null);
            }


            AbstractRequest resultEvent = null;



            XmlNode Event     = root.SelectSingleNode("Event");
            string  eventType = Event.InnerText;

            try
            {
                switch (eventType)
                {
                case EventType.SubscribeEventType:
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("检测到用户订阅事件,尝试解析..");
                    }
                    resultEvent = new SubscribeEventRequest(doc);
                    break;


                case EventType.UnsubscribeEventType:
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("检测到用户取消订阅事件,尝试解析..");
                    }
                    resultEvent = new UnsubscribeEventRequest(doc);
                    break;

                case EventType.ScanEventType:
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("检测到用户扫码事件,尝试解析..");
                    }
                    resultEvent = new ScanEventRequest(doc);
                    break;


                case EventType.LocationEventType:
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("检测到用户上报地理位置事件,尝试解析..");
                    }
                    resultEvent = new LocationEventRequest(doc);
                    break;


                case EventType.ClickEventType:
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("检测到用户自定义菜单事件,尝试解析..");
                    }
                    resultEvent = new ClickEventRequest(doc);
                    break;


                default:
                    logger.WarnFormat("检测到了无法识别的信息:{0}", eventType);
                    break;
                }


                if (logger.IsDebugEnabled)
                {
                    logger.DebugFormat("消息解析结果:{0}", resultEvent);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

            return(resultEvent);
        }
Exemplo n.º 8
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType msgType = MsgTypeHelper.GetMsgType(doc);

            AbstractRequest entity = null;

            // System.IO.File.AppendAllText(@"E:\home\LocalUser\580442\www\humowang\api\type.txt", "msgType:" + msgType + "\r\n");
            switch (msgType)
            {
            case RequestMsgType.Text:
            {
                entity = new TextRequest();
                break;
            }

            case RequestMsgType.Image:
            {
                entity = new ImageRequest();
                break;
            }

            case RequestMsgType.Voice:
            {
                entity = new VoiceRequest();
                break;
            }

            case RequestMsgType.Video:
            {
                entity = new VideoRequest();
                break;
            }

            case RequestMsgType.Location:
            {
                entity = new LocationRequest();
                break;
            }

            case RequestMsgType.Link:
            {
                entity = new LinkRequest();
                break;
            }

            case RequestMsgType.Event:
            {
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                {
                    entity = new SubscribeEventRequest();
                    //goto Label_00C5;
                    break;
                }

                case RequestEventType.UnSubscribe:
                {
                    entity = new UnSubscribeEventRequest();
                    //goto Label_00C5;
                    break;
                }

                case RequestEventType.Scan:
                {
                    entity = new ScanEventRequest();
                    // goto Label_00C5;
                    break;
                }

                case RequestEventType.Location:
                {
                    entity = new LocationEventRequest();
                    // goto Label_00C5;
                    break;
                }

                case RequestEventType.Click:
                {
                    entity = new ClickEventRequest();
                    // goto Label_00C5;
                    break;
                }

                case RequestEventType.VIEW:
                {
                    entity = new ViewEventRequest();
                    break;
                }

                default:
                {
                    throw new ArgumentOutOfRangeException();
                    // break;
                }
                }
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }

            //Label_00C5:
            EntityHelper.FillEntityWithXml <AbstractRequest>(entity, doc);

            return(entity);
        }
Exemplo n.º 9
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            AbstractRequest abstractRequest;

            switch (MsgTypeHelper.GetMsgType(doc))
            {
            case RequestMsgType.Text:
                abstractRequest = new TextRequest();
                break;

            case RequestMsgType.Image:
                abstractRequest = new ImageRequest();
                break;

            case RequestMsgType.Voice:
                abstractRequest = new VoiceRequest();
                break;

            case RequestMsgType.Video:
                abstractRequest = new VideoRequest();
                break;

            case RequestMsgType.Location:
                abstractRequest = new LocationRequest();
                break;

            case RequestMsgType.Link:
                abstractRequest = new LinkRequest();
                break;

            case RequestMsgType.Event:
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                    abstractRequest = new SubscribeEventRequest();
                    break;

                case RequestEventType.UnSubscribe:
                    abstractRequest = new UnSubscribeEventRequest();
                    break;

                case RequestEventType.Scan:
                    abstractRequest = new ScanEventRequest();
                    break;

                case RequestEventType.Location:
                    abstractRequest = new LocationEventRequest();
                    break;

                case RequestEventType.Click:
                    abstractRequest = new ClickEventRequest();
                    break;

                case RequestEventType.MASSSENDJOBFINISH:
                    abstractRequest = new MassendJobFinishEventRequest();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            EntityHelper.FillEntityWithXml <AbstractRequest>(abstractRequest, doc);
            Regex regex = new Regex("<MsgID>(?<url>\\d+)</MsgID>");

            if (abstractRequest.MsgId == 0L)
            {
                Match match = Regex.Match(doc.Root.ToString(), "<MsgID>(?<msgid>\\d+)</MsgID>", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    abstractRequest.MsgId      = long.Parse(match.Groups["msgid"].Value);
                    abstractRequest.CreateTime = DateTime.Now;
                }
            }
            return(abstractRequest);
        }
Exemplo n.º 10
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType msgType = MsgTypeHelper.GetMsgType(doc);
            AbstractRequest entity = null;
            switch (msgType)
            {
                case RequestMsgType.Text:
                    entity = new TextRequest();
                    break;

                case RequestMsgType.Image:
                    entity = new ImageRequest();
                    break;

                case RequestMsgType.Voice:
                    entity = new VoiceRequest();
                    break;

                case RequestMsgType.Video:
                    entity = new VideoRequest();
                    break;

                case RequestMsgType.Location:
                    entity = new LocationRequest();
                    break;

                case RequestMsgType.Link:
                    entity = new LinkRequest();
                    break;

                case RequestMsgType.Event:
                    //switch (EventTypeHelper.GetEventType(doc))
                    switch (doc.Root.Element("Event").Value.ToUpper())
                    {
                        //case RequestEventType.Subscribe:
                        case "SUBSCRIBE"://订阅(关注)
                            entity = new SubscribeEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.UnSubscribe:
                        case "UNSUBSCRIBE"://取消订阅(关注)
                            entity = new UnSubscribeEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.Scan:
                        case "SCAN"://二维码扫描
                            entity = new ScanEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.Location:
                        case "LOCATION"://地理位置
                            entity = new LocationEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.Click:
                        case "CLICK"://菜单点击
                            entity = new ClickEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.MASSSENDJOBFINISH:
                        case "MASSSENDJOBFINISH":
                            entity = new MassendJobFinishEventRequest();
                            goto Label_00D1;

                        case "VIEW":
                            entity = new ViewEventRequest();
                            goto Label_00D1;

                        //default://其他意外类型(也可以选择抛出异常)
                        //    entity = new AbstractRequest();
                        //    goto Label_00D1;

                    }
                    throw new ArgumentOutOfRangeException();

                default:
                    throw new ArgumentOutOfRangeException();
            }
        Label_00D1:
            //EntityHelper.FillEntityWithXml<AbstractRequest>(entity, doc);
            //修改无法解析完整数据 2017.7.4
            EntityHelper.FillEntityWithXml(entity, doc);
            new Regex(@"<MsgID>(?<url>\d+)</MsgID>");
            if (entity.MsgId == 0L)
            {
                Match match = Regex.Match(doc.Root.ToString(), @"<MsgID>(?<msgid>\d+)</MsgID>", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    entity.MsgId = long.Parse(match.Groups["msgid"].Value);
                    entity.CreateTime = DateTime.Now;
                }
            }
            return entity;
        }