using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; namespace MySystem.Areas.Api.Controllers.v1 { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class MsgAlertController : BaseController { public MsgAlertController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 通用-自定义弹窗消息 [Authorize] public JsonResult MsgAlert(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = MsgAlertDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> MsgAlertDo(string value) { JsonData data = JsonMapper.ToObject(value); List> dataList = new List>(); var query = maindb.MsgAlert.Where(m => m.Status > 0).OrderByDescending(m => m.Sort).ToList(); foreach (var item in query) { Dictionary Obj = new Dictionary(); string[] AppointUsers = new string[] { }; var UserIds = ""; var info = maindb.UserSwapWhite.Where(m => m.QueryCount == item.Id).ToList(); Obj.Add("MsgType", item.MsgType); //消息类型 Obj.Add("Title", item.Title); //标题 Obj.Add("Content", item.Content); //简介 Obj.Add("EffectStartDate", item.EffectStartDate == null ? "" : item.EffectStartDate.Value.ToString("yyyy/MM/dd HH:mm:ss")); //有效开始时间 Obj.Add("EffectEndDate", item.EffectEndDate == null ? "" : item.EffectEndDate.Value.ToString("yyyy/MM/dd HH:mm:ss")); //有效结束时间 Obj.Add("BgPic", DefaultPic(item.BgPic)); //背景图片 Obj.Add("UrlParam", item.UrlParam); //跳转Url参数 Obj.Add("Url", item.Url); //跳转Url Obj.Add("BtnText", item.BtnText); //按钮文字 Obj.Add("AlertFlag", item.SeoKeyword); //弹窗标识 Obj.Add("IsWeekend", item.IsWeekend); //是否周末 Obj.Add("TimeByDay", item.TimeByDay); //每日次数 Obj.Add("IsAppoint", item.AlertFlag); //是否指定对象(1 是 0 否) if (info.Count > 0) { foreach (var items in info) { UserIds += items.UserId + ","; } AppointUsers = UserIds.TrimEnd(',').Split(','); Obj.Add("AppointUsers", AppointUsers); //弹窗对象 } Obj.Add("Id", item.Id); //Id dataList.Add(Obj); } return dataList; } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }