SystemSetController.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.Models;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. using Microsoft.IdentityModel.Tokens;
  14. using System.Text;
  15. using System.Security.Claims;
  16. using System.IdentityModel.Tokens.Jwt;
  17. namespace MySystem.Areas.Api.Controllers
  18. {
  19. [Area("Api")]
  20. [Route("Api/[controller]/[action]")]
  21. public class SystemSetController : BaseController
  22. {
  23. public SystemSetController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  24. {
  25. }
  26. #region 验证获取jwt的token
  27. public JsonResult AppCheck(string value)
  28. {
  29. value = DesDecrypt(value);
  30. // string uuid = data["uuid"].ToString();
  31. // string salt = data["salt"].ToString();
  32. // string u = function.MD5_16(uuid + salt);
  33. Dictionary<string, object> Obj = new Dictionary<string, object>();
  34. //生成jwt令牌
  35. Obj.Add("Token", PublicFunction.AppToken(1, JwtSecret, JwtIss, "consumer"));
  36. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  37. }
  38. #endregion
  39. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  40. /// <summary>
  41. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  42. /// </summary>
  43. /// <param name="value">请求的参数(json字符串)</param>
  44. /// <param name="signField">要签名的字段</param>
  45. /// <returns></returns>
  46. private string CheckSign(string value, string[] signField)
  47. {
  48. JsonData json = JsonMapper.ToObject(value);
  49. Dictionary<string, string> dic = new Dictionary<string, string>();
  50. for (int i = 0; i < signField.Length; i++)
  51. {
  52. dic.Add(signField[i], json[signField[i]].ToString());
  53. }
  54. string sign = json["sign"].ToString(); //客户端签名字符串
  55. return new Sign().sign(dic, sign);
  56. }
  57. #endregion
  58. }
  59. }