Exemplo n.º 1
0
        public string SendNews(SNews model)
        {
            string art="";
            foreach(var one in model.Articles)
            {

                art+=string.Format(@"
                                    <item>
                                    <Title><![CDATA[{0}]]></Title>
                                    <Description><![CDATA[{1}]]></Description>
                                    <PicUrl><![CDATA[{2}]]></PicUrl>
                                    <Url><![CDATA[{3}]]></Url>
                                    </item>",one.Title,one.Description,one.PicUrl,one.Url);

            }

            return string.Format(@"<xml>
                                    <ToUserName><![CDATA[{0}]]></ToUserName>
                                    <FromUserName><![CDATA[{1}]]></FromUserName>
                                    <CreateTime>{2}</CreateTime>
                                    <MsgType><![CDATA[{3}]]></MsgType>
                                    <ArticleCount>{4}</ArticleCount>
                                    <Articles>{5}</Articles>
                                    </xml> ",model.ToUserName,model.FromUserName,model.CreateTime,model.MsgType,
                                            model.ArticleCount,art);
        }
Exemplo n.º 2
0
        //接收到文本消息  处理
        public void DoText(Dictionary<string, string> model)
        {
            SText mT = new SText();
            string text = ReadXml.ReadModel("Content", model).Trim();
            mT.FromUserName = ReadXml.ReadModel("ToUserName", model);
            mT.ToUserName = ReadXml.ReadModel("FromUserName", model);
            mT.CreateTime = long.Parse(ReadXml.ReadModel("CreateTime", model));
            if (text == "?" || text == "?" || text == "帮助")
            {
                mT.Content = mT.Content = ReadXml.Menu();
                mT.MsgType = "text";
                ReadXml.ResponseToEnd(DALWei.SendText(mT));
            }
            else
            {

                SNews mN = new SNews();
                mN.FromUserName = ReadXml.ReadModel("ToUserName", model);
                mN.ToUserName = ReadXml.ReadModel("FromUserName", model);
                mN.CreateTime = long.Parse(ReadXml.ReadModel("CreateTime", model));
                mN.MsgType = "news";

                //   以下为文章内容,  实际使用时,此处应该是一个跟数据库交互的方法,查询出文章
                //文章条数,  文章内容等   都应该由数据库查询出来的数据决定   这里测试,就模拟几条

                mN.ArticleCount = 5;
                List<ArticlesModel> listNews = new List<ArticlesModel>();
                for (int i = 0; i < 5; i++)
                {
                    ArticlesModel ma = new ArticlesModel();
                    ma.Title = "这是第" + (i + 1).ToString() + "篇文章";
                    ma.Description = "-描述-" + i.ToString() + "-描述-";
                    ma.PicUrl = "http://image6.tuku.cn/pic/wallpaper/dongwu/taipingniaogaoqingbizhi/s00" + (i + 1).ToString() + ".jpg";
                    ma.Url = "http://www.cnblogs.com/mochen/";
                    listNews.Add(ma);
                }
                mN.Articles = listNews;
                ReadXml.ResponseToEnd(DALWei.SendNews(mN));
            }
        }