123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- 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.BsModels;
- 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 : Admin.Controllers.BaseController
- {
- public PageUpdateInfoController(IHttpContextAccessor accessor, ILogger<Admin.Controllers.BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 页面数据检查
- public JsonResult Check(string value)
- {
- value = HttpUtility.UrlDecode(value);
- function.WriteLog(DateTime.Now.ToString() + ":页面数据检查:" + Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() + "APP接口IP监控");
- 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 Kind = data["Kind"].ToString();
- string pagename = data["Url"].ToString();
- string apptype = data["apptype"].ToString();
- string version = data["version"].ToString();
- int ModuleVersion = 0;
- if(value.Contains("\"ModuleVersion\""))
- {
- ModuleVersion = int.Parse(function.CheckInt(data["ModuleVersion"].ToString()));
- }
- // string filename = pagename + ".html";
- Dictionary<string, string> Obj = new Dictionary<string, string>();
- PageUpdateInfo query = MysqlDbconn.Instance.GetPage(pagename, Kind);
- if (query != null)
- {
- Obj.Add("ModuleVersion", query.ModuleVersion.ToString()); //模板更新版本
- Obj.Add("DataVersion", "1"); //数据更新版本
- if (apptype == "android")
- {
- Obj.Add("ModulePath", "/template/app/" + Kind + "/");
- if (ismakefile == "1" && ModuleVersion < query.ModuleVersion)
- {
- string PagePath = "template/app/" + Kind + "/" + query.ModulePath;
- string pageContent = PublicFunction.GetNetFileContent(OssHost + PagePath);
- Obj.Add("ModuleContent", pageContent); //模板内容
- }
- else
- {
- Obj.Add("ModuleContent", ""); //模板内容
- }
- }
- else if (apptype == "ios")
- {
- Obj.Add("ModulePath", "/template/app/" + Kind + "/");
- if (ismakefile == "1" && ModuleVersion < query.ModuleVersion)
- {
- string PagePath = "template/app/" + Kind + "/" + query.ModulePath;
- string pageContent = PublicFunction.GetNetFileContent(OssHost + PagePath);
- Obj.Add("ModuleContent", pageContent); //模板内容
- }
- else
- {
- Obj.Add("ModuleContent", ""); //模板内容
- }
- }
- else
- {
- string PagePath = "template/app/" + Kind + "/" + query.ModulePath;
- string pageContent = PublicFunction.GetNetFileContent(OssHost + PagePath);
- pageContent = pageContent.Replace("'/", "'/skin/app/" + Kind + "/");
- pageContent = pageContent.Replace("\"/", "\"/skin/app/" + Kind + "/");
- pageContent = pageContent.Replace("\"./", "\"/skin/app/" + Kind + "/");
- pageContent = pageContent.Replace("'./", "'/skin/app/" + Kind + "/");
- pageContent = pageContent.Replace("(./", "(/skin/app/" + Kind + "/");
- 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(string Kind = "default")
- {
- Dictionary<string, string> dic = new Dictionary<string, string>();
- List<PageUpdateInfo> newpages = MysqlDbconn.Instance.GetPageList(Kind);
- 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,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- 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
- }
- }
|