Quellcode durchsuchen

增加黑名单正则,匹配的不返回dp

dodo hold vor 1 Jahr
Ursprung
Commit
63f028a9dc

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 6 - 0
molilian.core/Core/jd/JdPoolCore.cs

@@ -87,8 +87,14 @@ namespace molilian.core
 
         public static IEnumerable<JdPoolDTO> List(bool force = false)
         {
+#if DEBUG
+            return new DBContext.Table("jd_pool")
+                .Where("", new { status = 1 })
+                .Select<JdPoolDTO>();
+#endif
             if (!force && _cached != null) return _cached;
 
+
             string cache_key = $"cache:jd_pool";
             var list = RedisHelper.Get<IEnumerable<JdPoolDTO>>(cache_key);
             if (force || list == null)

+ 72 - 3
molilian.core/Core/taoke/UnionParseCore.cs

@@ -432,6 +432,25 @@ namespace molilian.core
             {
                 var config = TkConfigCore.Get();
 
+
+                if (!string.IsNullOrEmpty(config.jd_blacklist_regular))
+                {
+                    var blacklist = config.jd_blacklist_regular.Split('\n')
+                        .Where(line => !string.IsNullOrWhiteSpace(line))
+                        .ToList();
+                    bool is_blacklist = AlimamaPlus.MatchOtherInfo(content, blacklist);
+                    if (is_blacklist)
+                    {
+                        result.success = false;
+                        result.deeplink_url = string.Empty;
+                        result.message = "放弃转链";
+                        result.reason = "规则排除";
+                        _ = TkLogCore.ParseLogAsync(result);
+                        return JdParseOutput(result);
+                    }
+                }
+
+
                 //============================== 放弃转链-地区过滤 ==============================
                 if (!result.ip.StartsWith("127.0.0") && accountid == 0 && JdUnionPlus.ShouldIgnoreRequest(config, ip, oaid, out string reason))
                 {
@@ -439,7 +458,11 @@ namespace molilian.core
 
                     result.deeplink_url = result.link_type switch
                     {
-                        LinkTypeEnum.other_aff or LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
+                        LinkTypeEnum.other_aff or
+                        LinkTypeEnum.live or
+                        LinkTypeEnum.video or
+                        LinkTypeEnum.profile or
+                        LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
                         _ => JdUnionPlus.GetDeeplink(string.Empty),
                     };
 
@@ -469,7 +492,12 @@ namespace molilian.core
                     result.success = false;
                     result.message = "放弃转链";
                     result.reason = "没有匹配账号";
-                    result.deeplink_url = JdUnionPlus.GetDeeplink(result.shortLinkurl);
+                    result.deeplink_url = result.link_type switch
+                    {
+                        LinkTypeEnum.other_aff or LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
+                        _ => JdUnionPlus.GetDeeplink(string.Empty),
+                    };
+
                     _ = TkLogCore.ParseLogAsync(result);
                     return JdParseOutput(result);
                 }
@@ -506,7 +534,11 @@ namespace molilian.core
                     result.message = "内部错误";
                     result.reason = "转链接口异常";
                 }
-                result.deeplink_url = JdUnionPlus.GetDeeplink(result.shortLinkurl);
+                result.deeplink_url = result.link_type switch
+                {
+                    LinkTypeEnum.other_aff or LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
+                    _ => JdUnionPlus.GetDeeplink(string.Empty),
+                };
             }
             _ = TkLogCore.ParseLogAsync(result);
             return JdParseOutput(result, IfExceptional ? APIResultCodeEnum.NotAcceptable : APIResultCodeEnum.OK);
@@ -606,6 +638,24 @@ namespace molilian.core
             {
                 var config = TkConfigCore.Get();
 
+                if (!string.IsNullOrEmpty(config.pdd_blacklist_regular))
+                {
+                    var blacklist = config.pdd_blacklist_regular.Split('\n')
+                    .Where(line => !string.IsNullOrWhiteSpace(line))
+                    .ToList();
+                    bool is_blacklist = AlimamaPlus.MatchOtherInfo(content, blacklist);
+                    if (is_blacklist)
+                    {
+                        result.success = false;
+                        result.deeplink_url = string.Empty;
+                        result.message = "放弃转链";
+                        result.reason = "规则排除";
+                        _ = TkLogCore.ParseLogAsync(result);
+                        return PddParseOutput(result);
+                    }
+                }
+
+
                 //============================== 放弃转链-地区过滤 ==============================
                 if (accountid == 0 && PddUnionPlus.ShouldIgnoreRequest(config, ip, oaid, out string reason))
                 {
@@ -691,6 +741,25 @@ namespace molilian.core
             {
                 var config = TkConfigCore.Get();
 
+                if (!string.IsNullOrEmpty(config.ks_blacklist_regular))
+                {
+                    var blacklist = config.ks_blacklist_regular.Split('\n')
+                    .Where(line => !string.IsNullOrWhiteSpace(line))
+                    .ToList();
+                    bool is_blacklist = AlimamaPlus.MatchOtherInfo(content, blacklist);
+                    if (is_blacklist)
+                    {
+                        result.success = false;
+                        result.deeplink_url = string.Empty;
+                        result.message = "放弃转链";
+                        result.reason = "规则排除";
+                        _ = TkLogCore.ParseLogAsync(result);
+                        return KsParseOutput(result);
+                    }
+                }
+
+
+
                 //============================== 放弃转链-地区过滤 ==============================
                 if (accountid == 0 && KsUnionPlus.ShouldIgnoreRequest(config, ip, oaid, out string reason))
                 {

+ 3 - 0
molilian.core/DTO/alimama/TkConfigDTO.cs

@@ -30,6 +30,7 @@ namespace molilian.core
         public string jdIgnorePercentageCity { get; set; } = string.Empty;
         public int jd_limit_per_ip_24h { get; set; } = 0;
         public int jd_limit_per_oaid_24h { get; set; } = 0;
+        public string jd_blacklist_regular { get; set; } = string.Empty;
 
         public int tk_limit_per_ip_24h { get; set; } = 0;
         public int tk_limit_per_oaid_24h { get; set; } = 0;
@@ -42,12 +43,14 @@ namespace molilian.core
         public string pddIgnorePercentageCity { get; set; } = string.Empty;
         public int pdd_limit_per_ip_24h { get; set; } = 0;
         public int pdd_limit_per_oaid_24h { get; set; } = 0;
+        public string pdd_blacklist_regular { get; set; } = string.Empty;
 
 
         public int ksIgnorePercentage { get; set; } = 0;
         public string ksIgnorePercentageCity { get; set; } = string.Empty;
         public int ks_limit_per_ip_24h { get; set; } = 0;
         public int ks_limit_per_oaid_24h { get; set; } = 0;
+        public string ks_blacklist_regular { get; set; } = string.Empty;
         public string ksTestToken { get; set; } = string.Empty;
 
 

+ 94 - 57
molilian.core/Plus/JDUnion/JdUnionPlus.cs

@@ -43,16 +43,19 @@ namespace molilian.core
         {
             if (string.IsNullOrEmpty(url)) return string.Empty;
 
-            // 定义正则表达式模式,使用捕获组提取数字ID
-            string pattern = @"https?://item(?:\.m)?\.jd\.com/(?:product/)?(\d+)\.html(?:\?.*)?";
+            string[] patterns = [
+                @"https?://(?:i-)?item(?:\.m)?\.jd\.com/(?:product/)?(\d+)\.html(?:\?.*)?"
+                //@"https?:\/\/b2b\.m\.jd\.com\/goods-detail\/.*[?&]skuId=(\d+)"
+            ];
 
-            // 使用正则表达式进行匹配
-            Match match = Regex.Match(url, pattern);
-
-            if (match.Success)
+            foreach (var pattern in patterns)
             {
-                string idNumber = match.Groups[1].Value;  // 捕获组1包含数字ID
-                return idNumber;
+                Match match = Regex.Match(url, pattern);
+                if (match.Success)
+                {
+                    string idNumber = match.Groups[1].Value;  // 捕获组1包含数字ID
+                    return idNumber;
+                }
             }
             return string.Empty;
         }
@@ -128,29 +131,33 @@ namespace molilian.core
 
             if (string.IsNullOrEmpty(url)) return LinkTypeEnum.unknown;
             string lowerUrl = url.ToLower();
+            Uri uri = new(url);
 
-            if (lowerUrl.StartsWith("https://u.jd.com") ||
-                lowerUrl.StartsWith("http://u.jd.com"))
-                return LinkTypeEnum.other_aff;
+            if ("3.cn".Equals(uri.Host))
+            {
+                var target_url = GetDesiredUrl(url);
+                return GetLinkType(target_url, out desiredUrl, out itemId);
+            }
+
+            string[] arr = ["mall.jd.com", "shop.m.jd.com", "shop.jd.com"];
+            if (arr.Contains(uri.Host)) return LinkTypeEnum.profile;
+
+            arr = ["lives.jd.com"];
+            if (arr.Contains(uri.Host)) return LinkTypeEnum.live;
 
-            if (lowerUrl.StartsWith("https://lives.jd.com/") ||
-                lowerUrl.StartsWith("http://lives.jd.com/"))
-                return LinkTypeEnum.live;
+            arr = ["u.jd.com"];
+            if (arr.Contains(uri.Host)) return LinkTypeEnum.other_aff;
 
-            if (lowerUrl.StartsWith("https://h5.m.jd.com/active/faxian/video/index.html") ||
-                lowerUrl.StartsWith("http://h5.m.jd.com/active/faxian/video/index.html"))
+            arr = ["h5.m.jd.com"];
+            if (arr.Contains(uri.Host)) return LinkTypeEnum.video;
+
+            if (lowerUrl.Contains("h5.m.jd.com/active/faxian/video/index.html"))
                 return LinkTypeEnum.video;
 
-            if (lowerUrl.StartsWith("https://eco.m.jd.com/content/dr_home/index.html") ||
-                lowerUrl.StartsWith("http://eco.m.jd.com/content/dr_home/index.html")) return LinkTypeEnum.profile;
+            if (lowerUrl.Contains("eco.m.jd.com/content/dr_home/index.html"))
+                return LinkTypeEnum.profile;
 
-            if (lowerUrl.StartsWith("https://3.cn") ||
-                lowerUrl.StartsWith("http://3.cn"))
-            {
-                var target_url = GetDesiredUrl(url);
-                return GetLinkType(target_url, out desiredUrl, out itemId);
-            }
-            if (lowerUrl.Contains("jd.com"))
+            if (uri.Host.Contains("jd.com"))
             {
                 itemId = GetItemId(url);
                 if (!string.IsNullOrEmpty(itemId)) return LinkTypeEnum.goods;
@@ -241,38 +248,64 @@ namespace molilian.core
             url = out_url;
             result.itemId = itemId;
 
-            if (result.link_type == LinkTypeEnum.other_aff)
-            {
-                result.success = false;
-                result.link_type = LinkTypeEnum.unknown;
-                result.channel_type = ChannelTypeEnum.jd;
-                result.message = "放弃转链";
-                result.reason = "其他推广链接";
-                result.accountId = 0;
-                result.accountName = string.Empty;
-                result.content = content;
-                result.shortLinkurl = url;
-                result.deeplink_url = GetDeeplink(url);
-                return result;
-            }
-
-            if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(result.itemId) ||
-                (!url.StartsWith("https://item.jd.com/") &&
-                !url.StartsWith("https://item.m.jd.com/product/") &&
-                !url.StartsWith("http://item.m.jd.com/product/") &&
-                !url.StartsWith("http://item.m.jd.com/product/")))
+            switch (result.link_type)
             {
-                result.success = false;
-                result.link_type = LinkTypeEnum.unknown;
-                result.channel_type = ChannelTypeEnum.jd;
-                result.message = "放弃转链";
-                result.reason = "非标链接";
-                result.accountId = 0;
-                result.accountName = string.Empty;
-                result.content = content;
-                result.shortLinkurl = url;
-                result.deeplink_url = GetDeeplink(url);
-                return result;
+                case LinkTypeEnum.profile:
+                case LinkTypeEnum.live:
+                case LinkTypeEnum.video:
+
+                    result.success = false;
+                    result.channel_type = ChannelTypeEnum.jd;
+                    result.message = "放弃转链";
+                    result.reason = result.link_type switch
+                    {
+                        LinkTypeEnum.profile => "店铺",
+                        LinkTypeEnum.live => "直播",
+                        LinkTypeEnum.video => "视频",
+                        _ => "非标链接",
+                    };
+                    result.accountId = 0;
+                    result.accountName = string.Empty;
+                    result.content = content;
+                    result.shortLinkurl = url;
+                    result.deeplink_url = GetDeeplink(url);
+                    return result;
+                case LinkTypeEnum.other_aff:
+                    result.success = false;
+                    result.link_type = LinkTypeEnum.unknown;
+                    result.channel_type = ChannelTypeEnum.jd;
+                    result.message = "放弃转链";
+                    result.reason = "其他推广链接";
+                    result.accountId = 0;
+                    result.accountName = string.Empty;
+                    result.content = content;
+                    result.shortLinkurl = url;
+                    result.deeplink_url = GetDeeplink(url);
+                    return result;
+                default:
+                    if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(result.itemId) ||
+                        (!url.StartsWith("https://item.jd.com/") &&
+                        !url.StartsWith("https://item.m.jd.com/product/") &&
+                        !url.StartsWith("http://item.m.jd.com/product/") &&
+                        !url.StartsWith("http://item.m.jd.com/product/")))
+                    {
+                        result.success = false;
+                        result.link_type = LinkTypeEnum.unknown;
+                        result.channel_type = ChannelTypeEnum.jd;
+                        result.message = "放弃转链";
+                        result.reason = "非标链接";
+                        result.accountId = 0;
+                        result.accountName = string.Empty;
+                        result.content = content;
+                        result.shortLinkurl = url;
+                        result.deeplink_url = result.link_type switch
+                        {
+                            LinkTypeEnum.other_aff or LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
+                            _ => JdUnionPlus.GetDeeplink(string.Empty),
+                        };
+                        return result;
+                    }
+                    break;
             }
 
             if (!result.ip.StartsWith("127.0.0") && FlowControlIgnoreRequest(_config, out string reason))
@@ -286,7 +319,11 @@ namespace molilian.core
                 result.accountName = string.Empty;
                 result.content = content;
                 result.shortLinkurl = url;
-                result.deeplink_url = GetDeeplink(url);
+                result.deeplink_url = result.link_type switch
+                {
+                    LinkTypeEnum.other_aff or LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
+                    _ => JdUnionPlus.GetDeeplink(string.Empty),
+                };
                 return result;
             }
 

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.