Beispiel #1
0
        public static ReqMsgBase GetReqMsgEntity(XDocument doc)
        {
            ReqMsgBase reqMsg  = null;
            string     msgType = doc.Root.Element(CommonEnum.MSG_TYPE).Value;

            switch (msgType)
            {
            case MsgTypeEnum.TEXT:
                reqMsg = new ReqMsgText();
                break;

            case MsgTypeEnum.EVENT:
                string eventType = doc.Root.Element(CommonEnum.EVENT_TYPE).Value;
                switch (eventType)
                {
                case "subscribe":
                    reqMsg = new ReqEventSubscribe();
                    break;

                case "CLICK":
                    reqMsg = new ReqEventClick();
                    break;
                }
                break;
            }
            EntityXmlHelper.FillEntityWithXml(reqMsg, doc);
            return(reqMsg);
        }
        /// <summary>
        /// 创建处理器
        /// </summary>
        /// <param name="requestXml">请求的xml</param>
        /// <returns>IHandler对象</returns>
        public static IHandler CreateHandler(ReqMsgBase reqMsg)
        {
            IHandler handler = null;

            if (reqMsg != null)
            {
                string msgType = reqMsg.MsgType;

                switch (msgType)
                {
                case MsgTypeEnum.TEXT:
                    handler = new TextHandler((ReqMsgText)reqMsg);
                    break;

                case MsgTypeEnum.EVENT:
                    ReqEventBase reqEvent  = (ReqEventBase)reqMsg;
                    string       eventType = reqEvent.Event;
                    switch (eventType)
                    {
                    case "subscribe":
                        handler = new SubscribeEventHandler((ReqEventSubscribe)reqMsg);
                        break;

                    case "CLICK":
                        handler = new ClickEventHandler((ReqEventClick)reqMsg);
                        break;
                    }
                    break;
                }
            }

            return(handler);
        }
Beispiel #3
0
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <returns></returns>
        public string ResponseMsg(ReqMsgBase reqMsg)
        {
            IHandler handler = HandlerFactory.CreateHandler(reqMsg);

            if (handler != null)
            {
                return(handler.HandleRequest());
            }

            return(string.Empty);
        }
Beispiel #4
0
 public string Execute()
 {
     if (request.HttpMethod.ToUpper().Equals("GET"))
     {
         string signature = request.QueryString[CommonEnum.SIGNATURE];
         string timestamp = request.QueryString[CommonEnum.TIMESTAMP];
         string nonce     = request.QueryString[CommonEnum.NONCE];
         if (CheckSignature.Check(signature, timestamp, nonce))
         {
             return(HttpContext.Current.Request.QueryString[CommonEnum.ECHOSTR]);
         }
         else
         {
             return(string.Empty);
         }
     }
     else
     {
         string     requestXml = RequestUtility.ReadRequest(request);
         ReqMsgBase reqMsg     = ReqMsgFactory.GetReqMsgEntity(XDocument.Parse(requestXml));
         return(ResponseMsg(reqMsg));
     }
 }