PageInfoController.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 PageInfoController : BaseController
  18. {
  19. public PageInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 通用-协议和介绍
  23. // [Authorize]
  24. public JsonResult Detail(string value)
  25. {
  26. if (string.IsNullOrEmpty(value))
  27. {
  28. System.IO.StreamReader sr = new System.IO.StreamReader(Request.Body);
  29. value = sr.ReadToEnd();
  30. value = value.Split('=')[1];
  31. }
  32. value = DesDecrypt(value);
  33. JsonData data = JsonMapper.ToObject(value);
  34. Dictionary<string, object> Obj = DetailDo(value);
  35. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  36. }
  37. public Dictionary<string, object> DetailDo(string value)
  38. {
  39. JsonData data = JsonMapper.ToObject(value);
  40. Dictionary<string, object> Obj = new Dictionary<string, object>();
  41. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  42. PageInfo query = new PageInfoService().Query(Id);
  43. Obj.Add("Title", query.Title); //标题
  44. Obj.Add("Contents", query.Contents); //内容
  45. return Obj;
  46. }
  47. #endregion
  48. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  49. /// <summary>
  50. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  51. /// </summary>
  52. /// <param name="value">请求的参数(json字符串)</param>
  53. /// <param name="signField">要签名的字段</param>
  54. /// <returns></returns>
  55. private string CheckSign(string value, string[] signField)
  56. {
  57. JsonData json = JsonMapper.ToObject(value);
  58. Dictionary<string, string> dic = new Dictionary<string, string>();
  59. for (int i = 0; i < signField.Length; i++)
  60. {
  61. dic.Add(signField[i], json[signField[i]].ToString());
  62. }
  63. string sign = json["sign"].ToString(); //客户端签名字符串
  64. return new Sign().sign(dic, sign);
  65. }
  66. #endregion
  67. }
  68. }