Commit c7ce787f authored by 黄奎's avatar 黄奎

xxx

parent 905acc38
...@@ -58,6 +58,21 @@ namespace Mall.CacheManager.User ...@@ -58,6 +58,21 @@ namespace Mall.CacheManager.User
return redis.KeyExists(cacheKey); 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>
/// 设置缓存 /// 设置缓存
/// </summary> /// </summary>
......
using System; using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -87,5 +88,8 @@ namespace Mall.Common.Plugin ...@@ -87,5 +88,8 @@ namespace Mall.Common.Plugin
{ {
return (userIp >= begin) && (userIp <= end); return (userIp >= begin) && (userIp <= end);
} }
} }
} }
\ No newline at end of file
...@@ -3357,6 +3357,31 @@ namespace Mall.Module.Education ...@@ -3357,6 +3357,31 @@ namespace Mall.Module.Education
}; };
return member_UserRepository.Update(cols, wheres); 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 #endregion
......
...@@ -2,10 +2,17 @@ using System; ...@@ -2,10 +2,17 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Text.Unicode; using System.Text.Unicode;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dnc.Api.Throttle; 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.ThirdCore.Message;
using Mall.WebApi.Filter; using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
...@@ -15,9 +22,11 @@ using Microsoft.AspNetCore.HttpsPolicy; ...@@ -15,9 +22,11 @@ using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using Senparc.CO2NET; using Senparc.CO2NET;
using Senparc.CO2NET.HttpUtility; using Senparc.CO2NET.HttpUtility;
using Senparc.CO2NET.RegisterServices; using Senparc.CO2NET.RegisterServices;
...@@ -46,10 +55,12 @@ namespace Mall.WebApi ...@@ -46,10 +55,12 @@ namespace Mall.WebApi
// return httpClientHandler; // return httpClientHandler;
//}); //});
services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true) services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true)
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true); .Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
services.AddControllers(); services.AddControllers();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文 services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文
services.AddSenparcGlobalServices(Configuration)//Senparc.CO2NET 全局注册 services.AddSenparcGlobalServices(Configuration)//Senparc.CO2NET 全局注册
.AddSenparcWeixinServices(Configuration);//Senparc.Weixin 注册 .AddSenparcWeixinServices(Configuration);//Senparc.Weixin 注册
services.AddMvc().AddJsonOptions(options => services.AddMvc().AddJsonOptions(options =>
...@@ -114,11 +125,13 @@ namespace Mall.WebApi ...@@ -114,11 +125,13 @@ namespace Mall.WebApi
services.AddApiThrottle(options => services.AddApiThrottle(options =>
{ {
options.Global.AddValves(new BlackListValve options.Global.AddValves(
new BlackListValve
{ {
Policy = Policy.Ip, Policy = Policy.Ip,
Priority = 99 Priority = 99
}, new WhiteListValve },
new WhiteListValve
{ {
Policy = Policy.UserIdentity, Policy = Policy.UserIdentity,
Priority = 88 Priority = 88
...@@ -127,13 +140,77 @@ namespace Mall.WebApi ...@@ -127,13 +140,77 @@ namespace Mall.WebApi
{ {
Policy = Policy.Header, Policy = Policy.Header,
PolicyKey = "throttle", PolicyKey = "throttle",
}); }
);
options.OnIpAddress = (context) =>
{
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. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting) public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
{ {
......
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