Exemplo n.º 1
0
        /// <summary>
        /// 从xml数据加载文本消息
        /// </summary>
        /// <param name="xml"></param>
        public static EventMessage LoadFromXml(XElement rootElement)
        {
            EventMessage em = null;

            string eventValue = rootElement.Element(WeiXinConstants.EVENT).Value.ToLower();

            switch (eventValue)
            {
            case "click":
            case "view":
                em = new MenuEventMessage();
                break;

            case "location":
                em = new LocationMessage();
                break;

            default:
                em = new MenuEventMessage();
                break;
            }

            em.FromXML(rootElement);

            return(em);
        }
Exemplo n.º 2
0
        public string Handle_MenuEventMessage(MenuEventMessage message)
        {
            //Log4netHelper.Write("Handle_MenuEventMessage");
            string result = string.Empty;
            if (message != null && message.EventKey != null)
            {
                switch (message.EventKey.ToUpper())
                {
                    //case "BTN_LOGIN":
                    //    result = HandleLoginClickAndGetResponse(message);
                    //    break;
                    //case "BTN_LOGOUT":
                    //    result = HandleLogoutClickAndGetResponse(message);
                    //    break;
                    //case "MY_MENU":
                    //    result = HandleMyMenuClickAndGetResponse(message);
                    //    break;
                    //case "PERSONAL_INFO":
                    //    result = HandlePersonalInfoClickAndGetResponse(message);
                    //    break;
                    case "BTN_OUTLINE":
                        result = HandleOutlineClickAndGetResponse(message);
                        break;
                }
            }

            return result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 从xml数据加载文本消息
        /// </summary>
        /// <param name="xml"></param>
        public static EventMessage LoadFromXml(XElement rootElement)
        {
            EventMessage em = null;

            string eventValue = rootElement.Element(WeiXinConstants.EVENT).Value.ToLower();

            switch (eventValue)
            {
                case "click":
                case "view":
                    em = new MenuEventMessage();
                    break;
                case "location":
                    em = new LocationMessage();
                    break;
                default:
                    em = new MenuEventMessage();
                    break;
            }

            em.FromXML(rootElement);

            return em;
        }
Exemplo n.º 4
0
        public static BaseMessage GetMessageByXml(string xmlStr)
        {
            if (string.IsNullOrEmpty(xmlStr))
            {
                //Log4netHelper.Write("xmlStr is null, return null");
                return null;
            }

            XDocument doc = XDocument.Parse(xmlStr);

            XElement rootElement = doc.Root;

            XElement msgTypeElement = rootElement.Element(WeiXinConstants.MSG_TYPE);

            if (msgTypeElement == null)
            {
                //Log4netHelper.Write("msgTypeElement is null, return null");
                return null;
            }

            string msgType = msgTypeElement.Value;
            //Log4netHelper.Write("msgType :" + msgType);

            BaseMessage returnValue;
            switch (msgType)
            {
                case "text":
                    returnValue = new TextMessage();
                    break;
                case "event":
                    returnValue = new MenuEventMessage();
                    break;
                //case "image":
                //    returnValue = new ImageMessage();
                //    break;
                //case "voice":
                //    returnValue = new VoiceMessage();
                //    break;
                //case "video":
                //    returnValue = new VideoMessage();
                //    break;
                //case "music":
                //    returnValue = new MusicMessage();
                //    break;
                case "news":
                    returnValue = new TuwenMessage();
                    break;
                default:
                    returnValue = null;
                    break;
            }

            if (returnValue != null)
                returnValue.FromXML(rootElement);

            return returnValue;
        }
Exemplo n.º 5
0
        public static BaseMessage GetMessageByXml(string xmlStr)
        {
            if (string.IsNullOrEmpty(xmlStr))
            {
                //Log4netHelper.Write("xmlStr is null, return null");
                return(null);
            }

            XDocument doc = XDocument.Parse(xmlStr);

            XElement rootElement = doc.Root;

            XElement msgTypeElement = rootElement.Element(WeiXinConstants.MSG_TYPE);

            if (msgTypeElement == null)
            {
                //Log4netHelper.Write("msgTypeElement is null, return null");
                return(null);
            }

            string msgType = msgTypeElement.Value;
            //Log4netHelper.Write("msgType :" + msgType);

            BaseMessage returnValue;

            switch (msgType)
            {
            case "text":
                returnValue = new TextMessage();
                break;

            case "event":
                returnValue = new MenuEventMessage();
                break;

            //case "image":
            //    returnValue = new ImageMessage();
            //    break;
            //case "voice":
            //    returnValue = new VoiceMessage();
            //    break;
            //case "video":
            //    returnValue = new VideoMessage();
            //    break;
            //case "music":
            //    returnValue = new MusicMessage();
            //    break;
            case "news":
                returnValue = new TuwenMessage();
                break;

            default:
                returnValue = null;
                break;
            }

            if (returnValue != null)
            {
                returnValue.FromXML(rootElement);
            }

            return(returnValue);
        }
Exemplo n.º 6
0
        //protected string HandleLoginClickAndGetResponse(EventMessage message)
        //{
        //    TextMessage tm = new TextMessage();
        //    tm.ToUserName = message.FromUserName;
        //    tm.FromUserName = message.ToUserName;
        //    tm.CreateTime = WeiXinHelper.GetNowTime();
        //    tm.Content = AuthUtility.GetAuthResult(message);
        //    string returnValue = tm.GetResponseString();
        //    return returnValue;
        //}
        //private string HandleLogoutClickAndGetResponse(EventMessage message)
        //{
        //    TextMessage tm = new TextMessage();
        //    tm.ToUserName = message.FromUserName;
        //    tm.FromUserName = message.ToUserName;
        //    tm.CreateTime = WeiXinHelper.GetNowTime();
        //    tm.Content = AuthUtility.GetLogoutResult(message);
        //    string returnValue = tm.GetResponseString();
        //    return returnValue;
        //}
        private string HandleOutlineClickAndGetResponse(MenuEventMessage message)
        {
            TuwenMessage twMsg = new TuwenMessage();
            twMsg.FromUserName = message.ToUserName;
            twMsg.ToUserName = message.FromUserName;
            twMsg.CreateTime = WeiXinHelper.GetNowTime();

            TuwenArticleMessage article1 = new TuwenArticleMessage()
            {
                Title = "交大红娘团队",
                Description = "交大红娘团队成员有吴斯一, 陈楠,石皓,刘崇宵",
                PicUrl = "http://img.taopic.com/uploads/allimg/130716/318769-130G60Q62985.jpg",
                Url = "http://img.taopic.com/uploads/allimg/130716/318769-130G60Q62985.jpg"
            };

            TuwenArticleMessage article2 = new TuwenArticleMessage()
            {
                Title = "吴斯一,CEO",
                Description = "吴斯一,CEO",
                PicUrl = "http://e.hiphotos.baidu.com/image/h%3D200/sign=9e12075d6e224f4a4899741339f69044/d1a20cf431adcbef5ae00f7dafaf2edda2cc9ff0.jpg",
                Url = "http://e.hiphotos.baidu.com/image/h%3D200/sign=9e12075d6e224f4a4899741339f69044/d1a20cf431adcbef5ae00f7dafaf2edda2cc9ff0.jpg"
            };

            TuwenArticleMessage article3 = new TuwenArticleMessage()
            {
                Title = "陈楠,CTO",
                Description = "陈楠,CTO",
                PicUrl = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg",
                Url = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg"
            };

            TuwenArticleMessage article4 = new TuwenArticleMessage()
            {
                Title = "石皓,CFO",
                Description = "石皓,CFO",
                PicUrl = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg",
                Url = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg"
            };

            TuwenArticleMessage article5 = new TuwenArticleMessage()
            {
                Title = "刘崇宵,COO",
                Description = "刘崇宵,COO",
                PicUrl = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg",
                Url = "http://g.hiphotos.baidu.com/image/pic/item/9345d688d43f879412576a35d11b0ef41bd53a04.jpg"
            };

            twMsg.AddArticle(article1);
            twMsg.AddArticle(article2);
            twMsg.AddArticle(article3);
            twMsg.AddArticle(article4);
            twMsg.AddArticle(article5);

            return twMsg.GetResponseString();
        }