PageUpdateInfoController.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 System.Web;
  9. using MySystem.BsModels;
  10. using LitJson;
  11. using Library;
  12. // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  13. namespace MySystem.Areas.Api.Controllers
  14. {
  15. [Area("Api")]
  16. [Route("Api/[controller]/[action]")]
  17. public class PageUpdateInfoController : Admin.Controllers.BaseController
  18. {
  19. public PageUpdateInfoController(IHttpContextAccessor accessor, ILogger<Admin.Controllers.BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 页面数据检查
  23. public JsonResult Check(string value)
  24. {
  25. value = HttpUtility.UrlDecode(value);
  26. function.WriteLog(DateTime.Now.ToString() + ":页面数据检查:" + Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() + "APP接口IP监控");
  27. JsonData data = JsonMapper.ToObject(value);
  28. string version = data["version"].ToString();
  29. string CheckSignResult = CheckSign(value, new string[] { "Url" });
  30. if (CheckSignResult != "1")
  31. {
  32. return Json(new AppResultJson() { Status = "-1", Info = CheckSignResult });
  33. }
  34. else
  35. {
  36. return CheckDo(value);
  37. }
  38. }
  39. public JsonResult CheckDo(string value, string ismakefile = "1")
  40. {
  41. value = HttpUtility.UrlDecode(value);
  42. JsonData data = JsonMapper.ToObject(value);
  43. string Kind = data["Kind"].ToString();
  44. string pagename = data["Url"].ToString();
  45. string apptype = data["apptype"].ToString();
  46. string version = data["version"].ToString();
  47. int ModuleVersion = 0;
  48. if(value.Contains("\"ModuleVersion\""))
  49. {
  50. ModuleVersion = int.Parse(function.CheckInt(data["ModuleVersion"].ToString()));
  51. }
  52. // string filename = pagename + ".html";
  53. Dictionary<string, string> Obj = new Dictionary<string, string>();
  54. PageUpdateInfo query = MysqlDbconn.Instance.GetPage(pagename, Kind);
  55. if (query != null)
  56. {
  57. Obj.Add("ModuleVersion", query.ModuleVersion.ToString()); //模板更新版本
  58. Obj.Add("DataVersion", "1"); //数据更新版本
  59. if (apptype == "android")
  60. {
  61. Obj.Add("ModulePath", "/template/app/" + Kind + "/");
  62. if (ismakefile == "1" && ModuleVersion < query.ModuleVersion)
  63. {
  64. string PagePath = "template/app/" + Kind + "/" + query.ModulePath;
  65. string pageContent = PublicFunction.GetNetFileContent(OssHost + PagePath);
  66. Obj.Add("ModuleContent", pageContent); //模板内容
  67. }
  68. else
  69. {
  70. Obj.Add("ModuleContent", ""); //模板内容
  71. }
  72. }
  73. else if (apptype == "ios")
  74. {
  75. Obj.Add("ModulePath", "/template/app/" + Kind + "/");
  76. if (ismakefile == "1" && ModuleVersion < query.ModuleVersion)
  77. {
  78. string PagePath = "template/app/" + Kind + "/" + query.ModulePath;
  79. string pageContent = PublicFunction.GetNetFileContent(OssHost + PagePath);
  80. Obj.Add("ModuleContent", pageContent); //模板内容
  81. }
  82. else
  83. {
  84. Obj.Add("ModuleContent", ""); //模板内容
  85. }
  86. }
  87. else
  88. {
  89. string PagePath = "template/app/" + Kind + "/" + query.ModulePath;
  90. string pageContent = PublicFunction.GetNetFileContent(OssHost + PagePath);
  91. pageContent = pageContent.Replace("'/", "'/skin/app/" + Kind + "/");
  92. pageContent = pageContent.Replace("\"/", "\"/skin/app/" + Kind + "/");
  93. pageContent = pageContent.Replace("\"./", "\"/skin/app/" + Kind + "/");
  94. pageContent = pageContent.Replace("'./", "'/skin/app/" + Kind + "/");
  95. pageContent = pageContent.Replace("(./", "(/skin/app/" + Kind + "/");
  96. Obj.Add("ModuleContent", pageContent); //模板内容
  97. }
  98. Obj.Add("ModuleFileName", query.ModulePath);
  99. Obj.Add("DataContent", "{}");
  100. string DataId = function.MD5_16(query.ModulePath);
  101. Obj.Add("DataId", DataId); //模板数据Id
  102. if (apptype != "web")
  103. {
  104. Obj.Add("BgColor", "#" + query.BgColor);
  105. Obj.Add("TextColor", "#" + query.TextColor);
  106. Obj.Add("StatusBarStyle", query.StatusBarStyle);
  107. Obj.Add("ShowTitle", query.ShowTitle == 1 ? "1" : "0");
  108. Obj.Add("Title", query.Title);
  109. Obj.Add("LeftBtn1", function.CheckNull(query.LeftBtn1));
  110. Obj.Add("LeftBtn2", function.CheckNull(query.LeftBtn2));
  111. Obj.Add("RightBtn1", function.CheckNull(query.RightBtn1));
  112. Obj.Add("RightBtn2", function.CheckNull(query.RightBtn2));
  113. if (ismakefile == "1")
  114. {
  115. Obj.Add("LeftAction1", query.LeftAction1 == null ? "" : query.LeftAction1);
  116. Obj.Add("LeftAction2", query.LeftAction2 == null ? "" : query.LeftAction2);
  117. Obj.Add("RightAction1", query.RightAction1 == null ? "" : query.RightAction1);
  118. Obj.Add("RightAction2", query.RightAction2 == null ? "" : query.RightAction2);
  119. }
  120. else
  121. {
  122. Obj.Add("LeftAction1", query.LeftAction1 == null ? "" : query.LeftAction1.Replace("\\", "\\\\").Replace("\"", "\\\""));
  123. Obj.Add("LeftAction2", query.LeftAction2 == null ? "" : query.LeftAction2.Replace("\\", "\\\\").Replace("\"", "\\\""));
  124. Obj.Add("RightAction1", query.RightAction1 == null ? "" : query.RightAction1.Replace("\\", "\\\\").Replace("\"", "\\\""));
  125. Obj.Add("RightAction2", query.RightAction2 == null ? "" : query.RightAction2.Replace("\\", "\\\\").Replace("\"", "\\\""));
  126. }
  127. Obj.Add("IsScrollBar", query.IsScrollBar == 1 ? "1" : "0");
  128. Obj.Add("IsSkid", query.IsSkid == 1 ? "1" : "0"); //是否侧滑返回
  129. Obj.Add("MustUpdate", query.MustUpdate == 1 ? "1" : "0"); //是否强制更新
  130. Obj.Add("WebTitle", query.QueryCount.ToString());
  131. }
  132. }
  133. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  134. }
  135. #endregion
  136. #region 页面层级结构数据
  137. public JsonResult GetPageTree(string Kind = "default")
  138. {
  139. Dictionary<string, string> dic = new Dictionary<string, string>();
  140. List<PageUpdateInfo> newpages = MysqlDbconn.Instance.GetPageList(Kind);
  141. foreach (PageUpdateInfo page in newpages)
  142. {
  143. if (dic.ContainsKey("page" + page.ModulePath.Replace(".html", "")))
  144. {
  145. dic.Add("page" + page.ModulePath.Replace(".html", ""), page.GotoPages);
  146. }
  147. }
  148. return Json(new AppResultJson() { Status = "1", Info = "", Data = dic });
  149. }
  150. #endregion
  151. private int versionToNumber(string version)
  152. {
  153. string[] versionlist = version.Split('.');
  154. string left = versionlist[0];
  155. string mid = versionlist[1];
  156. if (mid.Length == 1) mid = "00" + mid;
  157. if (mid.Length == 2) mid = "0" + mid;
  158. string right = versionlist[2];
  159. if (right.Length == 1) right = "00" + right;
  160. if (right.Length == 2) right = "0" + right;
  161. string result = left + mid + right;
  162. return int.Parse(result);
  163. }
  164. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  165. /// <summary>
  166. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  167. /// </summary>
  168. /// <param name="value">请求的参数(json字符串)</param>
  169. /// <param name="signField">要签名的字段</param>
  170. /// <returns></returns>
  171. private string CheckSign(string value, string[] signField)
  172. {
  173. JsonData json = JsonMapper.ToObject(value);
  174. Dictionary<string, string> dic = new Dictionary<string, string>();
  175. for (int i = 0; i < signField.Length; i++)
  176. {
  177. dic.Add(signField[i], json[signField[i]].ToString());
  178. }
  179. string sign = json["sign"].ToString(); //客户端签名字符串
  180. return new Sign().sign(dic, sign);
  181. }
  182. #endregion
  183. }
  184. }