PageUpdateInfoController.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.MainModels;
  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 : BaseController
  18. {
  19. public PageUpdateInfoController(IHttpContextAccessor accessor, ILogger<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. JsonData data = JsonMapper.ToObject(value);
  27. string version = data["version"].ToString();
  28. string CheckSignResult = CheckSign(value, new string[] { "Url" });
  29. if (CheckSignResult != "1")
  30. {
  31. return Json(new AppResultJson() { Status = "-1", Info = CheckSignResult });
  32. }
  33. else
  34. {
  35. return CheckDo(value);
  36. }
  37. }
  38. public JsonResult CheckDo(string value, string ismakefile = "1")
  39. {
  40. value = HttpUtility.UrlDecode(value);
  41. JsonData data = JsonMapper.ToObject(value);
  42. string pagename = data["Url"].ToString();
  43. string apptype = data["apptype"].ToString();
  44. string version = data["version"].ToString();
  45. // string filename = pagename + ".html";
  46. Dictionary<string, string> Obj = new Dictionary<string, string>();
  47. PageUpdateInfo query = RedisDbconn.Instance.Get<PageUpdateInfo>("PageUpdateInfo:" + pagename);
  48. if (query != null)
  49. {
  50. SystemSet set = RedisDbconn.Instance.Get<SystemSet>("SystemSet") ?? new SystemSet();
  51. Obj.Add("ModuleVersion", query.ModuleVersion.ToString()); //模板更新版本
  52. Obj.Add("DataVersion", "1"); //数据更新版本
  53. if (apptype == "android")
  54. {
  55. Obj.Add("ModulePath", "/template/app/default/");
  56. if (ismakefile == "1")
  57. {
  58. string PagePath = function.ReadInstance("/WebRootPath.txt") + "/template/app/default/" + query.ModulePath;
  59. string pageContent = function.ReadInstanceByFull(PagePath);
  60. Obj.Add("ModuleContent", pageContent); //模板内容
  61. }
  62. }
  63. else if (apptype == "ios")
  64. {
  65. Obj.Add("ModulePath", "/template/app/default/");
  66. if (ismakefile == "1")
  67. {
  68. string PagePath = function.ReadInstance("/WebRootPath.txt") + "/template/app/default/" + query.ModulePath;
  69. string pageContent = function.ReadInstanceByFull(PagePath);
  70. Obj.Add("ModuleContent", pageContent); //模板内容
  71. }
  72. }
  73. else
  74. {
  75. string PagePath = function.ReadInstance("/WebRootPath.txt") + "/template/app/default/" + query.ModulePath;
  76. string pageContent = function.ReadInstanceByFull(PagePath);
  77. pageContent = pageContent.Replace("'/", "'/skin/app/default/");
  78. pageContent = pageContent.Replace("\"/", "\"/skin/app/default/");
  79. pageContent = pageContent.Replace("\"./", "\"/skin/app/default/");
  80. pageContent = pageContent.Replace("'./", "'/skin/app/default/");
  81. pageContent = pageContent.Replace("(./", "(/skin/app/default/");
  82. Obj.Add("ModuleContent", pageContent); //模板内容
  83. }
  84. Obj.Add("ModuleFileName", query.ModulePath);
  85. Obj.Add("DataContent", "{}");
  86. string DataId = function.MD5_16(query.ModulePath);
  87. Obj.Add("DataId", DataId); //模板数据Id
  88. if (apptype != "web")
  89. {
  90. Obj.Add("BgColor", "#" + query.BgColor);
  91. Obj.Add("TextColor", "#" + query.TextColor);
  92. Obj.Add("StatusBarStyle", query.StatusBarStyle);
  93. Obj.Add("ShowTitle", query.ShowTitle == 1 ? "1" : "0");
  94. Obj.Add("Title", query.Title);
  95. Obj.Add("LeftBtn1", function.CheckNull(query.LeftBtn1));
  96. Obj.Add("LeftBtn2", function.CheckNull(query.LeftBtn2));
  97. Obj.Add("RightBtn1", function.CheckNull(query.RightBtn1));
  98. Obj.Add("RightBtn2", function.CheckNull(query.RightBtn2));
  99. if (ismakefile == "1")
  100. {
  101. Obj.Add("LeftAction1", query.LeftAction1 == null ? "" : query.LeftAction1);
  102. Obj.Add("LeftAction2", query.LeftAction2 == null ? "" : query.LeftAction2);
  103. Obj.Add("RightAction1", query.RightAction1 == null ? "" : query.RightAction1);
  104. Obj.Add("RightAction2", query.RightAction2 == null ? "" : query.RightAction2);
  105. }
  106. else
  107. {
  108. Obj.Add("LeftAction1", query.LeftAction1 == null ? "" : query.LeftAction1.Replace("\\", "\\\\").Replace("\"", "\\\""));
  109. Obj.Add("LeftAction2", query.LeftAction2 == null ? "" : query.LeftAction2.Replace("\\", "\\\\").Replace("\"", "\\\""));
  110. Obj.Add("RightAction1", query.RightAction1 == null ? "" : query.RightAction1.Replace("\\", "\\\\").Replace("\"", "\\\""));
  111. Obj.Add("RightAction2", query.RightAction2 == null ? "" : query.RightAction2.Replace("\\", "\\\\").Replace("\"", "\\\""));
  112. }
  113. Obj.Add("IsScrollBar", query.IsScrollBar == 1 ? "1" : "0");
  114. Obj.Add("IsSkid", query.IsSkid == 1 ? "1" : "0"); //是否侧滑返回
  115. Obj.Add("MustUpdate", query.MustUpdate == 1 ? "1" : "0"); //是否强制更新
  116. Obj.Add("WebTitle", query.QueryCount.ToString());
  117. }
  118. }
  119. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  120. }
  121. #endregion
  122. #region 页面层级结构数据
  123. public JsonResult GetPageTree()
  124. {
  125. Dictionary<string, string> dic = new Dictionary<string, string>();
  126. List<PageUpdateInfo> newpages = RedisDbconn.Instance.GetList<PageUpdateInfo>("PageUpdateInfo", 1, 1000);
  127. foreach (PageUpdateInfo page in newpages)
  128. {
  129. if (dic.ContainsKey("page" + page.ModulePath.Replace(".html", "")))
  130. {
  131. dic.Add("page" + page.ModulePath.Replace(".html", ""), page.GotoPages);
  132. }
  133. }
  134. return Json(new AppResultJson() { Status = "1", Info = "", Data = dic });
  135. }
  136. #endregion
  137. private int versionToNumber(string version)
  138. {
  139. string[] versionlist = version.Split('.');
  140. string left = versionlist[0];
  141. string mid = versionlist[1];
  142. if (mid.Length == 1) mid = "00" + mid;
  143. if (mid.Length == 2) mid = "0" + mid;
  144. string right = versionlist[2];
  145. if (right.Length == 1) right = "00" + right;
  146. if (right.Length == 2) right = "0" + right;
  147. string result = left + mid + right;
  148. return int.Parse(result);
  149. }
  150. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  151. /// <summary>
  152. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  153. /// </summary>
  154. /// <param name="value">请求的参数(json字符串)</param>
  155. /// <param name="signField">要签名的字段</param>
  156. /// <returns></returns>
  157. private string CheckSign(string value, string[] signField)
  158. {
  159. JsonData json = JsonMapper.ToObject(value);
  160. Dictionary<string, string> dic = new Dictionary<string, string>();
  161. for (int i = 0; i < signField.Length; i++)
  162. {
  163. dic.Add(signField[i], json[signField[i]].ToString());
  164. }
  165. string sign = json["sign"].ToString(); //客户端签名字符串
  166. return new Sign().sign(dic, sign);
  167. }
  168. #endregion
  169. }
  170. }