Commit ef123276 authored by liudong1993's avatar liudong1993

1

parent 5bb2da32
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);
}
}
}
}
......@@ -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);
......
......@@ -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 = "访问过于频繁!" };
// };
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment