|
|
@@ -27,6 +27,7 @@ namespace molilian.core
|
|
|
{
|
|
|
string _app_key;
|
|
|
string _app_secret;
|
|
|
+ static Random _random = new Random();
|
|
|
public JdUnionPlus(string app_key, string app_secret)
|
|
|
{
|
|
|
_app_key = app_key;
|
|
|
@@ -109,29 +110,51 @@ namespace molilian.core
|
|
|
return body;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public static bool ShouldIgnoreRequest(string ip, string oaid, out string reason)
|
|
|
{
|
|
|
reason = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
+ // IP和流量控制
|
|
|
var config = TkConfigCore.Get();
|
|
|
+ string ignorePercentageCity = config.jdIgnorePercentageCity;
|
|
|
+ string? ipInfo = IP2RegionPlus.Search(ip);
|
|
|
+ if (AlimamaPlus.IgnoreRegionIncluded(ignorePercentageCity, ipInfo, out string regionInfo))
|
|
|
+ {
|
|
|
+ reason = $"地区控制:{regionInfo}";
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ reason = "配置异常";
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
+ public static bool FlowControlIgnoreRequest(out string reason)
|
|
|
+ {
|
|
|
+ reason = string.Empty;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // IP和流量控制
|
|
|
+ var config = TkConfigCore.Get();
|
|
|
int ignorePercentage = config.jdIgnorePercentage;
|
|
|
if (ignorePercentage == 0) return false;
|
|
|
- Random random = new Random();
|
|
|
- var randomValue = (decimal)random.Next(0, 100);
|
|
|
- bool result = randomValue <= ignorePercentage; // 如果生成的随机数小于忽略百分比,则返回 true,表示需要忽略请求
|
|
|
- if (result) reason = "流量控制";
|
|
|
- return result;
|
|
|
|
|
|
+ var randomValue = (decimal)_random.Next(0, 100);
|
|
|
+ bool result = randomValue <= ignorePercentage; // 如果生成的随机数小于忽略百分比,则返回 true,表示需要忽略请求
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ reason = "流量控制";
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
reason = $"配置异常";
|
|
|
- return true;
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|