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
ef123276
Commit
ef123276
authored
Sep 23, 2021
by
liudong1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
5bb2da32
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
55 deletions
+76
-55
BackListHelper.cs
Mall.Common/BackListHelper.cs
+21
-0
ApiFilterAttribute.cs
Mall.WebApi/Filter/ApiFilterAttribute.cs
+1
-1
Startup.cs
Mall.WebApi/Startup.cs
+54
-54
No files found.
Mall.Common/BackListHelper.cs
0 → 100644
View file @
ef123276
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Mall.Common
{
public
class
BackListHelper
{
public
static
List
<
string
>
bankList
=
new
List
<
string
>();
public
static
void
Add
(
string
Ip
)
{
if
(!
bankList
.
Contains
(
Ip
))
{
bankList
.
Add
(
Ip
);
}
}
}
}
Mall.WebApi/Filter/ApiFilterAttribute.cs
View file @
ef123276
...
...
@@ -49,7 +49,7 @@ namespace Mall.WebApi.Filter
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
new
ApiResult
{
resultCode
=
(
int
)
ResultCode
.
FormRepeatSubmit
,
message
=
"
傻屌
"
,
message
=
"
您已进入访问黑名单
"
,
data
=
null
});
Common
.
Plugin
.
LogHelper
.
Write
(
"OnActionExecuting:"
+
ip
);
...
...
Mall.WebApi/Startup.cs
View file @
ef123276
...
...
@@ -160,63 +160,63 @@ namespace Mall.WebApi
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
;
}
string
ip
=
""
;
ip
=
context
.
Request
.
Headers
[
"X-Forwarded-For"
].
FirstOrDefault
();
if
(
string
.
IsNullOrEmpty
(
ip
))
{
ip
=
context
.
Connection
.
RemoteIpAddress
.
ToString
();
}
Common
.
BackListHelper
.
Add
(
ip
);
Common
.
Plugin
.
LogHelper
.
Write
(
"ConfigureServices_ip2222_【"
+
ip
+
"】"
);
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
);
}
//
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;
//
}
//
string ip = "";
//
ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
//
if (string.IsNullOrEmpty(ip))
//
{
//
ip = context.Connection.RemoteIpAddress.ToString();
//
}
//
Common.BackListHelper.Add(ip);
//
Common.Plugin.LogHelper.Write("ConfigureServices_ip2222_【" + ip + "】");
//
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);
//
}
}
}
catch
(
Exception
ex
)
{
//
}
//
}
//
catch (Exception ex)
//
{
}
}
//
}
//
}
return
new
ApiThrottleResult
()
{
Content
=
"访问过于频繁!"
};
};
//
return new ApiThrottleResult() { Content = "访问过于频繁!" };
//
};
});
}
...
...
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