TestController.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * 测试
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.AspNetCore.Http;
  9. using MySystem.Models.Bs;
  10. using Library;
  11. using LitJson;
  12. using Microsoft.AspNetCore.Authorization;
  13. using MySystem.Service.Bs;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/[controller]/[action]")]
  18. public class TestController : BaseController
  19. {
  20. public TestController(IHttpContextAccessor accessor) : base(accessor)
  21. {
  22. }
  23. #region 测试方法
  24. /// <summary>
  25. /// 产品库列表
  26. /// </summary>
  27. /// <returns></returns>
  28. // [HttpPost]
  29. // [Authorize]
  30. [Route("/main/test/all")]
  31. public JsonResult List(string value)
  32. {
  33. value = PublicFunction.DesDecrypt(value);
  34. JsonData data = JsonMapper.ToObject(value);
  35. string userName = "root"; //账号
  36. string pwd = "123456"; //密码
  37. SysAdmin sys = SysAdminService.Query(userName, function.MD5_32(pwd));
  38. if (sys.Id == 0)
  39. {
  40. return Json(new AppResultJson() { Status = "-1", Info = "账号或密码不正确" });
  41. }
  42. int RoleId = int.Parse(function.CheckInt(sys.Role));
  43. SysAdminRole Role = SysAdminRoleService.Query(RoleId);
  44. string RightInfo = function.CheckNull(Role.RightInfo);
  45. Dictionary<string, object> obj = new Dictionary<string, object>(); //返回字段
  46. obj.Add("rightList", new AdminRightList().GetRight(sys.Role, RightInfo)); //权限列表
  47. obj.Add("apiToken", PublicFunction.AppToken(sys.AdminName)); //后台所有接口API所需的token
  48. obj.Add("apiTokenExpiredDate", DateTime.Now.AddDays(10).ToString("yyyy-MM-dd HH:mm:ss"));
  49. string token = dbconn.Encrypt3DES(sys.Id.ToString() + "-" + function.ConvertDateTimeInt(DateTime.Now));
  50. RefreshTokens check = RefreshTokensService.Query(sys.Id);
  51. if (check.UserId == 0)
  52. {
  53. Dictionary<string, object> Fields = new Dictionary<string, object>();
  54. Fields.Add("UserId", sys.Id);
  55. Fields.Add("ExpiredDate", DateTime.Now.AddDays(10));
  56. Fields.Add("RefreshToken", token);
  57. RefreshTokensService.Add(Fields);
  58. }
  59. else
  60. {
  61. Dictionary<string, object> Fields = new Dictionary<string, object>();
  62. Fields.Add("ExpiredDate", DateTime.Now.AddDays(10));
  63. Fields.Add("RefreshToken", token);
  64. RefreshTokensService.Edit(Fields, sys.Id);
  65. }
  66. List<string> roles = new List<string>();
  67. roles.Add(sys.Role);
  68. obj.Add("roles", roles);
  69. obj.Add("realName", sys.RealName);
  70. obj.Add("refreshToken", token); //主token,用于刷新apiToken
  71. AppConfig.LoginSession.sysId = sys.Id;
  72. AppConfig.LoginSession.sysAdminName = sys.AdminName;
  73. AppConfig.LoginSession.sysRealName = sys.RealName;
  74. return Json(new AppResultJson() { Status = "1", Info = "", Data = obj });
  75. }
  76. #endregion
  77. }
  78. }