唐召明
authored
|
1
|
using Hh.Mes.Service;
|
赖素文
authored
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Hh.Mes.Api.Controllers
{
/// <summary>
/// 系统公共的接口
/// ps:新增方法需要在SystemVariable 注册 APIList、EnumLog 新增枚举 ,方便接口日志定位查询
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class SystemController : BaseController
{
private readonly SystemService service;
|
唐召明
authored
|
17
|
public SystemController(SystemService systemService, IHttpContextAccessor accessor)
|
赖素文
authored
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
{
service = systemService;
context = accessor.HttpContext;
var sysUserApi = base.GetUser(context);
this.service.sysUserApi = sysUserApi;
}
#region 登入 ,退出,检查版本,获取枚举
/// <summary>
/// app检查
/// </summary>
/// <returns></returns>
[HttpGet]
[ActionName("Mes/V1/base/AppCheckVerByAppNameAndVer")]
public string AppCheckVerByAppNameAndVer(string appId, double ver)
{
var result = service.AppCheckVerByAppNameAndVer(appId, ver);
return Serialize(result);
}
/// <summary>
/// 登入退出 【删除redis,删除 sys_user_online】
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionName("Mes/V1/Login/Logout")]
public string Logout()
{
var token = GetToken(HttpContext);
|
唐召明
authored
|
48
|
return Serialize(service.Logout(token));
|
赖素文
authored
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
}
/// <summary>
/// 登入 登入成功后自动在输出到缓存Cookies 头部
/// 其他接口调用前 要先调用登入接口,或者使用配置文件忽略登入验证
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionName("Mes/V1/Login")]
public string Login()
{
string userName = Request.Form["username"].ToString().Trim();
var password = Request.Form["password"].ToString().Trim();
//登录
var result = service.Login(userName, password, Program.AppKey, Program.AppSecret);
bool isOk = result is string;
if (!isOk)
{
//写入cookies
//https://www.cnblogs.com/land/archive/2009/04/10/1433074.html
Response.Cookies.Append(Program.tokens, result.Token);
}
|
唐召明
authored
|
71
72
|
else
{
|
赖素文
authored
|
73
74
|
Response.Cookies.Append(Program.tokens, "");
}
|
唐召明
authored
|
75
|
return Serialize(result);
|
赖素文
authored
|
76
77
78
79
80
81
82
83
84
85
86
87
88
|
}
/// <summary>
/// 判断token是否存在,过期
/// </summary>
[HttpPost]
[ActionName("Mes/V1/AppCheckToken")]
public string AppCheckToken()
{
var token = GetToken(context);
return Serialize(service.AppCheckToken(token));
}
|
|
89
90
91
92
93
94
95
96
97
98
|
///// <summary>
///// 枚举对象
///// </summary>
///// <returns></returns>
//[HttpGet]
//[ActionName("Mes/V1/GetState")]
//public string GetState()
//{
// return service.GetState();
//}
|
赖素文
authored
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/// <summary>
/// 获取PDA用户可访问的模块列表
/// </summary>
[HttpPost]
[ActionName("Mes/V1/GetPDAModules")]
public string GetPDAModules()
{
var token = GetToken(context);
return Serialize(service.GetPDAModules(token));
}
#endregion
/// <summary>
/// 第3方登入
/// </summary>
/// <returns></returns>
[HttpGet]
[ActionName("Mes/V1/Login/OtherLogin")]
public string OtherLogin(string token)
{
//登录
var result = service.OtherLogin(token);
//写入cookies
//https://www.cnblogs.com/land/archive/2009/04/10/1433074.html
//Response.Cookies.Append(Program.tokens, result.Token);
|
唐召明
authored
|
125
|
return Serialize(result);
|
赖素文
authored
|
126
127
128
|
}
}
}
|