123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using CB.Framework;
- using HttpCodeLib;
- using Newtonsoft.Json;
- using System.Collections.Generic;
- using System.Text;
- using CB.Cache;
- namespace CB.Web.tb
- {
- public partial class index : WebPage
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- private static HttpHelpers httpHelpers = new HttpHelpers();
- /// <summary>
- ///
- /// </summary>
- /// <param name="indexType">当前类型 </param>
- /// <param name="maxLength">标题最大</param>
- /// <param name="wap"></param>
- /// <param name="showDate"></param>
- /// <returns></returns>
- protected virtual string GetSynArticleZx(int indexType, int maxLength, bool wap, bool showDate = false)
- {
- StringBuilder sp = new StringBuilder();
- try
- {
- #region 修改成统一的缓存管理 by 大师兄 2017.10.13
- object jsonlist = CBCache.GetCacheService().GetObject("__TopicInterface__GetNewList__");
- #endregion
- if (jsonlist == null)
- {
- //开始调用
- string getZx = System.Configuration.ConfigurationManager.AppSettings["getZX"];
- HttpItems items = new HttpItems
- {
- URL = getZx + "/zx/TopicInterface/GetNewList",
- Method = "GET",
- Accept = "text/html, application/html+xml, */*",
- Timeout = 30 * 1000
- };
- HttpResults hr = httpHelpers.GetHtml(items);
- jsonlist = hr.Html;
- CB.Cache.CBCache.GetCacheService().AddObject("__TopicInterface__GetNewList__", hr.Html);
- }
- dynamic jsonList = JsonConvert.DeserializeObject<dynamic>(jsonlist.ToString());
- var fortstr = "<li><a href=\"{0}\" target=\"_blank\">{1}</a><span></span></li>";
- if (showDate)
- fortstr = "<li><a href=\"{0}\" target=\"_blank\">{1}</a><span class=\"time\">{2}</span></li>";
- switch (indexType)
- {
- case 1:
- foreach (var item in jsonList.data)
- {
- var lst = new List<object>() { "http://zx.55128.cn" + item.SourceUrl, CB.Common.Utils.GetSubString(item.title.ToString(), maxLength, "") };
- if (showDate)
- lst.Add(item.createTime.ToString("MM-dd"));
- sp.AppendFormat(fortstr, lst.ToArray());
- }
- break;
- case 2:
- foreach (var item in jsonList.dataTwo)
- {
- var lst = new List<object>() { "http://zx.55128.cn" + item.SourceUrl, CB.Common.Utils.GetSubString(item.title.ToString(), maxLength, "") };
- if (showDate)
- lst.Add(item.createTime.ToString("MM-dd"));
- sp.AppendFormat(fortstr, lst.ToArray());
- }
- break;
- case 3:
- foreach (var item in jsonList.dataThress)
- {
- var lst = new List<object>() { "http://zx.55128.cn" + item.SourceUrl, CB.Common.Utils.GetSubString(item.title.ToString(), maxLength, "") };
- if (showDate)
- lst.Add(item.createTime.ToString("MM-dd"));
- sp.AppendFormat(fortstr, lst.ToArray());
- }
- break;
- default:
- break;
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- sp = new StringBuilder("");
- }
- return sp.ToString();
- }
- }
- }
|