| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /*
- * 测试
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using MySystem.Models.Bs;
- using Library;
- using LitJson;
- using Microsoft.AspNetCore.Authorization;
- using MySystem.Service.Bs;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("Api/v1/[controller]/[action]")]
- public class TestController : BaseController
- {
- public TestController(IHttpContextAccessor accessor) : base(accessor)
- {
- }
- #region 测试方法
- /// <summary>
- /// 产品库列表
- /// </summary>
- /// <returns></returns>
- // [HttpPost]
- // [Authorize]
- [Route("/main/test/all")]
- public JsonResult List(string value)
- {
- value = PublicFunction.DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- string userName = "root"; //账号
- string pwd = "123456"; //密码
- SysAdmin sys = SysAdminService.Query(userName, function.MD5_32(pwd));
- if (sys.Id == 0)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "账号或密码不正确" });
- }
- int RoleId = int.Parse(function.CheckInt(sys.Role));
- SysAdminRole Role = SysAdminRoleService.Query(RoleId);
- string RightInfo = function.CheckNull(Role.RightInfo);
- Dictionary<string, object> obj = new Dictionary<string, object>(); //返回字段
- obj.Add("rightList", new AdminRightList().GetRight(sys.Role, RightInfo)); //权限列表
- obj.Add("apiToken", PublicFunction.AppToken(sys.AdminName)); //后台所有接口API所需的token
- obj.Add("apiTokenExpiredDate", DateTime.Now.AddDays(10).ToString("yyyy-MM-dd HH:mm:ss"));
- string token = dbconn.Encrypt3DES(sys.Id.ToString() + "-" + function.ConvertDateTimeInt(DateTime.Now));
- RefreshTokens check = RefreshTokensService.Query(sys.Id);
- if (check.UserId == 0)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("UserId", sys.Id);
- Fields.Add("ExpiredDate", DateTime.Now.AddDays(10));
- Fields.Add("RefreshToken", token);
- RefreshTokensService.Add(Fields);
- }
- else
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("ExpiredDate", DateTime.Now.AddDays(10));
- Fields.Add("RefreshToken", token);
- RefreshTokensService.Edit(Fields, sys.Id);
- }
- List<string> roles = new List<string>();
- roles.Add(sys.Role);
- obj.Add("roles", roles);
- obj.Add("realName", sys.RealName);
- obj.Add("refreshToken", token); //主token,用于刷新apiToken
- AppConfig.LoginSession.sysId = sys.Id;
- AppConfig.LoginSession.sysAdminName = sys.AdminName;
- AppConfig.LoginSession.sysRealName = sys.RealName;
- return Json(new AppResultJson() { Status = "1", Info = "", Data = obj });
- }
- #endregion
- }
- }
|