ProjectVersionController.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.Models;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class ProjectVersionController : BaseController
  18. {
  19. public ProjectVersionController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 通用-获取小程序版本
  23. // [Authorize]
  24. public JsonResult GetCurrentVer(string value)
  25. {
  26. // value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. int ProjectId = int.Parse(function.CheckInt(data["ProjectId"].ToString())); //小程序项目
  29. string AppId = data["AppId"].ToString(); //平台分配的AppId
  30. string Token = data["Token"].ToString(); //用户令牌
  31. Dictionary<string, object> Obj = new Dictionary<string, object>();
  32. if(function.MD5_32(AppId + "G9&E@952") != Token)
  33. {
  34. return Json(new AppResultJson() { Status = "-1", Info = "无权限", Data = Obj });
  35. }
  36. Users user = db.Users.FirstOrDefault(m => m.AppId == AppId) ?? new Users();
  37. bool check = db.ProjectVersion.Any(m => m.ProjectId == ProjectId && m.UserId == user.Id);
  38. if(!check)
  39. {
  40. return Json(new AppResultJson() { Status = "-1", Info = "暂无版本", Data = Obj });
  41. }
  42. ProjectVersion query = db.ProjectVersion.Where(m => m.ProjectId == ProjectId && m.UserId == user.Id).OrderByDescending(m => m.Id).FirstOrDefault() ?? new ProjectVersion();
  43. Obj.Add("VerNum", query.VerNum); //版本号
  44. Obj.Add("VerNo", query.VersionNo); //版本号
  45. Obj.Add("UpdateNote", query.UpdateNote); //更新说明
  46. Obj.Add("FilePath", SourceHost + query.FilePath); //模板文件路径
  47. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  48. }
  49. #endregion
  50. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  51. /// <summary>
  52. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  53. /// </summary>
  54. /// <param name="value">请求的参数(json字符串)</param>
  55. /// <param name="signField">要签名的字段</param>
  56. /// <returns></returns>
  57. private string CheckSign(string value, string[] signField)
  58. {
  59. JsonData json = JsonMapper.ToObject(value);
  60. Dictionary<string, string> dic = new Dictionary<string, string>();
  61. for (int i = 0; i < signField.Length; i++)
  62. {
  63. dic.Add(signField[i], json[signField[i]].ToString());
  64. }
  65. string sign = json["sign"].ToString(); //客户端签名字符串
  66. return new Sign().sign(dic, sign);
  67. }
  68. #endregion
  69. }
  70. }