|
@@ -6,114 +6,50 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
|
using dodohold.core;
|
|
using dodohold.core;
|
|
|
-using Spire.Pdf.Exporting.XPS.Schema;
|
|
|
|
|
-using System.Xml.Linq;
|
|
|
|
|
-using System.Net;
|
|
|
|
|
-using TencentCloud.Mrs.V20200910.Models;
|
|
|
|
|
-using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
-using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
-using Spire.Pdf.Graphics;
|
|
|
|
|
|
|
+using Dataoke;
|
|
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
|
+using Org.BouncyCastle.Ocsp;
|
|
|
|
|
+using System.Diagnostics;
|
|
|
|
|
+using TencentCloud.Fmu.V20191213.Models;
|
|
|
|
|
+using Microsoft.VisualBasic;
|
|
|
|
|
+using System.Text.Json;
|
|
|
|
|
+using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
|
+using System.Security.Cryptography;
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
using System.Threading.Channels;
|
|
using System.Threading.Channels;
|
|
|
-using TencentCloud.Weilingwith.V20230427.Models;
|
|
|
|
|
-using System.Threading;
|
|
|
|
|
-using static dodohold.core.ZTOExpress.CreateOrderArgs;
|
|
|
|
|
|
|
+using TencentCloud.Tione.V20211111.Models;
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace molilian.core
|
|
namespace molilian.core
|
|
|
{
|
|
{
|
|
|
- public partial class UnionCPSCore
|
|
|
|
|
|
|
+ public partial class UnionCpsPlus
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
private static string _end_point;
|
|
private static string _end_point;
|
|
|
- static UnionCPSCore()
|
|
|
|
|
|
|
+ static UnionCpsPlus()
|
|
|
{
|
|
{
|
|
|
_end_point = Environment.GetEnvironmentVariable("EndPoint");
|
|
_end_point = Environment.GetEnvironmentVariable("EndPoint");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static async Task<ActionResult> GetLinkAsync(string channel, string ip, string oaid)
|
|
|
|
|
|
|
+ public static UnionCpsDTO GetFormattedObject(CpsChannelEnum channel, string ip = "", string oaid = "")
|
|
|
{
|
|
{
|
|
|
- return channel switch
|
|
|
|
|
|
|
+ return new()
|
|
|
{
|
|
{
|
|
|
- "eleme" => await EleAsync(ip, oaid),
|
|
|
|
|
- "meituan" => await MeituanAsync(ip, oaid),
|
|
|
|
|
- _ => await InvalidChannelAsync(ip, oaid),
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private static async Task<APIResult> InvalidChannelAsync(string ip, string oaid)
|
|
|
|
|
- {
|
|
|
|
|
- UnionCpsDTO result = new()
|
|
|
|
|
- {
|
|
|
|
|
- channel = CpsChannelEnum.invalid,
|
|
|
|
|
|
|
+ channel = channel,
|
|
|
end_point = _end_point,
|
|
end_point = _end_point,
|
|
|
ip = ip,
|
|
ip = ip,
|
|
|
oaid = oaid
|
|
oaid = oaid
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
- result.success = false;
|
|
|
|
|
- result.message = "无效渠道";
|
|
|
|
|
- _ = TkLogCore.CpsLogAsync(result);
|
|
|
|
|
- return new APIResult(new
|
|
|
|
|
- {
|
|
|
|
|
- result.success,
|
|
|
|
|
- result.message,
|
|
|
|
|
- channel = result.channel.ToString(),
|
|
|
|
|
- });
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static bool ShouldIgnoreRequest(TkConfigDTO config, CpsChannelEnum channel, string ip, string oaid, out string reason)
|
|
|
|
|
- {
|
|
|
|
|
- reason = string.Empty;
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- // IP和流量控制
|
|
|
|
|
- string ignorePercentageCity = config.cpsIgnorePercentageCity;
|
|
|
|
|
- string? ipInfo = IP2RegionPlus.Search(ip);
|
|
|
|
|
- if (AlimamaPlus.IgnoreRegionIncluded(ignorePercentageCity, ipInfo, out string regionInfo))
|
|
|
|
|
- {
|
|
|
|
|
- reason = $"地区控制:{regionInfo}";
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- int limit_num = config.cps_limit_per_ip_24h;
|
|
|
|
|
- if (limit_num > 0)
|
|
|
|
|
- {
|
|
|
|
|
- int num = TkLogCore.getClientRequestTotalByIp(channel, ip);
|
|
|
|
|
- if (num > limit_num)
|
|
|
|
|
- {
|
|
|
|
|
- reason = "IP控制";
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- num = TkLogCore.getClientRequestTotalByOAID(channel, oaid);
|
|
|
|
|
- if (num > limit_num)
|
|
|
|
|
- {
|
|
|
|
|
- reason = "OAID控制";
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- catch (Exception ex)
|
|
|
|
|
- {
|
|
|
|
|
- reason = "配置异常";
|
|
|
|
|
- }
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ #region CPS 相关
|
|
|
public static async Task<APIResult> EleAsync(string ip, string oaid)
|
|
public static async Task<APIResult> EleAsync(string ip, string oaid)
|
|
|
{
|
|
{
|
|
|
- UnionCpsDTO result = new()
|
|
|
|
|
- {
|
|
|
|
|
- channel = CpsChannelEnum.eleme,
|
|
|
|
|
- end_point = _end_point,
|
|
|
|
|
- ip = ip,
|
|
|
|
|
- oaid = oaid
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ UnionCpsDTO result = GetFormattedObject(CpsChannelEnum.eleme, ip, oaid);
|
|
|
var config = TkConfigCore.Get();
|
|
var config = TkConfigCore.Get();
|
|
|
|
|
|
|
|
//============================== 放弃转链-地区过滤 ==============================
|
|
//============================== 放弃转链-地区过滤 ==============================
|
|
|
- if (ShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
|
|
|
|
|
|
|
+ if (CpsShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
|
|
|
{
|
|
{
|
|
|
result.success = false;
|
|
result.success = false;
|
|
|
result.message = "流量控制";
|
|
result.message = "流量控制";
|
|
@@ -144,19 +80,11 @@ namespace molilian.core
|
|
|
|
|
|
|
|
public static async Task<APIResult> MeituanAsync(string ip, string oaid)
|
|
public static async Task<APIResult> MeituanAsync(string ip, string oaid)
|
|
|
{
|
|
{
|
|
|
- UnionCpsDTO result = new()
|
|
|
|
|
- {
|
|
|
|
|
- channel = CpsChannelEnum.meituan,
|
|
|
|
|
- end_point = _end_point,
|
|
|
|
|
- ip = ip,
|
|
|
|
|
- oaid = oaid
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ UnionCpsDTO result = GetFormattedObject(CpsChannelEnum.meituan, ip, oaid);
|
|
|
var config = TkConfigCore.Get();
|
|
var config = TkConfigCore.Get();
|
|
|
|
|
|
|
|
//============================== 放弃转链-地区过滤 ==============================
|
|
//============================== 放弃转链-地区过滤 ==============================
|
|
|
- if (ShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
|
|
|
|
|
|
|
+ if (CpsShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
|
|
|
{
|
|
{
|
|
|
result.success = false;
|
|
result.success = false;
|
|
|
result.message = "流量控制";
|
|
result.message = "流量控制";
|
|
@@ -185,6 +113,46 @@ namespace molilian.core
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public static bool CpsShouldIgnoreRequest(TkConfigDTO config, CpsChannelEnum channel, string ip, string oaid, out string reason)
|
|
|
|
|
+ {
|
|
|
|
|
+ reason = string.Empty;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // IP和流量控制
|
|
|
|
|
+ string ignorePercentageCity = config.cpsIgnorePercentageCity;
|
|
|
|
|
+ string? ipInfo = IP2RegionPlus.Search(ip);
|
|
|
|
|
+ if (AlimamaPlus.IgnoreRegionIncluded(ignorePercentageCity, ipInfo, out string regionInfo))
|
|
|
|
|
+ {
|
|
|
|
|
+ reason = $"地区控制:{regionInfo}";
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ int limit_num = config.cps_limit_per_ip_24h;
|
|
|
|
|
+ if (limit_num > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ int num = TkLogCore.getClientRequestTotalByIp(channel, ip);
|
|
|
|
|
+ if (num > limit_num)
|
|
|
|
|
+ {
|
|
|
|
|
+ reason = "IP控制";
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ num = TkLogCore.getClientRequestTotalByOAID(channel, oaid);
|
|
|
|
|
+ if (num > limit_num)
|
|
|
|
|
+ {
|
|
|
|
|
+ reason = "OAID控制";
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ reason = "配置异常";
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|