AdvertismentController.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.Models;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class AdvertismentController : BaseController
  18. {
  19. public AdvertismentController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 通用-广告详情
  23. [Authorize]
  24. public JsonResult Detail(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. Dictionary<string, object> Obj = DetailDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  30. }
  31. public Dictionary<string, object> DetailDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. Dictionary<string, object> Obj = new Dictionary<string, object>();
  35. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  36. Advertisment query = new AdvertismentService().Query(Id);
  37. Obj.Add("Title", query.Title); //标题
  38. Obj.Add("Contents", CheckContentImage(query.Contents)); //内容
  39. return Obj;
  40. }
  41. #endregion
  42. #region 首页-首页顶部广告
  43. [Authorize]
  44. public JsonResult IndexTop(string value)
  45. {
  46. value = DesDecrypt(value);
  47. JsonData data = JsonMapper.ToObject(value);
  48. List<Dictionary<string, object>> dataList = IndexTopDo(value);
  49. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  50. }
  51. public List<Dictionary<string, object>> IndexTopDo(string value)
  52. {
  53. JsonData data = JsonMapper.ToObject(value);
  54. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  55. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  56. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  57. List<Dictionary<string, object>> query = new AdvertismentService().List(new List<FieldItem>(), " and ColId like '003001%'", PageNum, PageSize);
  58. foreach (var subdata in query)
  59. {
  60. Dictionary<string, object> curData = new Dictionary<string, object>();
  61. curData.Add("Title", subdata["Title"].ToString()); //标题
  62. curData.Add("PicPath", DefaultPic(subdata["PicPath"].ToString())); //图片
  63. curData.Add("Url", subdata["Url"].ToString()); //链接地址
  64. curData.Add("Parameter", subdata["SeoTitle"].ToString()); //参数
  65. curData.Add("Id", subdata["Id"].ToString());
  66. dataList.Add(curData);
  67. }
  68. return dataList;
  69. }
  70. #endregion
  71. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  72. /// <summary>
  73. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  74. /// </summary>
  75. /// <param name="value">请求的参数(json字符串)</param>
  76. /// <param name="signField">要签名的字段</param>
  77. /// <returns></returns>
  78. private string CheckSign(string value, string[] signField)
  79. {
  80. JsonData json = JsonMapper.ToObject(value);
  81. Dictionary<string, string> dic = new Dictionary<string, string>();
  82. for (int i = 0; i < signField.Length; i++)
  83. {
  84. dic.Add(signField[i], json[signField[i]].ToString());
  85. }
  86. string sign = json["sign"].ToString(); //客户端签名字符串
  87. return new Sign().sign(dic, sign);
  88. }
  89. #endregion
  90. }
  91. }