123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using System.Xml;
- using System.Text;
- using CB.Cache;
- using CB.Common;
- namespace CB.Data.Synchronize
- {
- /// <summary>
- /// 站外文章显示
- /// </summary>
- public class Article
- {
- /// <summary>
- /// 调用站外文章
- /// </summary>
- /// <param name="topSize">topSize</param>
- /// <param name="pageSize">pageSize</param>
- /// <param name="cid">文章分类</param>
- /// <param name="wap">是否WAP站</param>
- /// <returns></returns>
- public static IList<ArticleInfo> 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<ArticleInfo> list = cache.GetObject(key) as IList<ArticleInfo>;
- if (null == list)
- {
- list = GetArticleList(pageSize, cid, wap);
- cache.AddObject(key, list);
- }
- if (null == list)
- return null;
- IList<ArticleInfo> r = new List<ArticleInfo>();
- 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<ArticleInfo> 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<ArticleInfo> list = new List<ArticleInfo>();
- 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;
- }
- /// <summary>
- /// 站外文章实体
- /// </summary>
- public class ArticleInfo
- {
- /// <summary>
- /// 标题
- /// </summary>
- public string Title { get; set; }
- /// <summary>
- /// 文章链接
- /// </summary>
- public string Url { get; set; }
- /// <summary>
- /// 文章时间
- /// </summary>
- public DateTime Time { get; set; }
- }
- }
- }
|