SystemSetController.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. JsonData data = JsonMapper.ToObject(value);
  31. string uuid = data["uuid"].ToString();
  32. string salt = data["salt"].ToString();
  33. string u = function.MD5_16(uuid + salt);
  34. Dictionary<string, object> Obj = new Dictionary<string, object>();
  35. //生成jwt令牌
  36. Obj.Add("Token", PublicFunction.AppToken(u, JwtSecret, JwtIss, "consumer"));
  37. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  38. }
  39. #endregion
  40. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  41. /// <summary>
  42. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  43. /// </summary>
  44. /// <param name="value">请求的参数(json字符串)</param>
  45. /// <param name="signField">要签名的字段</param>
  46. /// <returns></returns>
  47. private string CheckSign(string value, string[] signField)
  48. {
  49. JsonData json = JsonMapper.ToObject(value);
  50. Dictionary<string, string> dic = new Dictionary<string, string>();
  51. for (int i = 0; i < signField.Length; i++)
  52. {
  53. dic.Add(signField[i], json[signField[i]].ToString());
  54. }
  55. string sign = json["sign"].ToString(); //客户端签名字符串
  56. return new Sign().sign(dic, sign);
  57. }
  58. #endregion
  59. }
  60. }