ShareExtendion.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Microsoft.AspNetCore.Html;
  2. using System;
  3. using System.Text;
  4. using CZFW.Framework.Interface;
  5. using CZFW.Framework.Logic;
  6. using CZFW.Framework.Model.Entity;
  7. using CZFW.Framework.Model;
  8. namespace CZKJ.GBRS2.WebMVC.Helper
  9. {
  10. public static class ShareExtendion
  11. {
  12. public static IHtmlContent CZWechatShare(object model = null)
  13. {
  14. IShare share = model as IShare;
  15. if (share == null)
  16. {
  17. string url = CZHttpContext.Current.Request.Path.ToString();
  18. if (url != null)
  19. {
  20. ISeoShare shareLogic = new SeoShareLogic();
  21. share = shareLogic.GetEntity(x => x.Mark == url.Replace("/", "") || x.Mark == url || x.Url == url);
  22. }
  23. }
  24. if (share == null)
  25. {
  26. share = new SeoShareEntity
  27. {
  28. ShareImage = "/assets/image/logo-lg.png",
  29. ShareTitle = "国宝人寿保险股份有限公司",
  30. ShareUrl = ""
  31. };
  32. }
  33. StringBuilder stringBuilder = new StringBuilder();
  34. stringBuilder.Append(@"<script>");
  35. stringBuilder.AppendFormat(@"{1}var shareTitle = '{0}';", share.ShareTitle, Environment.NewLine);
  36. stringBuilder.AppendFormat(@"{1}var shareLink = '{0}';", share.ShareUrl, Environment.NewLine);
  37. stringBuilder.AppendFormat(@"{1}var shareImgUrl = '{0}';", share.ShareImage, Environment.NewLine);
  38. stringBuilder.AppendFormat(@"{1}var shareDesc = '{0}';", share.ShareDescription, Environment.NewLine);
  39. stringBuilder.AppendFormat(@"{1}var shareDefaultImgUrl = '{0}';{1}", "/Attached/20180315/180315090853849519.png", Environment.NewLine);
  40. stringBuilder.Append(@"</script>");
  41. return new HtmlString(stringBuilder.ToString());
  42. }
  43. public static IHtmlContent CZSEO(object model = null)
  44. {
  45. ISeo seo = model as ISeo;
  46. if (seo == null || seo.SeoTitle == null)
  47. {
  48. string url = CZHttpContext.Current.Request.Path.ToString();
  49. string allUrl = url + CZHttpContext.Current.Request.QueryString.Value.ToString();
  50. if (url != null)
  51. {
  52. ISeoShare shareLogic = new SeoShareLogic();
  53. seo = shareLogic.GetEntity(x => x.Mark == url.Replace("/", "") || x.Mark == url || x.Url == url || x.Mark == allUrl);
  54. }
  55. }
  56. if (seo == null || seo.SeoTitle == null)
  57. {
  58. seo = new SeoShareEntity
  59. {
  60. SeoTitle = "国宝人寿保险股份有限公司",
  61. SeoKeywords = "国宝人寿保险股份有限公司",
  62. SeoDescription = "国宝人寿保险股份有限公司"
  63. };
  64. }
  65. var html = $"<title>{seo.SeoTitle}</title>";
  66. html += $"<meta name=\"description\" content=\"{seo.SeoDescription} 国宝 国宝人寿 国宝人寿官网 国宝保险 保险 人寿 人寿保险\"/>";
  67. html += $"<meta name=\"keywords\" content=\"{seo.SeoKeywords} 国宝 国宝人寿 国宝人寿官网 国宝保险 保险 人寿 人寿保险\"/>";
  68. return new HtmlString(html);
  69. }
  70. }
  71. }