Ejemplo n.º 1
0
        public static WxRequest DeserializeMessage(string rawXml)
        {
            var doc = new XmlDocument();

            doc.LoadXml(rawXml);
            var       rootElement = doc.DocumentElement;
            var       msgType     = rootElement.SelectSingleNode("MsgType");
            var       messageType = msgType.InnerText.ToLower();
            WxRequest request     = null;

            switch (messageType)
            {
            case "text":
                request = new TextWxRequest();
                break;

            case "image":
                request = new ImageWxRequest();
                break;

            case "voice":
                request = new VoiceWxRequest();
                break;

            case "video":
                request = new VideoWxRequest();
                break;

            case "location":
                request = new LocationWxRequest();
                break;

            case "link":
                request = new LinkWxRequest();
                break;

            case "event":
                request = new EventWxRequest();
                break;

            default:
                request = new WxRequest();
                break;
            }
            request.LoadData(rootElement);
            return(request);
        }
Ejemplo n.º 2
0
 //智能回复
 public string OnTextMessageReceived(TextWxRequest request)
 {
     if (request.Content.Contains("text"))
     {
         return(new TextWxResponseXml(request)
         {
             Content = "here is some the sample text:XXXXXXXXXX"
         }.ToXml());
     }
     else if (request.Content.Contains("news"))
     {
         var alist = new List <ArticleItem>
         {
             new ArticleItem()
             {
                 item = new Article()
                 {
                     Description =
                         "新浪体育讯 随着罗本领衔的荷兰的出局,本届世界杯的金球之争中,梅西的竞争对手又少了一个。阿根廷如果能夺得冠军,那么梅西拿到世界杯最佳球员的可能性很大。不过在梅西眼中,冠军奖杯胜过一切,据《阿斯报》报道,梅西在阿根廷国家队内表示,自己宁愿赢得世界杯而不是“金球奖”。"
                     ,
                     PicUrl =
                         "http://i2.sinaimg.cn/2014/news/arg/2014-07-11/U5244P1545T33D24242F682DT20140711120824.jpg"
                     ,
                     Title = "梅西:只想世界杯夺冠不想金球 西媒:对C罗的讽刺"
                     ,
                     Url =
                         "http://2014.sina.com.cn/news/arg/2014-07-11/120824242.shtml?sina-fr=bd.xw.fxw.sports.sjb"
                 }
             }
         };
         return(new NewsWxResponseXml(request)
         {
             Articles = alist
         }.ToXml());
     }
     return("");
 }