MsgAlertController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.MainModels;
  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 MsgAlertController : BaseController
  18. {
  19. public MsgAlertController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 通用-自定义弹窗消息
  23. [Authorize]
  24. public JsonResult MsgAlert(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = MsgAlertDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> MsgAlertDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  35. var query = maindb.MsgAlert.Where(m => m.Status > 0).OrderByDescending(m => m.Sort).ToList();
  36. foreach (var item in query)
  37. {
  38. Dictionary<string, object> Obj = new Dictionary<string, object>();
  39. string[] AppointUsers = new string[] { };
  40. var UserIds = "";
  41. var info = maindb.UserSwapWhite.Where(m => m.QueryCount == item.Id).ToList();
  42. Obj.Add("MsgType", item.MsgType); //消息类型
  43. Obj.Add("Title", item.Title); //标题
  44. Obj.Add("Content", item.Content); //简介
  45. Obj.Add("EffectStartDate", item.EffectStartDate == null ? "" : item.EffectStartDate.Value.ToString("yyyy/MM/dd HH:mm:ss")); //有效开始时间
  46. Obj.Add("EffectEndDate", item.EffectEndDate == null ? "" : item.EffectEndDate.Value.ToString("yyyy/MM/dd HH:mm:ss")); //有效结束时间
  47. Obj.Add("BgPic", DefaultPic(item.BgPic)); //背景图片
  48. Obj.Add("UrlParam", item.UrlParam); //跳转Url参数
  49. Obj.Add("Url", item.Url); //跳转Url
  50. Obj.Add("BtnText", item.BtnText); //按钮文字
  51. Obj.Add("AlertFlag", item.SeoKeyword); //弹窗标识
  52. Obj.Add("IsWeekend", item.IsWeekend); //是否周末
  53. Obj.Add("TimeByDay", item.TimeByDay); //每日次数
  54. Obj.Add("IsAppoint", item.AlertFlag); //是否指定对象(1 是 0 否)
  55. if (info.Count > 0)
  56. {
  57. foreach (var items in info)
  58. {
  59. UserIds += items.UserId + ",";
  60. }
  61. AppointUsers = UserIds.TrimEnd(',').Split(',');
  62. Obj.Add("AppointUsers", AppointUsers); //弹窗对象
  63. }
  64. Obj.Add("Id", item.Id); //Id
  65. dataList.Add(Obj);
  66. }
  67. return dataList;
  68. }
  69. #endregion
  70. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  71. /// <summary>
  72. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  73. /// </summary>
  74. /// <param name="value">请求的参数(json字符串)</param>
  75. /// <param name="signField">要签名的字段</param>
  76. /// <returns></returns>
  77. private string CheckSign(string value, string[] signField)
  78. {
  79. JsonData json = JsonMapper.ToObject(value);
  80. Dictionary<string, string> dic = new Dictionary<string, string>();
  81. for (int i = 0; i < signField.Length; i++)
  82. {
  83. dic.Add(signField[i], json[signField[i]].ToString());
  84. }
  85. string sign = json["sign"].ToString(); //客户端签名字符串
  86. return new Sign().sign(dic, sign);
  87. }
  88. #endregion
  89. }
  90. }