Prechádzať zdrojové kódy

修复ip/oaid频控的bug;
deeplink转链增加插件redu;

dodo hold 1 rok pred
rodič
commit
465cec0d59

+ 3 - 0
molilian.api/Controllers/public/TaskController.cs

@@ -367,6 +367,8 @@ namespace molilian.api.Controllers
                     DBContext.Execute(sql, null);
                     sql = $"CREATE TABLE IF NOT EXISTS ks_parse_logs_{table_suffix} LIKE ks_parse_logs;";
                     DBContext.Execute(sql, null);
+                    sql = $"CREATE TABLE IF NOT EXISTS dy_parse_logs_{table_suffix} LIKE dy_parse_logs;";
+                    DBContext.Execute(sql, null);
                     sql = $"CREATE TABLE IF NOT EXISTS tk_promotion_logs_{table_suffix} LIKE tk_promotion_logs;";
                     DBContext.Execute(sql, null);
 
@@ -760,6 +762,7 @@ namespace molilian.api.Controllers
             JdPoolCore.Refresh();
             PddPoolCore.Refresh();
             PangolinPoolCore.Refresh();
+            ReduPoolCore.Refresh();
 
             //ElePoolCore.Refresh();
             //MeituanPoolCore.Refresh();

+ 2 - 2
molilian.api/Controllers/public/TestController.cs

@@ -127,7 +127,7 @@ namespace molilian.api.Controllers
         {
             ReduPlus plus = new ReduPlus("", "", "");
             var result = await plus.DouyinParse(command);
-            return Content(result);
+            return Content(result.Convert2Json());
         }
 
         [HttpGet]
@@ -136,7 +136,7 @@ namespace molilian.api.Controllers
 
             ReduPlus plus = new ReduPlus("", "", "");
             var result = await plus.KuaishouParse(command);
-            return Content(result);
+            return Content(result.Convert2Json());
         }
 
 

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 76 - 0
molilian.core/Core/douyin/ReduPoolCore.cs

@@ -0,0 +1,76 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.AspNetCore.Mvc.Filters;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using dodohold.core;
+using Dataoke;
+using Google.Protobuf.WellKnownTypes;
+using System.Diagnostics;
+using System.Text.Json;
+using TencentCloud.Tcm.V20210413.Models;
+
+
+namespace molilian.core
+{
+    public partial class ReduPoolCore
+    {
+        private static readonly object _lockObj = new();
+        private static IEnumerable<ReduPoolDTO> _cached;
+        public static ReduPoolDTO? GetOne()
+        {
+            var list = List();
+            if (!list.Any()) return null;
+            return list.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
+        }
+
+        public static IEnumerable<ReduPoolDTO> List(bool force = false)
+        {
+            if (!force && _cached != null) return _cached;
+
+            string cache_key = $"cache:redu_pool";
+            var list = RedisHelper.Get<IEnumerable<ReduPoolDTO>>(cache_key);
+            if (force || list == null)
+            {
+                lock (_lockObj)
+                {
+                    list = new DBContext.Table("redu_pool")
+                        .Where("status=@status", new { status = 1 })
+                        .Select<ReduPoolDTO>();
+                    if (list == null) return default;
+                    RedisHelper.Set(cache_key, list, 30 * 86400);
+                }
+            }
+            _cached = list;
+            return list;
+        }
+        public static void Refresh()
+        {
+            _ = List(true);
+        }
+
+        public static void Disabled(string name)
+        {
+            string cache_key = $"cache:redu_pool:{name}:disabled";
+            long count = RedisHelper.IncrBy(cache_key);
+            RedisHelper.Expire(cache_key, 10);
+            if (count > 1) return;
+
+            new DBContext.Table("redu_pool")
+                .Add("status", 0)
+                .Where("name=@name", new { name })
+                .Update();
+            _ = List(true);
+
+            NotifyCore.Notify(new NifyMessage
+            {
+                message = $"【热度:{name}】调用异常",
+                priority = NifyMessagePriority.high,
+                tags = ["red_circle"]
+            });
+        }
+
+    }
+}

+ 13 - 2
molilian.core/Core/log/base.cs

@@ -20,6 +20,7 @@ using TencentCloud.Csip.V20221121.Models;
 using COSXML.Network;
 using System.Security.Policy;
 using System.Diagnostics;
+using TencentCloud.Ecm.V20190719.Models;
 
 
 namespace molilian.core
@@ -195,6 +196,15 @@ namespace molilian.core
                 log.SaveAsync();
                 stopwatch.Reset();
 
+
+                stopwatch.Start();
+                taskTotal = task_insert_parse_dy_logs(limit, redis);
+                total += taskTotal;
+                stopwatch.Stop();
+                log.Info($"task_insert_parse_dy_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
+                log.SaveAsync();
+                stopwatch.Reset();
+
                 transaction.Commit();
             }
             catch (Exception ex)
@@ -244,7 +254,8 @@ namespace molilian.core
             Task.Run(() => RunTaskWithLogging(() => task_insert_parse_coupon_logs(limit, redis), "task_insert_parse_coupon_logs")),
             Task.Run(() => RunTaskWithLogging(() => task_insert_parse_cps_logs(limit, redis), "task_insert_parse_cps_logs")),
             Task.Run(() => RunTaskWithLogging(() => task_insert_promotion_img_logs(limit, redis), "task_insert_promotion_img_logs")),
-            Task.Run(() => RunTaskWithLogging(() => task_insert_parse_ks_logs(limit, redis), "task_insert_parse_ks_logs"))
+            Task.Run(() => RunTaskWithLogging(() => task_insert_parse_ks_logs(limit, redis), "task_insert_parse_ks_logs")),
+            Task.Run(() => RunTaskWithLogging(() => task_insert_parse_dy_logs(limit, redis), "task_insert_parse_dy_logs"))
         };
 
                 // 等待所有任务完成
@@ -417,7 +428,7 @@ namespace molilian.core
             await EndPointCore.ProcessEndPointNodesAsync(node =>
             {
                 if (string.IsNullOrEmpty(node.redis_server)) return Task.CompletedTask;
-
+                if (!node.is_public_api) return Task.CompletedTask;
 
 #if DEBUG
                 switch (node.name)

+ 4 - 2
molilian.core/Core/log/dy.cs

@@ -19,9 +19,11 @@ namespace molilian.core
 
                 for (int i = 0; i < limit; i++)
                 {
+
                     var data = redis.LPop<DyDataDTO>(queue_parse_dy_key);
                     if (data == null) break;
-                    new DBContext.Table(connection, "tk_parse_logs")
+                    string daily_table = $"dy_parse_logs_{data.create_time:yyyyMMdd}";
+                    new DBContext.Table(connection, daily_table)
                         .Add("end_point", data.end_point)
                         .Add("channel", (int)data.channel)
                         .Add("accountId", data.accountId)
@@ -72,7 +74,7 @@ namespace molilian.core
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 _ = RedisHelper.RPushAsync(queue_parse_dy_key, response);
 
-                saveClientRequestTotal(response.channel, response.ip, response.oaid);
+                if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
 
                 if (!response.ip.Contains("127.0.0"))
                 {

+ 2 - 1
molilian.core/Core/log/jd.cs

@@ -80,10 +80,11 @@ namespace molilian.core
                         response.deeplink_url);
                 }
 
+                if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
                 if (response.success || response.message.Equals("转链失败"))
                 {
                     RiskControlCore.CallsIncrBy(response.channel, response.accountId);
-                    saveClientRequestTotal(response.channel, response.ip, response.oaid);
+                    //saveClientRequestTotal(response.channel, response.ip, response.oaid);
                 }
 
                 if (!response.success && ("nologin".Equals(response.reason) ||

+ 1 - 1
molilian.core/Core/log/ks.cs

@@ -75,12 +75,12 @@ namespace molilian.core
                         response.deeplink_url);
                 }
 
+                //if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
                 if (response.success || response.message.Equals("转链失败"))
                 {
                     RiskControlCore.CallsIncrBy(response.channel, response.accountId);
                     saveClientRequestTotal(response.channel, response.ip, response.oaid);
                 }
-
                 if (!response.success && ("nologin".Equals(response.reason) ||
                     "方法不存在".Equals(response.reason) ||
                     "未登录".Equals(response.reason)))

+ 1 - 0
molilian.core/Core/log/pdd.cs

@@ -75,6 +75,7 @@ namespace molilian.core
                         response.deeplink_url);
                 }
 
+                //if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
                 if (response.success || response.message.Equals("转链失败"))
                 {
                     RiskControlCore.CallsIncrBy(response.channel, response.accountId);

+ 94 - 0
molilian.core/Core/tool/DeeplinkParseCore.cs

@@ -1,9 +1,11 @@
 
+using COSXML.Network;
 using dodohold.core;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.FileSystemGlobbing.Internal;
 using Sayaka.Common;
 using Spire.Pdf.Annotations;
+using System.Security.Cryptography;
 using System.Text.RegularExpressions;
 using System.Web;
 using System.Xml.Linq;
@@ -218,11 +220,28 @@ namespace molilian.core
                 var match = regex.Match(content);
                 if (match.Success)
                 {
+
                     if (match.Groups.Count > 1)
                     {
                         for (var i = 1; i < match.Groups.Count; i++)
                         {
                             string val = match.Groups[i].Value;
+
+
+                            switch (rule.plugin)
+                            {
+                                case "redu":
+                                    string deeplink_url = await PluginDyParseAsync(text, val, result);
+                                    if (!string.IsNullOrEmpty(deeplink_url))
+                                    {
+                                        result.itemName = prompt_text;
+                                        result.deeplink_url = deeplink_url;
+                                        result.success = true;
+                                        return result;
+                                    }
+                                    break;
+                            }
+
                             if (deeplink.Contains("{url:"))
                             {
                                 string encodedUrl = HttpUtility.UrlEncode(val);
@@ -336,6 +355,81 @@ namespace molilian.core
 
         }
 
+        public static async Task<string> PluginDyParseAsync(string content, string matchText, DeeplinkParseDataDTO deeplinkResult, CancellationToken cancellationToken = default)
+        {
+            string ip = deeplinkResult.ip;
+            string oaid = deeplinkResult.oaid;
+
+            var result = DyUnionPlus.GetFormattedObject(content, ip, oaid);
+            result.create_time = deeplinkResult.create_time;
+
+
+            result.rawContent = content;
+            bool IfExceptional = false;
+            try
+            {
+
+                if (DyUnionPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = reason;
+                    _ = TkLogCore.ParseLogAsync(result);
+                    return null;
+                }
+
+                var account = ReduPoolCore.GetOne();
+                if (account == null)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "没有匹配账号";
+                    _ = TkLogCore.ParseLogAsync(result);
+                    return null;
+                }
+
+                var now = DateTime.Now;
+                var ts2 = now - result.create_time;
+                result.elapsedTime2 = (int)ts2.TotalMilliseconds;
+                result = await DyUnionPlus.DyParseAsync(account, matchText, result, cancellationToken);
+                result.deeplink_url = result.deeplink_url.Replace("snssdk1128://", "snssdk561124://");
+
+                var ts3 = DateTime.Now - now;
+                result.elapsedTime3 = (int)ts3.TotalMilliseconds;
+            }
+            catch (Exception ex)
+            {
+                if (ex.Message.Contains("was canceled"))
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "请求超时";
+                }
+                else
+                {
+                    IfExceptional = true;
+                    _ = new LoggerLibrary("unionParse", "dy_error")
+                        .Info(ip, oaid)
+                        .Info(content)
+                        .Info(ex.Message, ex.StackTrace)
+                        .SaveAsync();
+                    NotifyCore.Notify(new NifyMessage
+                    {
+                        message = $"【转链异常DY】\n{content}\n\n{ex.Message}\n{ex.StackTrace}",
+                        priority = NifyMessagePriority.high,
+                        tags = ["red_circle"]
+                    });
+                    result.success = false;
+                    result.message = "内部错误";
+                    result.reason = "转链接口异常";
+                }
+            }
+            var ts = DateTime.Now - result.create_time;
+            result.elapsedTime = (int)ts.TotalMilliseconds;
+            _ = TkLogCore.ParseLogAsync(result);
+            return result.deeplink_url;
+        }
+
     }
 
 }

+ 1 - 0
molilian.core/DTO/deeplink/DeeplinkParseRuleDTO.cs

@@ -15,6 +15,7 @@ namespace molilian.core
         public string body_pattern { get; set; } = string.Empty;
         public string url_pattern { get; set; } = string.Empty;
         public string pattern { get; set; } = string.Empty;
+        public string plugin { get; set; } = string.Empty;
         public string deeplink_template { get; set; } = string.Empty;
         public string prompt_text { get; set; } = string.Empty;
         public bool enable { get; set; } = true;

+ 2 - 0
molilian.core/DTO/dy/DyDataDTO.cs

@@ -26,6 +26,8 @@
         public string shortLinkurl { get; set; } = string.Empty;
         public string deeplink_url { get; set; } = string.Empty;
         public int elapsedTime { get; set; } = 0;
+        public int elapsedTime2 { get; set; } = 0;
+        public int elapsedTime3 { get; set; } = 0;
         public DateTime create_time { get; set; } = DateTime.Now;
         public string end_point { get; set; } = string.Empty;
         public int subCode { get; set; } = 0;

+ 17 - 0
molilian.core/DTO/dy/ReduDTO.cs

@@ -0,0 +1,17 @@
+namespace molilian.core
+{
+
+    public class ReduPoolDTO
+    {
+        public int id { get; set; }
+        public string name { get; set; } = string.Empty;
+        public string description { get; set; } = string.Empty;
+        public string base_url { get; set; } = string.Empty;
+        public string app_key { get; set; } = string.Empty;
+        public string app_secret { get; set; } = string.Empty;
+        public DateTime create_time { get; set; }
+        public DateTime last_time { get; set; }
+        public bool status { get; set; }
+
+    }
+}

+ 35 - 0
molilian.core/Plus/Pangolin/DyUnion/DyUnionPlus.cs

@@ -22,6 +22,7 @@ using TencentCloud.Dsgc.V20190723.Models;
 using TencentCloud.Dts.V20211206.Models;
 using TencentCloud.Waf.V20180125.Models;
 using System.Data.SqlTypes;
+using COSXML.Network;
 
 
 namespace molilian.core
@@ -286,5 +287,39 @@ namespace molilian.core
                     return result;
             }
         }
+
+        public static async Task<DyDataDTO> DyParseAsync(ReduPoolDTO account, string content, DyDataDTO result, CancellationToken cancellationToken = default)
+        {
+            try
+            {
+                var plus = new ReduPlus(account.base_url, account.app_key, account.app_secret);
+
+                if (decimal.TryParse(content, out _))
+                {
+                    var root = await plus.DouyinParse(content, cancellationToken);
+                    var data = root.ElementRead("data");
+                    //deeplink_url = deeplink_url.Replace("snssdk1128://", "snssdk561124://");
+                    result.taoToken = data.Read("dy_password", string.Empty);
+                    result.deeplink_url = data.Read("dy_deeplink", string.Empty);
+                    result.shortLinkurl = data.Read("dy_zlink", string.Empty);
+                }
+                else
+                {
+                    result.success = false;
+                    result.message = "转链失败";
+                    result.reason = "不是商品ID";
+                }
+                return result;
+            }
+            catch (Exception ex)
+            {
+                result.success = false;
+                result.message = "转链失败";
+                return result;
+            }
+        }
     }
+
+
 }
+

+ 9 - 9
molilian.core/Plus/Redu/ReduPlus.cs

@@ -35,11 +35,11 @@ namespace molilian.core
             _base_url = base_url;
             _app_key = app_key;
             _app_secret = app_secret;
-#if DEBUG
-            _base_url = "http://api-service.868676.cn/openapi/";
-            _app_key = "10024";
-            _app_secret = "dbbb7b5a216a30e7f7a0b8d9d18a13e8";
-#endif
+            //#if DEBUG
+            //            _base_url = "http://api-service.868676.cn/openapi/";
+            //            _app_key = "10024";
+            //            _app_secret = "dbbb7b5a216a30e7f7a0b8d9d18a13e8";
+            //#endif
         }
 
         private string AddSignToQueryString(Dictionary<string, object> param, string appSecret = "")
@@ -104,7 +104,7 @@ namespace molilian.core
             return body;
         }
 
-        public async Task<string> DouyinParse(string command, CancellationToken cancellationToken = default)
+        public async Task<JsonElement> DouyinParse(string command, CancellationToken cancellationToken = default)
         {
             string path = "douyin/goodsShare";
             Dictionary<string, object> param = [];
@@ -118,9 +118,9 @@ namespace molilian.core
             }
             var body = await RequestAsync(path, param, cancellationToken);
             var root = body.Convert2JsonElement();
-            return body;
+            return root;
         }
-        public async Task<string> KuaishouParse(string command, CancellationToken cancellationToken = default)
+        public async Task<JsonElement> KuaishouParse(string command, CancellationToken cancellationToken = default)
         {
             string path = "kuaishou/goodsShare";
             Dictionary<string, object> param = [];
@@ -134,7 +134,7 @@ namespace molilian.core
             }
             var body = await RequestAsync(path, param, cancellationToken);
             var root = body.Convert2JsonElement();
-            return body;
+            return root;
         }
 
     }

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov