SystemSetController.cs 2.3 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.MainModels;
  10. using LitJson;
  11. using Library;
  12. using Microsoft.IdentityModel.Tokens;
  13. using System.Text;
  14. using System.Security.Claims;
  15. using System.IdentityModel.Tokens.Jwt;
  16. namespace MySystem.Areas.Api.Controllers
  17. {
  18. [Area("Api")]
  19. [Route("Api/[controller]/[action]")]
  20. public class SystemSetController : BaseController
  21. {
  22. public SystemSetController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  23. {
  24. }
  25. #region 验证获取jwt的token
  26. public JsonResult AppCheck(string value)
  27. {
  28. value = DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(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(u, 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. }