Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
c7ce787f
Commit
c7ce787f
authored
Sep 22, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xxx
parent
905acc38
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
15 deletions
+136
-15
UserReidsCache.cs
Mall.CacheManager/User/UserReidsCache.cs
+15
-0
IPHelper.cs
Mall.Common/Plugin/IPHelper.cs
+6
-2
EducationModule.cs
Mall.Module.Education/EducationModule.cs
+25
-0
Startup.cs
Mall.WebApi/Startup.cs
+90
-13
No files found.
Mall.CacheManager/User/UserReidsCache.cs
View file @
c7ce787f
...
...
@@ -58,6 +58,21 @@ namespace Mall.CacheManager.User
return
redis
.
KeyExists
(
cacheKey
);
}
/// <summary>
/// 删除Key
/// </summary>
/// <param name="cacheKey"></param>
/// <returns></returns>
public
static
bool
Delete
(
string
UserId
)
{
string
cacheKey
=
UserModuleCacheKeyConfig
.
Applet_Login_Info
+
UserId
;
if
(
Exists
(
cacheKey
))
{
return
redis
.
KeyDelete
(
cacheKey
);
}
return
false
;
}
/// <summary>
/// 设置缓存
/// </summary>
...
...
Mall.Common/Plugin/IPHelper.cs
View file @
c7ce787f
using
System
;
using
Microsoft.AspNetCore.Http
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
...
...
@@ -87,5 +88,8 @@ namespace Mall.Common.Plugin
{
return
(
userIp
>=
begin
)
&&
(
userIp
<=
end
);
}
}
}
\ No newline at end of file
}
\ No newline at end of file
Mall.Module.Education/EducationModule.cs
View file @
c7ce787f
...
...
@@ -3357,6 +3357,31 @@ namespace Mall.Module.Education
};
return
member_UserRepository
.
Update
(
cols
,
wheres
);
}
/// <summary>
/// 将用户加入黑名单
/// </summary>
/// <param name="TenantId"></param>
/// <param name="MallBaseId"></param>
/// <param name="UserId"></param>
/// <returns></returns>
public
bool
UpdateUserBlacklist
(
int
UserId
)
{
Dictionary
<
string
,
object
>
cols
=
new
Dictionary
<
string
,
object
>()
{
{
nameof
(
RB_Member_User
.
Blacklist
),
1
}
};
List
<
WhereHelper
>
wheres
=
new
List
<
WhereHelper
>()
{
new
WhereHelper
(){
FiledName
=
nameof
(
RB_Member_User
.
Id
),
FiledValue
=
UserId
,
OperatorEnum
=
OperatorEnum
.
Equal
},
};
return
member_UserRepository
.
Update
(
cols
,
wheres
);
}
#
endregion
...
...
Mall.WebApi/Startup.cs
View file @
c7ce787f
...
...
@@ -2,10 +2,17 @@ using System;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Text.Encodings.Web
;
using
System.Text.Unicode
;
using
System.Threading.Tasks
;
using
Dnc.Api.Throttle
;
using
JWT
;
using
JWT.Serializers
;
using
Mall.CacheManager.User
;
using
Mall.Common.Plugin
;
using
Mall.Module.Education
;
using
Mall.Module.User
;
using
Mall.ThirdCore.Message
;
using
Mall.WebApi.Filter
;
using
Microsoft.AspNetCore.Builder
;
...
...
@@ -15,9 +22,11 @@ using Microsoft.AspNetCore.HttpsPolicy;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
Newtonsoft.Json.Linq
;
using
Senparc.CO2NET
;
using
Senparc.CO2NET.HttpUtility
;
using
Senparc.CO2NET.RegisterServices
;
...
...
@@ -46,10 +55,12 @@ namespace Mall.WebApi
// return httpClientHandler;
//});
services
.
Configure
<
Microsoft
.
AspNetCore
.
Server
.
Kestrel
.
Core
.
KestrelServerOptions
>(
x
=>
x
.
AllowSynchronousIO
=
true
)
.
Configure
<
IISServerOptions
>(
x
=>
x
.
AllowSynchronousIO
=
true
);
services
.
AddControllers
();
services
.
AddSingleton
<
IHttpContextAccessor
,
HttpContextAccessor
>();
//注入http上下文
services
.
AddSenparcGlobalServices
(
Configuration
)
//Senparc.CO2NET 全局注册
.
AddSenparcWeixinServices
(
Configuration
);
//Senparc.Weixin 注册
services
.
AddMvc
().
AddJsonOptions
(
options
=>
...
...
@@ -114,24 +125,90 @@ namespace Mall.WebApi
services
.
AddApiThrottle
(
options
=>
{
options
.
Global
.
AddValves
(
new
BlackListValve
options
.
Global
.
AddValves
(
new
BlackListValve
{
Policy
=
Policy
.
Ip
,
Priority
=
99
},
new
WhiteListValve
{
Policy
=
Policy
.
UserIdentity
,
Priority
=
88
},
new
BlackListValve
{
Policy
=
Policy
.
Header
,
PolicyKey
=
"throttle"
,
}
);
options
.
OnIpAddress
=
(
context
)
=>
{
Policy
=
Policy
.
Ip
,
Priority
=
99
},
new
WhiteListValve
{
Policy
=
Policy
.
UserIdentity
,
Priority
=
88
},
new
BlackListValve
{
Policy
=
Policy
.
Header
,
PolicyKey
=
"throttle"
,
});
string
ip
=
""
;
var
newIp
=
context
.
Request
.
Headers
[
"HTTP_X_FORWARDED_FOR"
].
FirstOrDefault
();
if
(
string
.
IsNullOrEmpty
(
newIp
))
{
ip
=
context
.
Connection
.
RemoteIpAddress
.
ToString
();
}
Common
.
Plugin
.
LogHelper
.
Write
(
"ConfigureServices_Ip_【"
+
ip
+
"】"
);
return
ip
;
};
options
.
onIntercepted
=
(
context
,
value
,
where
)
=>
{
Object
parm
=
new
JObject
();
var
request
=
context
.
Request
;
request
.
EnableBuffering
();
string
responseData
=
""
;
using
(
var
reader
=
new
StreamReader
(
request
.
Body
,
encoding
:
Encoding
.
UTF8
))
{
var
body
=
reader
.
ReadToEndAsync
();
// Do some processing with body…
// Reset the request body stream position so the next middleware can read it
responseData
=
body
.
Result
;
request
.
Body
.
Position
=
0
;
}
Common
.
Plugin
.
LogHelper
.
Write
(
"ConfigureServices_responseData_【"
+
responseData
+
"】"
);
if
(!
string
.
IsNullOrWhiteSpace
(
responseData
.
Trim
()))
{
try
{
var
jsonParm
=
JObject
.
Parse
(
responseData
);
var
token
=
jsonParm
.
GetStringValue
(
"token"
);
if
(!
string
.
IsNullOrWhiteSpace
(
token
))
{
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
IDateTimeProvider
provider
=
new
UtcDateTimeProvider
();
IJwtValidator
validator
=
new
JwtValidator
(
serializer
,
provider
);
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtDecoder
decoder
=
new
JwtDecoder
(
serializer
,
validator
,
urlEncoder
);
string
secret
=
Common
.
Config
.
JwtSecretKey
;
var
json
=
decoder
.
Decode
(
token
,
secret
,
verify
:
true
);
//token为之前生成的字符串
JObject
jwtJson
=
JObject
.
Parse
(
json
);
var
mall_userInfo
=
JObject
.
Parse
(
jwtJson
.
GetStringValue
(
"mall_userInfo"
));
var
requestFrom
=
mall_userInfo
.
GetInt
(
"requestFrom"
);
var
uid
=
mall_userInfo
.
GetInt
(
"uid"
);
if
(
requestFrom
==
2
&&
uid
>
0
)
{
UserReidsCache
.
Delete
(
uid
.
ToString
());
new
EducationModule
().
UpdateUserBlacklist
(
uid
);
}
Common
.
Plugin
.
LogHelper
.
Write
(
"ConfigureServices_Token_【"
+
json
+
"】"
);
}
}
catch
(
Exception
ex
)
{
}
}
return
new
ApiThrottleResult
()
{
Content
=
"访问过于频繁!"
};
};
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...
...
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