Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8d5496ef5 | ||
|
|
3edb472bfb |
+16
-1
@@ -1,10 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace YYApi.Communications
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础相应
|
||||
/// </summary>
|
||||
public class BaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
@@ -38,6 +40,7 @@ namespace YYApi.Communications
|
||||
SetCode(200);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 返回指定代码的描述
|
||||
/// </summary>
|
||||
@@ -95,4 +98,16 @@ namespace YYApi.Communications
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态内容
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class BaseResponse<T> : BaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态内容
|
||||
/// </summary>
|
||||
public T Data { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,10 @@ namespace YYApi.Controllers
|
||||
/// </summary>
|
||||
public class BaseController : Controller
|
||||
{
|
||||
protected int LoginId => int.Parse(HttpContext.Items["LoginId"].ToString());
|
||||
/// <summary>
|
||||
/// 当前登录用户的ID
|
||||
/// </summary>
|
||||
protected LoginInfoItem LoginInfo => (LoginInfoItem)HttpContext.Items["LoginInfo"];
|
||||
|
||||
/// <summary>
|
||||
/// 验证请求参数
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
@@ -28,10 +29,10 @@ namespace YYApi.Helpers
|
||||
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
var id = cache.GetString(token);
|
||||
if (id != null)
|
||||
var login = cache.GetString(token);
|
||||
if (login != null)
|
||||
{
|
||||
httpContext.Items.Add("LoginId", id);
|
||||
httpContext.Items.Add("LoginInfo", JsonSerializer.Deserialize<LoginInfoItem>(login));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +40,17 @@ namespace YYApi.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录信息中间件
|
||||
/// </summary>
|
||||
public class LoginInfoItem
|
||||
{
|
||||
//登录用户的ID
|
||||
public int Id { get; set; }
|
||||
//登录用户来源
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测登录中间件
|
||||
/// </summary>
|
||||
@@ -70,10 +82,15 @@ namespace YYApi.Helpers
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public string SetId(int id)
|
||||
public string SetId(int id, string type = "user")
|
||||
{
|
||||
var uuid = GetUUID();
|
||||
Cache.SetString(uuid, id.ToString());
|
||||
var loginItem = new LoginInfoItem
|
||||
{
|
||||
Id = id,
|
||||
Type = type
|
||||
};
|
||||
Cache.SetString(uuid, JsonSerializer.Serialize(loginItem));
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,5 +2,15 @@
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true
|
||||
},
|
||||
"profiles": {
|
||||
"YYApi": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -4,12 +4,13 @@
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<OutputType>Library</OutputType>
|
||||
<PackOnBuild>true</PackOnBuild>
|
||||
<Version>0.1.0</Version>
|
||||
<Version>0.1.3</Version>
|
||||
<Authors>xRain@YYTech</Authors>
|
||||
<Description>AspNetCore一个方便的API文档,捕获异常,统一输入输出的API类库</Description>
|
||||
<PackageId>YY-Tech.YYApi</PackageId>
|
||||
<IsPackable>true</IsPackable>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -21,8 +22,8 @@
|
||||
<Content Remove="Properties\launchSettings.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0-rc4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0-rc5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc5" />
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<MonoDevelop>
|
||||
|
||||
Reference in New Issue
Block a user