Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
41b5c47f
Commit
41b5c47f
authored
Dec 31, 2021
by
lcx
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/过期限制' into feature/实发绩效检验,医技组绩效,绩效汇总表合并
parents
15e8630f
d808735f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
204 additions
and
0 deletions
+204
-0
performance/Performance.Api/Middlewares/ExpirationLimitMiddleware.cs
+51
-0
performance/Performance.Api/Middlewares/FunctionLimit.cs
+104
-0
performance/Performance.Api/Middlewares/RequestCultureMiddlewareExtensions.cs
+17
-0
performance/Performance.Api/Performance.Api.csproj
+10
-0
performance/Performance.Api/Program.cs
+1
-0
performance/Performance.Api/Startup.cs
+6
-0
performance/Performance.Api/secret.key
+2
-0
performance/Performance.Api/wwwroot/Performance.Api.xml
+12
-0
performance/Performance.DtoModels/ResponseType.cs
+1
-0
No files found.
performance/Performance.Api/Middlewares/ExpirationLimitMiddleware.cs
0 → 100644
View file @
41b5c47f
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Caching.Memory
;
using
Performance.DtoModels
;
using
Performance.Infrastructure
;
using
System
;
using
System.IO
;
using
System.Threading.Tasks
;
namespace
Performance.Api
{
/// <summary>
/// 过期限制
/// </summary>
public
class
ExpirationLimitMiddleware
{
private
readonly
RequestDelegate
_next
;
public
ExpirationLimitMiddleware
(
RequestDelegate
next
)
{
_next
=
next
;
}
public
async
Task
Invoke
(
HttpContext
context
)
{
if
(
context
.
Request
.
Path
.
StartsWithSegments
(
"/api/function/limit"
))
{
var
response
=
new
ApiResponse
(
ResponseType
.
OK
,
new
{
ExpirationTime
=
FunctionLimit
.
Limit
.
ExpirationTime
.
ToString
(
"yyyy-MM-dd"
),
Remark
=
FunctionLimit
.
Limit
.
Remark
,
});
context
.
Response
.
ContentType
=
"application/json"
;
await
context
.
Response
.
WriteAsync
(
JsonHelper
.
Serialize
(
response
));
return
;
}
else
if
(
FunctionLimit
.
Limit
.
ExpirationTime
>
DateTime
.
Now
)
{
await
_next
.
Invoke
(
context
);
return
;
}
else
{
var
response
=
new
ApiResponse
(
ResponseType
.
Expiration
,
FunctionLimit
.
Limit
.
Remark
);
context
.
Response
.
ContentType
=
"application/json"
;
await
context
.
Response
.
WriteAsync
(
JsonHelper
.
Serialize
(
response
));
}
}
}
}
performance/Performance.Api/Middlewares/FunctionLimit.cs
0 → 100644
View file @
41b5c47f
using
System
;
using
System.IO
;
using
System.Security.Cryptography
;
using
System.Text
;
using
XC.RSAUtil
;
namespace
Performance.Api
{
public
class
LimitInformation
{
public
DateTime
ExpirationTime
{
get
;
set
;
}
public
string
Remark
{
get
;
internal
set
;
}
}
public
class
FunctionLimit
{
public
static
LimitInformation
Limit
{
get
;
}
=
new
LimitInformation
();
public
static
void
Init
()
{
string
message
=
"此网站的验证证书有问题,验证证书已过期或还未生效,请及时联系供应厂商进行维护升级。"
;
var
filePath
=
Path
.
Combine
(
Environment
.
CurrentDirectory
,
"secret.key"
);
if
(!
File
.
Exists
(
filePath
))
{
Limit
.
ExpirationTime
=
DateTime
.
MinValue
;
Limit
.
Remark
=
message
;
return
;
}
string
content
=
ReadLimitContent
(
filePath
);
if
(
string
.
IsNullOrEmpty
(
content
))
{
Limit
.
ExpirationTime
=
DateTime
.
MinValue
;
Limit
.
Remark
=
message
;
return
;
}
var
timestamp
=
ConvertToExpiration
(
content
);
if
(
timestamp
==
0
)
{
Limit
.
ExpirationTime
=
DateTime
.
MinValue
;
Limit
.
Remark
=
message
;
return
;
}
Limit
.
ExpirationTime
=
(
new
DateTime
(
1970
,
1
,
1
,
8
,
0
,
0
,
DateTimeKind
.
Unspecified
)).
AddSeconds
(
timestamp
);
Limit
.
Remark
=
Limit
.
ExpirationTime
>
DateTime
.
Now
?
"已授权开放使用!"
:
message
;
}
private
static
long
ConvertToExpiration
(
string
content
)
{
long
result
=
0
;
try
{
var
bigDataRsa
=
new
RsaPkcs8Util
(
Encoding
.
UTF8
,
""
,
privateKey
,
2048
);
var
timestamp
=
bigDataRsa
.
DecryptBigData
(
content
,
RSAEncryptionPadding
.
Pkcs1
);
long
.
TryParse
(
timestamp
,
out
result
);
return
result
;
}
catch
(
Exception
)
{
}
return
result
;
}
private
static
string
ReadLimitContent
(
string
filePath
)
{
var
content
=
""
;
try
{
using
(
FileStream
stream
=
new
FileStream
(
filePath
,
FileMode
.
Open
))
using
(
StreamReader
reader
=
new
StreamReader
(
stream
))
{
content
=
reader
.
ReadToEnd
();
}
}
catch
(
Exception
)
{
}
return
content
;
}
private
static
string
privateKey
=
@"-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC/XTloNsKshhr/
GC34GSQqKxiojkSWBZ+Xe3SxryqrYjx8yyjdrTgBq8lXOO9xtu+jr3XcFwHhFsq5
iK8qwRZQhinASjOFroeszrn0dbuLMT3ad+pCfdkXKcOwmCifHWLqODn0JXmPnTx5
8F1JD954J1Es8ugyJ6S77T0iPezmHvPgxV0Cn4E7Lg2114LwBgy1Kgb5S/b3pz5P
MQKECPRqK69SRIzUU7Nvw1LrqjK9OF5ZWYdGBlCBpRvbd0RIrgJ3NzAUCrE5t3Y+
KI3UM02FhoGzWM0j8oC/P6GGkNL8bY5JMR2TGWfUiB1UUjT+Y2hCCl0tfZUBWPDu
NVeqB9dxAgMBAAECggEAGOU56LLnFKbFsFYm9NXgfJP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q0GM3KPC4MuM8gPkWBRnrGZ67J3bTpgPYVVFxxyIspDG6miMATfZXnDF
OKst4raozj7kX5ghZRZCI2okvFEipVkBSwPdAB20mx5DENXOtpr2h+V/57AgD8Ua
UGTpnMMY2uONH/H/mMPny8D5LA==
-----END PRIVATE KEY-----"
;
}
}
performance/Performance.Api/Middlewares/RequestCultureMiddlewareExtensions.cs
0 → 100644
View file @
41b5c47f
using
Microsoft.AspNetCore.Builder
;
namespace
Performance.Api
{
public
static
class
RequestCultureMiddlewareExtensions
{
/// <summary>
/// 过期限制
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public
static
IApplicationBuilder
UseExpirationLimit
(
this
IApplicationBuilder
builder
)
{
return
builder
.
UseMiddleware
<
ExpirationLimitMiddleware
>();
}
}
}
performance/Performance.Api/Performance.Api.csproj
View file @
41b5c47f
...
...
@@ -22,6 +22,16 @@
<EmbeddedResource Remove="Files\**" />
<None Remove="Files\**" />
</ItemGroup>
<ItemGroup>
<Content Include="secret.key">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="XC.RSAUtil" Version="1.3.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Performance.DtoModels\Performance.DtoModels.csproj" />
...
...
performance/Performance.Api/Program.cs
View file @
41b5c47f
...
...
@@ -11,6 +11,7 @@ public class Program
{
public
static
void
Main
(
string
[]
args
)
{
FunctionLimit
.
Init
();
var
logger
=
NLogBuilder
.
ConfigureNLog
(
"nlog.config"
).
GetCurrentClassLogger
();
try
{
...
...
performance/Performance.Api/Startup.cs
View file @
41b5c47f
...
...
@@ -5,12 +5,14 @@
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc.Authorization
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Hosting
;
using
Performance.Api.Configurations
;
using
Performance.DtoModels
;
using
Performance.Infrastructure
;
using
Performance.Services
;
using
System.Globalization
;
...
...
@@ -112,6 +114,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app
.
UseStatusCodePagesWithReExecute
(
"/error/{0}"
);
}
app
.
UseExpirationLimit
();
app
.
UseRouting
();
app
.
UseAuthentication
();
...
...
@@ -145,4 +150,5 @@ private void JsonOptions(MvcNewtonsoftJsonOptions json)
json
.
SerializerSettings
.
ReferenceLoopHandling
=
Newtonsoft
.
Json
.
ReferenceLoopHandling
.
Ignore
;
}
}
}
performance/Performance.Api/secret.key
0 → 100644
View file @
41b5c47f
UvHeSCNjMucE7mxfpB2wK1XQVSrGyXzxtRzclDPX+IoTYesKy64t4LEB4RpXEkF6lr8f9+GFSX0FPokmRGOzmP/Z+1kYdcu1FnA6DKI5izIe8BmL4GrGzyJYfxrPju8UzHiMexCHBxwzg7KrASjQBuzGS8UDvmOM5+ycZgar3h9zuG//kS9am2+a6BnWYk0iEOH7PGqo/QUOzN7hiSTF6y+Bl0ZmwdFy88sfBDccL9oZ4IbiM1I/zZjC1E4f6A97Tdr6h+BJ7e6kClrbk7TbOGMYKi5JY3CKCmVtCEUSvNriiHlazneLYYIDLFtjpor/9xfG+EDjrPANGtijoNi4YQ==
\ No newline at end of file
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
41b5c47f
...
...
@@ -2165,6 +2165,18 @@
<param
name=
"query"
></param>
<returns></returns>
</member>
<member
name=
"T:Performance.Api.ExpirationLimitMiddleware"
>
<summary>
过期限制
</summary>
</member>
<member
name=
"M:Performance.Api.RequestCultureMiddlewareExtensions.UseExpirationLimit(Microsoft.AspNetCore.Builder.IApplicationBuilder)"
>
<summary>
过期限制
</summary>
<param
name=
"builder"
></param>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.ClaimService.GetUserId"
>
<summary>
获取当前请求登录ID
...
...
performance/Performance.DtoModels/ResponseType.cs
View file @
41b5c47f
...
...
@@ -15,5 +15,6 @@ public enum ResponseType
Disable
=
7
,
TooManyRequests
=
8
,
Warning
=
9
,
Expiration
=
99
,
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment