通过配置api 接口,自动将Result 进行加密返回,同时code返回12标注 目前使用base64
parent
a9407c3290
commit
8b05c01e42
|
@ -28,6 +28,7 @@ using FellowOakDicom.Network;
|
||||||
using IRaCIS.Core.Application.Service.ImageAndDoc;
|
using IRaCIS.Core.Application.Service.ImageAndDoc;
|
||||||
using IP2Region.Net.Abstractions;
|
using IP2Region.Net.Abstractions;
|
||||||
using IP2Region.Net.XDB;
|
using IP2Region.Net.XDB;
|
||||||
|
using IRaCIS.Core.Application.BusinessFilter;
|
||||||
|
|
||||||
|
|
||||||
#region 获取环境变量
|
#region 获取环境变量
|
||||||
|
@ -104,11 +105,9 @@ builder.Services.AddControllers(options =>
|
||||||
options.Filters.Add<ModelActionFilter>();
|
options.Filters.Add<ModelActionFilter>();
|
||||||
options.Filters.Add<ProjectExceptionFilter>();
|
options.Filters.Add<ProjectExceptionFilter>();
|
||||||
options.Filters.Add<UnitOfWorkFilter>();
|
options.Filters.Add<UnitOfWorkFilter>();
|
||||||
|
options.Filters.Add<EncreptApiResultFilter>(10);
|
||||||
|
options.Filters.Add<LimitUserRequestAuthorization>();
|
||||||
|
|
||||||
if (_configuration.GetSection("BasicSystemConfig").GetValue<bool>("OpenLoginLimit"))
|
|
||||||
{
|
|
||||||
options.Filters.Add<LimitUserRequestAuthorization>();
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.AddNewtonsoftJsonSetup(builder.Services); // NewtonsoftJson 序列化 处理
|
.AddNewtonsoftJsonSetup(builder.Services); // NewtonsoftJson 序列化 处理
|
||||||
|
@ -117,6 +116,8 @@ builder.Services.AddOptions().Configure<SystemEmailSendConfig>(_configuration.Ge
|
||||||
builder.Services.AddOptions().Configure<ServiceVerifyConfigOption>(_configuration.GetSection("BasicSystemConfig"));
|
builder.Services.AddOptions().Configure<ServiceVerifyConfigOption>(_configuration.GetSection("BasicSystemConfig"));
|
||||||
builder.Services.AddOptions().Configure<AliyunOSSOptions>(_configuration.GetSection("AliyunOSS"));
|
builder.Services.AddOptions().Configure<AliyunOSSOptions>(_configuration.GetSection("AliyunOSS"));
|
||||||
builder.Services.AddOptions().Configure<ObjectStoreServiceOptions>(_configuration.GetSection("ObjectStoreService"));
|
builder.Services.AddOptions().Configure<ObjectStoreServiceOptions>(_configuration.GetSection("ObjectStoreService"));
|
||||||
|
builder.Services.AddOptions().Configure<EncreptResponseOption>(_configuration.GetSection("EncrypteResponseConfig"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//动态WebApi + UnifiedApiResultFilter 省掉控制器代码
|
//动态WebApi + UnifiedApiResultFilter 省掉控制器代码
|
||||||
|
@ -297,7 +298,7 @@ try
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var server = DicomServerFactory.Create<CStoreSCPService>(11112,userState: app.Services);
|
var server = DicomServerFactory.Create<CStoreSCPService>(11112, userState: app.Services);
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
|
|
@ -92,5 +92,12 @@
|
||||||
"DefaultPassword": "123456",
|
"DefaultPassword": "123456",
|
||||||
"DefaultInternalOrganizationName": "ExtImaging",
|
"DefaultInternalOrganizationName": "ExtImaging",
|
||||||
"ImageShareExpireDays": 10
|
"ImageShareExpireDays": 10
|
||||||
|
},
|
||||||
|
|
||||||
|
"EncrypteResponseConfig": {
|
||||||
|
"IsEnable": true,
|
||||||
|
"ApiPathList": [
|
||||||
|
"/test/get"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace IRaCIS.Core.Application.BusinessFilter
|
||||||
|
{
|
||||||
|
public class EncreptApiResultFilter : IAsyncResultFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IOptionsMonitor<EncreptResponseOption> _encreptResponseMonitor;
|
||||||
|
|
||||||
|
public EncreptApiResultFilter(IOptionsMonitor<EncreptResponseOption> encreptResponseMonitor)
|
||||||
|
{
|
||||||
|
_encreptResponseMonitor = encreptResponseMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(_encreptResponseMonitor.CurrentValue.IsEnable)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (context.Result is ObjectResult objectResult)
|
||||||
|
{
|
||||||
|
var statusCode = objectResult.StatusCode ?? context.HttpContext.Response.StatusCode;
|
||||||
|
|
||||||
|
var objectValue = objectResult.Value;
|
||||||
|
|
||||||
|
|
||||||
|
if (objectValue is IResponseOutput)
|
||||||
|
{
|
||||||
|
var responseOutput = objectValue as IResponseOutput<object>;
|
||||||
|
|
||||||
|
var path = context.HttpContext?.Request.Path.Value?.ToLower();
|
||||||
|
|
||||||
|
|
||||||
|
if(!string.IsNullOrEmpty(path) && path.Length>5 && _encreptResponseMonitor.CurrentValue.ApiPathList.Contains(path.ToLower()))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(responseOutput.IsSuccess)
|
||||||
|
{
|
||||||
|
responseOutput.Code = ApiResponseCodeEnum.ResultEncrepted;
|
||||||
|
responseOutput.Data = JsonConvert.SerializeObject(Convert.ToBase64String(Encoding.UTF8.GetBytes(responseOutput.Data.ToString())));
|
||||||
|
|
||||||
|
objectResult.Value = responseOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
await next.Invoke();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,8 +8,9 @@ namespace IRaCIS.Application.Services.BusinessFilter
|
||||||
/// 统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
|
/// 统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
|
||||||
/// by zhouhang 2021.09.12 周末
|
/// by zhouhang 2021.09.12 周末
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
|
public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步版本
|
/// 异步版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -26,15 +27,6 @@ namespace IRaCIS.Application.Services.BusinessFilter
|
||||||
//是200 并且没有包装 那么包装结果
|
//是200 并且没有包装 那么包装结果
|
||||||
if (statusCode == 200 && !(objectResult.Value is IResponseOutput))
|
if (statusCode == 200 && !(objectResult.Value is IResponseOutput))
|
||||||
{
|
{
|
||||||
//if (objectResult.Value == null)
|
|
||||||
//{
|
|
||||||
// var apiResponse = ResponseOutput.DBNotExist();
|
|
||||||
|
|
||||||
// objectResult.Value = apiResponse;
|
|
||||||
// objectResult.DeclaredType = apiResponse.GetType();
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
|
|
||||||
var type = objectResult.Value?.GetType();
|
var type = objectResult.Value?.GetType();
|
||||||
|
|
||||||
|
@ -64,8 +56,6 @@ namespace IRaCIS.Application.Services.BusinessFilter
|
||||||
objectResult.DeclaredType = apiResponse.GetType();
|
objectResult.DeclaredType = apiResponse.GetType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//如果不是200 是IResponseOutput 不处理
|
//如果不是200 是IResponseOutput 不处理
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using IRaCIS.Core.Domain.Models;
|
using IRaCIS.Core.Domain.Models;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Configuration.Json;
|
using Microsoft.Extensions.Configuration.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Domain.Share
|
namespace IRaCIS.Core.Domain.Share
|
||||||
{
|
{
|
||||||
|
@ -19,7 +20,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
public int LoginMaxFailCount { get; set; }
|
public int LoginMaxFailCount { get; set; }
|
||||||
|
|
||||||
public int LoginFailLockMinutes { get; set; }
|
public int LoginFailLockMinutes { get; set; }
|
||||||
|
|
||||||
public int AutoLoginOutMinutes { get; set; }
|
public int AutoLoginOutMinutes { get; set; }
|
||||||
|
|
||||||
|
@ -39,9 +40,9 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
public class SystemEmailSendConfig
|
public class SystemEmailSendConfig
|
||||||
{
|
{
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
public string Host { get; set; }
|
public string Host { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string FromEmail { get; set; }
|
public string FromEmail { get; set; }
|
||||||
|
@ -66,6 +67,13 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EncreptResponseOption
|
||||||
|
{
|
||||||
|
public bool IsEnable { get; set; }
|
||||||
|
|
||||||
|
public List<string> ApiPathList { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 项目基础配置规则
|
/// 项目基础配置规则
|
||||||
|
@ -89,7 +97,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
public static string SystemSiteCodePrefix { get; set; }
|
public static string SystemSiteCodePrefix { get; set; }
|
||||||
|
|
||||||
public static string BlindTaskPrefix { get; set; }
|
public static string BlindTaskPrefix { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户默认密码
|
/// 用户默认密码
|
||||||
|
@ -104,7 +112,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
{
|
{
|
||||||
Path = "appsettings.json",
|
Path = "appsettings.json",
|
||||||
ReloadOnChange = true
|
ReloadOnChange = true
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
DoctorCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DoctorCodePrefix");
|
DoctorCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DoctorCodePrefix");
|
||||||
|
@ -112,7 +120,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
QCChallengeCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("QCChallengeCodePrefix");
|
QCChallengeCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("QCChallengeCodePrefix");
|
||||||
NoneDicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("NoneDicomStudyCodePrefix");
|
NoneDicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("NoneDicomStudyCodePrefix");
|
||||||
DicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DicomStudyCodePrefix");
|
DicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DicomStudyCodePrefix");
|
||||||
DefaultPassword= configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DefaultPassword");
|
DefaultPassword = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DefaultPassword");
|
||||||
SystemSiteCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("SystemSiteCodePrefix");
|
SystemSiteCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("SystemSiteCodePrefix");
|
||||||
|
|
||||||
DefaultInternalOrganizationName = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DefaultInternalOrganizationName");
|
DefaultInternalOrganizationName = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DefaultInternalOrganizationName");
|
||||||
|
@ -125,7 +133,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
|
|
||||||
//获取实体编码字符串
|
//获取实体编码字符串
|
||||||
public static string GetCodeStr(int codeInt ,string typeStr)
|
public static string GetCodeStr(int codeInt, string typeStr)
|
||||||
{
|
{
|
||||||
switch (typeStr)
|
switch (typeStr)
|
||||||
{
|
{
|
||||||
|
@ -139,7 +147,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
case nameof(QCChallenge):
|
case nameof(QCChallenge):
|
||||||
|
|
||||||
return QCChallengeCodePrefix+ codeInt.ToString("D5");
|
return QCChallengeCodePrefix + codeInt.ToString("D5");
|
||||||
|
|
||||||
case nameof(NoneDicomStudy):
|
case nameof(NoneDicomStudy):
|
||||||
|
|
||||||
|
@ -164,5 +172,5 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -54,7 +54,9 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
NoToken = 10,
|
NoToken = 10,
|
||||||
|
|
||||||
//带了Token,但是没有相应权限(该用户类型不能做)
|
//带了Token,但是没有相应权限(该用户类型不能做)
|
||||||
HaveTokenNotAccess = 11
|
HaveTokenNotAccess = 11,
|
||||||
|
|
||||||
|
ResultEncrepted=12
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回数据
|
/// 返回数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
T Data { get; }
|
T Data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//public interface IResponseOutput<T,T2> : IResponseOutput
|
//public interface IResponseOutput<T,T2> : IResponseOutput
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||||
/// 数据 兼顾以前 Json序列化的时候返回属性名为“Result”
|
/// 数据 兼顾以前 Json序列化的时候返回属性名为“Result”
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("Result")]
|
[JsonProperty("Result")]
|
||||||
public T Data { get; private set; }
|
public T Data { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[JsonProperty("OtherInfo")]
|
[JsonProperty("OtherInfo")]
|
||||||
|
|
Loading…
Reference in New Issue