using System; using System.Collections.Generic; using System.Xml; using System.Text; using CB.Cache; using CB.Common; namespace CB.Data.Synchronize { /// /// 站外文章显示 /// public class Article { /// /// 调用站外文章 /// /// topSize /// pageSize /// 文章分类 /// 是否WAP站 /// public static IList GetArticleList(int topSize, int pageSize, int cid, bool wap = false) { string key = string.Format("{0}-{1}-{2}", CacheKeys.SyncArticleList, pageSize, cid); var cache = CBCache.GetCacheService(); IList list = cache.GetObject(key) as IList; if (null == list) { list = GetArticleList(pageSize, cid, wap); cache.AddObject(key, list); } if (null == list) return null; IList r = new List(); int count = list.Count; count = topSize > count ? count : topSize; for (int i = 0; i < topSize; i++) { r.Add(list[i]); } return r; } private static IList GetArticleList(int pageSize, int cid, bool wap) { if (string.IsNullOrEmpty(CB.Config.BaseConfigs.GetConfig().SynArticleUrl)) return null; string userName = "55128"; if (wap) userName = "55128wap"; string passKey = "d3d3LjU1MTI4LmNu"; string paras = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("topSize={0}|cid={1}", pageSize, cid))); string sign = Utils.MD5(passKey + userName + paras); string reqParas = string.Format("username={0}¶s={1}&sign={2}", userName, paras, sign); string str = Utils.GetHttpWebResponse(CB.Config.BaseConfigs.GetConfig().SynArticleUrl, reqParas); if (string.IsNullOrEmpty(str)) return null; XmlDocument doc = new XmlDocument(); try { doc.LoadXml(str); } catch { return null; } XmlNodeList nodeList = doc.GetElementsByTagName("data"); if (null == nodeList || 0 == nodeList.Count) return null; IList list = new List(); ArticleInfo entity = null; XmlNode n = null; foreach (XmlNode node in nodeList) { entity = new ArticleInfo(); n = node.SelectSingleNode("title"); if (null != n) entity.Title = n.InnerText.Trim(); n = node.SelectSingleNode("time"); if (null != n) entity.Time = TypeConverter.StrToDateTime(n.InnerText, DateTime.MinValue); n = node.SelectSingleNode("url"); if (null != n) entity.Url = n.InnerText.Trim(); list.Add(entity); } return list; } /// /// 站外文章实体 /// public class ArticleInfo { /// /// 标题 /// public string Title { get; set; } /// /// 文章链接 /// public string Url { get; set; } /// /// 文章时间 /// public DateTime Time { get; set; } } } }