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 ...@@ -49,7 +49,7 @@ namespace Mall.WebApi.Filter
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(new ApiResult actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(new ApiResult
{ {
resultCode = (int)ResultCode.FormRepeatSubmit, resultCode = (int)ResultCode.FormRepeatSubmit,
message = "傻屌", message = "您已进入访问黑名单",
data = null data = null
}); });
Common.Plugin.LogHelper.Write("OnActionExecuting:" + ip); Common.Plugin.LogHelper.Write("OnActionExecuting:" + ip);
......
...@@ -160,63 +160,63 @@ namespace Mall.WebApi ...@@ -160,63 +160,63 @@ namespace Mall.WebApi
Common.Plugin.LogHelper.Write("ConfigureServices_ip_【" + ip + "】"); Common.Plugin.LogHelper.Write("ConfigureServices_ip_【" + ip + "】");
return ip; return ip;
}; };
options.onIntercepted = (context, value, where) => //options.onIntercepted = (context, value, where) =>
{ // {
Object parm = new JObject(); // Object parm = new JObject();
var request = context.Request; // var request = context.Request;
request.EnableBuffering(); // request.EnableBuffering();
string responseData = ""; // string responseData = "";
using (var reader = new StreamReader(request.Body, encoding: Encoding.UTF8)) // using (var reader = new StreamReader(request.Body, encoding: Encoding.UTF8))
{ // {
var body = reader.ReadToEndAsync(); // var body = reader.ReadToEndAsync();
// Do some processing with body… // // Do some processing with body…
// Reset the request body stream position so the next middleware can read it // // Reset the request body stream position so the next middleware can read it
responseData = body.Result; // responseData = body.Result;
request.Body.Position = 0; // request.Body.Position = 0;
} // }
string ip = ""; // string ip = "";
ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault(); // ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
if (string.IsNullOrEmpty(ip)) // if (string.IsNullOrEmpty(ip))
{ // {
ip = context.Connection.RemoteIpAddress.ToString(); // ip = context.Connection.RemoteIpAddress.ToString();
} // }
Common.BackListHelper.Add(ip); // Common.BackListHelper.Add(ip);
Common.Plugin.LogHelper.Write("ConfigureServices_ip2222_【" + ip + "】"); // Common.Plugin.LogHelper.Write("ConfigureServices_ip2222_【" + ip + "】");
if (!string.IsNullOrWhiteSpace(responseData.Trim())) // if (!string.IsNullOrWhiteSpace(responseData.Trim()))
{ // {
try // try
{ // {
var jsonParm = JObject.Parse(responseData); // var jsonParm = JObject.Parse(responseData);
var token = jsonParm.GetStringValue("token"); // var token = jsonParm.GetStringValue("token");
if (!string.IsNullOrWhiteSpace(token)) // if (!string.IsNullOrWhiteSpace(token))
{ // {
IJsonSerializer serializer = new JsonNetSerializer(); // IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider(); // IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider); // IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); // IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder); // IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);
string secret = Common.Config.JwtSecretKey; // string secret = Common.Config.JwtSecretKey;
var json = decoder.Decode(token, secret, verify: true);//token为之前生成的字符串 // var json = decoder.Decode(token, secret, verify: true);//token为之前生成的字符串
JObject jwtJson = JObject.Parse(json); // JObject jwtJson = JObject.Parse(json);
var mall_userInfo = JObject.Parse(jwtJson.GetStringValue("mall_userInfo")); // var mall_userInfo = JObject.Parse(jwtJson.GetStringValue("mall_userInfo"));
var requestFrom = mall_userInfo.GetInt("requestFrom"); // var requestFrom = mall_userInfo.GetInt("requestFrom");
var uid = mall_userInfo.GetInt("uid"); // var uid = mall_userInfo.GetInt("uid");
if (requestFrom == 2 && uid > 0) // if (requestFrom == 2 && uid > 0)
{ // {
UserReidsCache.Delete(uid.ToString()); // UserReidsCache.Delete(uid.ToString());
new EducationModule().UpdateUserBlacklist(uid); // 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