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 System.Web; using MySystem.MainModels; using LitJson; using Library; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace MySystem.Areas.Api.Controllers { [Area("Api")] [Route("Api/[controller]/[action]")] public class PageUpdateInfoController : BaseController { public PageUpdateInfoController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 页面数据检查 public JsonResult Check(string value) { value = HttpUtility.UrlDecode(value); JsonData data = JsonMapper.ToObject(value); string version = data["version"].ToString(); string CheckSignResult = CheckSign(value, new string[] { "Url" }); if (CheckSignResult != "1") { return Json(new AppResultJson() { Status = "-1", Info = CheckSignResult }); } else { return CheckDo(value); } } public JsonResult CheckDo(string value, string ismakefile = "1") { value = HttpUtility.UrlDecode(value); JsonData data = JsonMapper.ToObject(value); string pagename = data["Url"].ToString(); string apptype = data["apptype"].ToString(); string version = data["version"].ToString(); // string filename = pagename + ".html"; Dictionary Obj = new Dictionary(); PageUpdateInfo query = RedisDbconn.Instance.Get("PageUpdateInfo:" + pagename); if (query != null) { SystemSet set = RedisDbconn.Instance.Get("SystemSet") ?? new SystemSet(); Obj.Add("ModuleVersion", query.ModuleVersion.ToString()); //模板更新版本 Obj.Add("DataVersion", "1"); //数据更新版本 if (apptype == "android") { Obj.Add("ModulePath", "/template/app/default/"); if (ismakefile == "1") { string PagePath = function.ReadInstance("/WebRootPath.txt") + "/template/app/default/" + query.ModulePath; string pageContent = function.ReadInstanceByFull(PagePath); Obj.Add("ModuleContent", pageContent); //模板内容 } } else if (apptype == "ios") { Obj.Add("ModulePath", "/template/app/default/"); if (ismakefile == "1") { string PagePath = function.ReadInstance("/WebRootPath.txt") + "/template/app/default/" + query.ModulePath; string pageContent = function.ReadInstanceByFull(PagePath); Obj.Add("ModuleContent", pageContent); //模板内容 } } else { string PagePath = function.ReadInstance("/WebRootPath.txt") + "/template/app/default/" + query.ModulePath; string pageContent = function.ReadInstanceByFull(PagePath); pageContent = pageContent.Replace("'/", "'/skin/app/default/"); pageContent = pageContent.Replace("\"/", "\"/skin/app/default/"); pageContent = pageContent.Replace("\"./", "\"/skin/app/default/"); pageContent = pageContent.Replace("'./", "'/skin/app/default/"); pageContent = pageContent.Replace("(./", "(/skin/app/default/"); Obj.Add("ModuleContent", pageContent); //模板内容 } Obj.Add("ModuleFileName", query.ModulePath); Obj.Add("DataContent", "{}"); string DataId = function.MD5_16(query.ModulePath); Obj.Add("DataId", DataId); //模板数据Id if (apptype != "web") { Obj.Add("BgColor", "#" + query.BgColor); Obj.Add("TextColor", "#" + query.TextColor); Obj.Add("StatusBarStyle", query.StatusBarStyle); Obj.Add("ShowTitle", query.ShowTitle == 1 ? "1" : "0"); Obj.Add("Title", query.Title); Obj.Add("LeftBtn1", function.CheckNull(query.LeftBtn1)); Obj.Add("LeftBtn2", function.CheckNull(query.LeftBtn2)); Obj.Add("RightBtn1", function.CheckNull(query.RightBtn1)); Obj.Add("RightBtn2", function.CheckNull(query.RightBtn2)); if (ismakefile == "1") { Obj.Add("LeftAction1", query.LeftAction1 == null ? "" : query.LeftAction1); Obj.Add("LeftAction2", query.LeftAction2 == null ? "" : query.LeftAction2); Obj.Add("RightAction1", query.RightAction1 == null ? "" : query.RightAction1); Obj.Add("RightAction2", query.RightAction2 == null ? "" : query.RightAction2); } else { Obj.Add("LeftAction1", query.LeftAction1 == null ? "" : query.LeftAction1.Replace("\\", "\\\\").Replace("\"", "\\\"")); Obj.Add("LeftAction2", query.LeftAction2 == null ? "" : query.LeftAction2.Replace("\\", "\\\\").Replace("\"", "\\\"")); Obj.Add("RightAction1", query.RightAction1 == null ? "" : query.RightAction1.Replace("\\", "\\\\").Replace("\"", "\\\"")); Obj.Add("RightAction2", query.RightAction2 == null ? "" : query.RightAction2.Replace("\\", "\\\\").Replace("\"", "\\\"")); } Obj.Add("IsScrollBar", query.IsScrollBar == 1 ? "1" : "0"); Obj.Add("IsSkid", query.IsSkid == 1 ? "1" : "0"); //是否侧滑返回 Obj.Add("MustUpdate", query.MustUpdate == 1 ? "1" : "0"); //是否强制更新 Obj.Add("WebTitle", query.QueryCount.ToString()); } } return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj }); } #endregion #region 页面层级结构数据 public JsonResult GetPageTree() { Dictionary dic = new Dictionary(); List newpages = RedisDbconn.Instance.GetList("PageUpdateInfo", 1, 1000); foreach (PageUpdateInfo page in newpages) { if (dic.ContainsKey("page" + page.ModulePath.Replace(".html", ""))) { dic.Add("page" + page.ModulePath.Replace(".html", ""), page.GotoPages); } } return Json(new AppResultJson() { Status = "1", Info = "", Data = dic }); } #endregion private int versionToNumber(string version) { string[] versionlist = version.Split('.'); string left = versionlist[0]; string mid = versionlist[1]; if (mid.Length == 1) mid = "00" + mid; if (mid.Length == 2) mid = "0" + mid; string right = versionlist[2]; if (right.Length == 1) right = "00" + right; if (right.Length == 2) right = "0" + right; string result = left + mid + right; return int.Parse(result); } #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 } }