Example #1
0
        public static BaseMessage GetCorpMessageByXml(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 = EventMessage.LoadFromXml(rootElement);
                //    break;
                //case "image":
                //    returnValue = new CorpImageMessage();
                //    break;
                //case "voice":
                //    returnValue = new CorpVoiceMessage();
                //    break;
                //case "video":
                //    returnValue = new CorpVideoMessage();
                //    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;
        }
Example #2
0
        protected string GetTuwenResponse(TextMessage tm)
        {
            TuwenMessage twMsg = new TuwenMessage();
            twMsg.FromUserName = tm.ToUserName;
            twMsg.ToUserName = tm.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();
        }