index.aspx.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using CB.Framework;
  3. using HttpCodeLib;
  4. using Newtonsoft.Json;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using CB.Cache;
  8. namespace CB.Web.tb
  9. {
  10. public partial class index : WebPage
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. }
  15. private static HttpHelpers httpHelpers = new HttpHelpers();
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. /// <param name="indexType">当前类型 </param>
  20. /// <param name="maxLength">标题最大</param>
  21. /// <param name="wap"></param>
  22. /// <param name="showDate"></param>
  23. /// <returns></returns>
  24. protected virtual string GetSynArticleZx(int indexType, int maxLength, bool wap, bool showDate = false)
  25. {
  26. StringBuilder sp = new StringBuilder();
  27. try
  28. {
  29. #region 修改成统一的缓存管理 by 大师兄 2017.10.13
  30. object jsonlist = CBCache.GetCacheService().GetObject("__TopicInterface__GetNewList__");
  31. #endregion
  32. if (jsonlist == null)
  33. {
  34. //开始调用
  35. string getZx = System.Configuration.ConfigurationManager.AppSettings["getZX"];
  36. HttpItems items = new HttpItems
  37. {
  38. URL = getZx + "/zx/TopicInterface/GetNewList",
  39. Method = "GET",
  40. Accept = "text/html, application/html+xml, */*",
  41. Timeout = 30 * 1000
  42. };
  43. HttpResults hr = httpHelpers.GetHtml(items);
  44. jsonlist = hr.Html;
  45. CB.Cache.CBCache.GetCacheService().AddObject("__TopicInterface__GetNewList__", hr.Html);
  46. }
  47. dynamic jsonList = JsonConvert.DeserializeObject<dynamic>(jsonlist.ToString());
  48. var fortstr = "<li><a href=\"{0}\" target=\"_blank\">{1}</a><span></span></li>";
  49. if (showDate)
  50. fortstr = "<li><a href=\"{0}\" target=\"_blank\">{1}</a><span class=\"time\">{2}</span></li>";
  51. switch (indexType)
  52. {
  53. case 1:
  54. foreach (var item in jsonList.data)
  55. {
  56. var lst = new List<object>() { "http://zx.55128.cn" + item.SourceUrl, CB.Common.Utils.GetSubString(item.title.ToString(), maxLength, "") };
  57. if (showDate)
  58. lst.Add(item.createTime.ToString("MM-dd"));
  59. sp.AppendFormat(fortstr, lst.ToArray());
  60. }
  61. break;
  62. case 2:
  63. foreach (var item in jsonList.dataTwo)
  64. {
  65. var lst = new List<object>() { "http://zx.55128.cn" + item.SourceUrl, CB.Common.Utils.GetSubString(item.title.ToString(), maxLength, "") };
  66. if (showDate)
  67. lst.Add(item.createTime.ToString("MM-dd"));
  68. sp.AppendFormat(fortstr, lst.ToArray());
  69. }
  70. break;
  71. case 3:
  72. foreach (var item in jsonList.dataThress)
  73. {
  74. var lst = new List<object>() { "http://zx.55128.cn" + item.SourceUrl, CB.Common.Utils.GetSubString(item.title.ToString(), maxLength, "") };
  75. if (showDate)
  76. lst.Add(item.createTime.ToString("MM-dd"));
  77. sp.AppendFormat(fortstr, lst.ToArray());
  78. }
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. catch (Exception e)
  85. {
  86. Console.WriteLine(e);
  87. sp = new StringBuilder("");
  88. }
  89. return sp.ToString();
  90. }
  91. }
  92. }