/// <summary> /// 响应图文信息 /// </summary> /// <param name="info">基类</param> /// <param name="list">返回的图文注意不能超过十个</param> /// <returns></returns> public string GetresponseNews(BaseMessage info, List <ArticleEntity> list) { ResponseNews model = new ResponseNews(info); model.Articles.AddRange(list); return(model.ToXml()); }
public async Task GetNewsAsync() { Settings settings = new Settings(); NewsService newsService = new NewsService(settings); ResponseNews data = await newsService.GetNewsAsync("Petrobras"); Assert.IsTrue(data.TotalResults > 0); }
/// <summary> /// 订阅或者显示公司信息 /// </summary> /// <param name="info"></param> /// <returns></returns> private string ShowCompanyInfo(BaseMessage info) { string result = ""; //使用在微信平台上的图文信息(单图文信息) ResponseNews response = new ResponseNews(info); ArticleEntity entity = new ArticleEntity(); entity.Title = "广州爱奇迪软件科技有限公司"; entity.Description = "欢迎关注广州爱奇迪软件--专业的单位信息化软件和软件开发框架提供商,我们立志于为客户提供最好的软件及服务。\r\n"; entity.Description += "我们是一家极富创新性的软件科技公司,从事研究、开发并销售最可靠的、安全易用的技术产品及优质专业的服务,帮助全球客户和合作伙伴取得成功。\r\n......(此处省略1000字,哈哈)"; entity.PicUrl = "http://www.iqidi.com/WeixinImage/company.png"; entity.Url = "http://www.iqidi.com"; response.Articles.Add(entity); result = response.ToXml(); return(result); }
/// <summary> /// 响应图文 /// </summary> /// <param name="context"></param> /// <param name="responseNews"></param> private void SendResponseNews(HttpContext context, ResponseNews responseNews) { string data = @" <xml> <ToUserName><![CDATA[{0}]]></ToUserName> <FromUserName><![CDATA[{1}]]></FromUserName> <CreateTime>{2}</CreateTime> <MsgType><![CDATA[{3}]]></MsgType> <ArticleCount>{4}</ArticleCount> <Articles> {5} </Articles> </xml> "; string dataArticleItem = @" <item> <Title><![CDATA[{0}]]></Title> <Description><![CDATA[{1}]]></Description> <PicUrl><![CDATA[{2}]]></PicUrl> <Url><![CDATA[{3}]]></Url> </item>"; StringBuilder sbArticles = new StringBuilder(); foreach (var item in responseNews.Articles) { sbArticles.Append(string.Format(dataArticleItem, item.Title, item.Description, item.PicUrl, item.Url)); } data = string.Format(data, responseNews.ToUserName, //{0} responseNews.FromUserName, //{1} responseNews.CreateTime.Ticks, //{2} responseNews.MsgType.ToString().ToLower(), //{3} responseNews.ArticleCount, //{4}, sbArticles //{5} ); SendResponse(context, data); }
public BaseMessage GetResponseByEvent(RequestEvent request) { if (string.Equals(request.Event, EventType.Click.ToString(), StringComparison.CurrentCultureIgnoreCase)) { var eventContext = GetContextByKey(request.EventKey); if (eventContext == null) { return(null); } switch (eventContext.MsgType) { case (int)ResponseType.News: var newsResponse = new ResponseNews(request) { ArticleCount = eventContext.ArticleContent.Count, Articles = eventContext.ArticleContent.OrderBy(m => m.Sort).Select(content => new ArticleEntity() { Title = content.Content.Title, PicUrl = content.Content.Image, Description = content.Content.Description, Url = content.Content.Url, }).ToList() }; return(newsResponse); case (int)ResponseType.Text: var textResponse = new ResponseText(request); var articles = eventContext.ArticleContent.FirstOrDefault(); var text = articles == null ? "" : articles.Content.Description; textResponse.Content = text; return(textResponse); } } return(null); }