Browse Source

爬订单时候同步获取淘宝数字id;
调整转链接口失败的message和reason;

dodo hold 2 years ago
parent
commit
cd366d02c5

+ 2 - 0
molilian.api/Controllers/public/TkController.cs

@@ -491,6 +491,8 @@ namespace molilian.api.Controllers
                 result.success,
                 result.message,
                 result.shortLinkurl,
+                result.itemId,
+                result.itemName,
                 result.deeplink_url,
             });
         }

File diff suppressed because it is too large
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 1 - 1
molilian.core/Core/taoke/DataokeCore.cs

@@ -127,7 +127,7 @@ namespace molilian.core
                 result.accountName = account.name;
 
                 GoodsDetailDTO goods = null;
-                //if (success) goods = plus.GetGoods(shortLinkurl);
+                if (success) goods = plus.GetGoods(shortLinkurl);
                 result.deeplink_url = JdUnionPlus.GetDeeplink(shortLinkurl);
 
                 if (goods != null)

+ 14 - 5
molilian.core/Core/taoke/OrderTrackingCore.cs

@@ -49,16 +49,25 @@ namespace molilian.core
             RedisHelper.Set(cacheKey, newData, ttl);
         }
 
-        public static TkDataDTO GetLinkSummary(int accountId, string name)
+        public static TkDataDTO GetLinkSummary(int accountId, string itemId, string itemTitle)
         {
-            string cacheKey = $":cache:order_summary:{accountId}:{name}";
             var result = EndPointCore.ProcessEndPointNodes<TkDataDTO>(node =>
             {
                 if (!node.is_public_api) return null;
 
                 var redis = RedisClientManager.GetRedisClient(node.redis_server);
-                var result = redis.Get<TkDataDTO>(cacheKey);
-                if (result != null) return result;
+                if (!string.IsNullOrEmpty(itemId))
+                {
+                    string cacheKey = $":cache:order_summary:{accountId}:{itemId}";
+                    var result = redis.Get<TkDataDTO>(cacheKey);
+                    if (result != null) return result;
+                }
+                if (!string.IsNullOrEmpty(itemId))
+                {
+                    string cacheKey = $":cache:order_summary:{accountId}:{itemTitle}";
+                    var result = redis.Get<TkDataDTO>(cacheKey);
+                    if (result != null) return result;
+                }
                 return null;
             });
             return result.Count > 0 ? result[0] : null;
@@ -81,7 +90,7 @@ namespace molilian.core
         {
             if (item.tbPaidTime < DateTime.Now.AddDays(-1)) return false;
 
-            var summary = GetLinkSummary(item.accountId, item.itemTitle);
+            var summary = GetLinkSummary(item.accountId, item.itemId, item.itemTitle);
             if (summary == null) return false;
 
 

+ 5 - 4
molilian.core/Core/taoke/TkLogCore.cs

@@ -54,7 +54,7 @@ namespace molilian.core
                 {
                     var data = redis.LPop<TkDataDTO>(queue_tb_key);
                     if (data == null) break;
-                    if ("127.0.0.1".Equals(data.ip))
+                    if ("127.0.0.1".Equals(data.ip) || data.elapsedTime > 2000)
                     {
                         new DBContext.Table(connection, "tk_logs_test")
                             .Add("end_point", data.end_point)
@@ -173,7 +173,7 @@ namespace molilian.core
                     var data = redis.LPop<TkDataDTO>(queue_parse_tb_key);
                     if (data == null) break;
 
-                    if ("127.0.0.1".Equals(data.ip))
+                    if ("127.0.0.1".Equals(data.ip) || data.elapsedTime > 2000)
                     {
                         new DBContext.Table(connection, "tk_parse_logs_test")
                             .Add("end_point", data.end_point)
@@ -696,14 +696,15 @@ namespace molilian.core
             {
                 if (!node.is_public_api) return 0;
 #if DEBUG
-                switch (node.name) {
+                switch (node.name)
+                {
 
                     case "bj":
                         node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
                         break;
                     case "gz":
                         node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
-                        break; 
+                        break;
                 }
 #endif
                 var redis = RedisClientManager.GetRedisClient(node.redis_server);

+ 165 - 0
molilian.core/Core/taoke/UnionParseCore.cs

@@ -142,6 +142,171 @@ namespace molilian.core
             swData.Add("StartNew", 0);
             Stopwatch stopwatch = Stopwatch.StartNew();
 
+            result.rawContent = content;
+            try
+            {
+                string reason = string.Empty;
+                //============================== 放弃转链-地区过滤 ==============================
+                bool is_ignore2 = AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out reason);
+
+                if (is_ignore2)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.itemName = "点击打开淘宝APP";
+                    result.reason = reason;
+                    _ = TkLogCore.ParseLogAsync(result);
+                    return TaobaoParseOutput(result, swData, new
+                    {
+                        result.success,
+                        result.message,
+                        result.content,
+                        result.itemName,
+                        result.deeplink_url,
+                    });
+                }
+
+
+                //============================== 放弃转链-初步筛选 ==============================
+                bool is_ignore = AlimamaPlus.FirstFilterIgnoreRequest(content, out reason);
+
+                if (string.IsNullOrEmpty(result.shortLinkurl) && is_ignore)
+                {
+                    //没有短链接都放弃
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.itemName = "点击打开淘宝APP";
+                    result.reason = "初步筛选";
+                    _ = TkLogCore.ParseLogAsync(result);
+                    return TaobaoParseOutput(result, swData, new
+                    {
+                        result.success,
+                        result.message,
+                        result.content,
+                        result.itemName,
+                        result.deeplink_url,
+                    });
+                }
+
+                //============================== 放弃转链-没有匹配账号 ==============================
+                TkPoolDTO? account = accountid > 0 ?
+                    TkPoolCore.GetOne(accountid) :
+                    TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
+                if (account == null)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "没有匹配账号";
+                    result.itemName = "点击打开淘宝APP";
+                    _ = TkLogCore.ParseLogAsync(result);
+                    return TaobaoParseOutput(result, swData, new
+                    {
+                        result.success,
+                        result.message,
+                        result.content,
+                        result.couponAmount,
+                        result.taoToken,
+                        result.shortLinkurl,
+                        result.deeplink_url,
+                    });
+                }
+                result.accountId = account.id;
+
+                alimama = new AlimamaPlus(account);
+                result.accountName = account.company;
+
+
+                int timeout = alimama._config.rt_max;
+                using var cts = new CancellationTokenSource();
+                cts.CancelAfter(timeout);
+
+
+                var requestTask = Task.Run(() => alimama.UnionParse2Async(content, result, cts.Token, swData), cts.Token);
+                var delayTask = Task.Delay(timeout, cts.Token);
+                var completedTask = await Task.WhenAny(requestTask, delayTask);
+                if (completedTask == requestTask)
+                {
+                    result = await requestTask;
+                }
+                else
+                {
+                    //============================== 放弃转链-请求超时 ==============================
+                    cts.Cancel();
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "请求超时";
+                    result.itemName = "点击打开淘宝APP";
+                }
+
+                result.accountName = account.company;
+                //result = await alimama.UnionParse2Async(content, result);
+            }
+            catch (Exception ex)
+            {
+                //============================== 放弃转链-请求超时 ==============================
+                if (ex.Message.Contains("was canceled"))
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "请求超时";
+                    result.itemName = "点击打开淘宝APP";
+                }
+                else
+                {
+                    //============================== 转链接口异常 ==============================
+                    _ = new LoggerLibrary("unionParse", "tb_error")
+                        .Info(ip, oaid)
+                        .Info(content)
+                        .Info(ex.Message, ex.StackTrace)
+                        .SaveAsync();
+
+                    NotifyCore.Notify(new NifyMessage
+                    {
+                        message = $"【转链异常TB】\n{content}\n\n{ex.Message}\n{ex.StackTrace}",
+                        priority = NifyMessagePriority.high,
+                        tags = ["red_circle"]
+                    });
+                    result.success = false;
+                    result.message = "转链接口异常";
+                    result.itemName = "点击打开淘宝APP";
+                }
+            }
+            _ = TkLogCore.ParseLogAsync(result, alimama);
+
+            return TaobaoParseOutput(result, swData, new
+            {
+                result.success,
+                result.message,
+                link_type = result.link_type.ToString(),
+                channel = result?.channel.ToString(),
+                result.channel_type,
+                result.itemId,
+                result.itemName,
+                result.pic,
+                result.promotionPrice,
+                result.couponAmount,
+                result.couponEffectiveStartTime,
+                result?.couponEffectiveEndTime,
+                result.shortLinkurl,
+                result.deeplink_url,
+                result.content,
+                result.taoToken,
+            });
+        }
+
+        public static async Task<APIResult> TaobaoParseAsync11(string content,
+            string ip = "", string oaid = "",
+            int accountid = 0)
+        {
+            AlimamaPlus alimama = null;
+            content = content.UrlDecode();
+            content = content[..Math.Min(1000, content.Length)];
+            var result = AlimamaPlus.GetFormattedObject(content, ip, oaid);
+
+            Dictionary<string, long> swData = new();
+            swData.Add("StartNew", 0);
+            Stopwatch stopwatch = Stopwatch.StartNew();
+
             result.rawContent = content;
             try
             {

+ 25 - 14
molilian.core/Plus/Alimama/crawler.cs

@@ -132,12 +132,20 @@ namespace molilian.core
                 createArgs2.Where("id=@id", new { exist2.id }).Update();
             }
 
+            /*
 
-            string sql = @$"
-INSERT INTO daily_logs (channel, accountId, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time)
+		-- 定义变量用于日期间隔
+SET @interval_days = 4;
+
+-- 汇总所有账户的数据
+INSERT INTO daily_logs (
+    channel, accountId, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time
+)
 SELECT
-    0 AS channel, 0 AS accountId, 'all' AS accountName,
-    DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY) AS log_date,
+    0 AS channel,
+    0 AS accountId,
+    'all' AS accountName,
+    DATE_SUB(CURDATE(), INTERVAL @interval_days DAY) AS log_date,
     COUNT(*) AS total_count,
     COALESCE(SUM(CASE WHEN message = '放弃转链' THEN 1 ELSE 0 END), 0) AS abandon_count,
     COALESCE(CONCAT(ROUND((SUM(CASE WHEN message = '放弃转链' THEN 1 ELSE 0 END) / COUNT(*)) * 100, 2), '%'), 0) AS abandon_percentage,
@@ -146,21 +154,25 @@ SELECT
     NOW() AS create_time,
     NOW() AS last_time
 FROM tk_logs
-WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY)
+WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL @interval_days DAY)
+  AND create_time < DATE_SUB(CURDATE(), INTERVAL @interval_days - 1 DAY)
 ON DUPLICATE KEY UPDATE
-    log_date = VALUES(log_date),
     total_count = VALUES(total_count),
     abandon_count = VALUES(abandon_count),
     abandon_percentage = VALUES(abandon_percentage),
     success_count = VALUES(success_count),
     success_percentage = VALUES(success_percentage),
     last_time = NOW();
-";
 
-            string sql2 = @$"
-INSERT INTO daily_logs (channel, accountId, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time)
+-- 按渠道、账户分组的数据
+INSERT INTO daily_logs (
+    channel, accountId, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time
+)
 SELECT
-    channel, accountId, accountName, DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY) AS log_date,
+    channel,
+    accountId,
+    accountName,
+    DATE_SUB(CURDATE(), INTERVAL @interval_days DAY) AS log_date,
     COUNT(*) AS total_count,
     COALESCE(SUM(CASE WHEN message = '放弃转链' THEN 1 ELSE 0 END), 0) AS abandon_count,
     COALESCE(CONCAT(ROUND((SUM(CASE WHEN message = '放弃转链' THEN 1 ELSE 0 END) / COUNT(*)) * 100, 2), '%'), 0) AS abandon_percentage,
@@ -169,18 +181,17 @@ SELECT
     NOW() AS create_time,
     NOW() AS last_time
 FROM tk_logs
-WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY)
+WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL @interval_days DAY)
+  AND create_time < DATE_SUB(CURDATE(), INTERVAL @interval_days - 1 DAY)
 GROUP BY channel, accountId, accountName
 ON DUPLICATE KEY UPDATE
-    log_date = VALUES(log_date),
     total_count = VALUES(total_count),
     abandon_count = VALUES(abandon_count),
     abandon_percentage = VALUES(abandon_percentage),
     success_count = VALUES(success_count),
     success_percentage = VALUES(success_percentage),
     last_time = NOW();
-";
-
+             */
             //DBContext.Execute(sql, new { });
             //DBContext.Execute(sql2, new { });
         }

+ 37 - 35
molilian.core/Plus/Alimama/orders.cs

@@ -2,6 +2,7 @@
 using Spire.Pdf.Xmp;
 using System.Data;
 using System.Drawing.Printing;
+using System.Runtime.InteropServices;
 using System.Text.Json;
 using System.Text.RegularExpressions;
 
@@ -216,6 +217,7 @@ SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_tfee_14 = sub.order_or
                     {
                         TkOrderDetailDTO item = order.GetRawText().Convert2Object<TkOrderDetailDTO>();
                         // 处理每个订单数据 
+
                         item.accountId = _accountId;
                         item.accountName = _company;
 
@@ -226,8 +228,7 @@ SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_tfee_14 = sub.order_or
                             return (total, max_modifiedTime, orderTimes);
                         }
                         //进行订单和转链匹配
-                        //string mktItemLink = $"https:{item.mktItemLink}";
-                        //item.itemId = GetRawItemId(mktItemLink);
+                        item.itemId = GetRawItemId(item.mktId);
                         if (item.tkStatus == 3 && item.tbPaidTime != DateTime.MinValue) orderTimes.Add(item.tbPaidTime.Date);
                         int? id = conn.Replace(item);
                         if (id != null)
@@ -256,56 +257,57 @@ SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_tfee_14 = sub.order_or
         }
 
 
-        string GetRawItemId(string url)
+        string GetRawItemId(string mktId)
         {
             try
             {
 
-                string cacheKey = $":cache:url2itemId:{url}";
+                string cacheKey = $":cache:mkt2itemId:{mktId}";
 
                 string itemId = RedisHelper.Get(cacheKey);
                 if (itemId != null) return itemId;
 
-                WebClientUtility client = new()
-                {
-                    Proxy = _proxy,
-                    UserAgent = Sayaka.Common.ProviderFakeUserAgent.RandomComputer
-                };
+
+                var ts = DateTime.Now.Convert2UnixTimestamp(true);
+                string url = "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/union.moose.content.entry";
+
+                //string url = $"{base_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&jumpType={jumpType}&tkTradeId=&positionIndex={positionIndex}";
+
+                var client = new WebClientUtility()
+                    .SetContentType("application/x-www-form-urlencoded")
+                    .AddHeaders("Cookie", _cookies)
+                    .AddHeaders("Origin", "https://pub.alimama.com")
+                    .Post("_tb_token_", _tb_token)
+                    .Post("t", ts.ToString())
+                    .Post("bizType", "detailPage")
+                    .Post("bizParam", $"{{\"itemId\":\"{mktId}\"}}");
+                //_tb_token_=3b88755bbe3f7&t=1718896771391&bizType=detailPage&bizParam=%7B%22itemId%22%3A%22JbtMUqkGMQvagTNb2Fvta-9ag242pu7MOX5e0bsrY%22%7D
+                //_tb_token_=361e383eb61e5&t=1718895935097&bizType=detailPage&bizParam=%7B%22itemId%22%3A%22JbtMUqkGMQvagTNb2Fvta-9ag242pu7MOX5e0bsrY%22%7D
+
+
 #if DEBUG
-                client.Proxy = null;
+#else
+                client.Proxy = _proxy;
 #endif
-                client.AllowAutoRedirect = false;
+                if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
                 var response = client.Request(url);
-                if (response.Successed)
-                {
-                    string location = response.ResponseMessage?.Headers?.Location?.ToString();
-                    if (!string.IsNullOrEmpty(location))
-                    {
-                        itemId = location.GetContentPart("id=", "");
-                        if (!string.IsNullOrEmpty(itemId))
-                        {
-                            RedisHelper.Set(cacheKey, itemId, 86400 * 30);
-                        }
-                        return itemId;
-                    }
-                    var responseBody = response.Body();
-                    if (response.ResponseMessage.IsSuccessStatusCode)
-                    {
-                        throw new APIException(responseBody);
-                    }
-                    else
-                    {
-                        throw new APIException($"{response.ResponseMessage.StatusCode}\t{responseBody}");
-                    }
+                if (!response.Successed)
+                { 
+                    throw response.ResponseException;
                 }
-                else
+
+                var body = response.Body();
+                var root = body.Convert2JsonElement();
+                itemId = root.PathRead<string>("model.item.itemId");
+                if (!string.IsNullOrEmpty(itemId))
                 {
-                    throw response.ResponseException;
+                    RedisHelper.Set(cacheKey, itemId, 86400 * 7);
                 }
+                return itemId;
             }
             catch (Exception ex)
             {
-                string message = $"【GetRawItemId】[{url}\n{ex.Message}\n{ex.StackTrace}";
+                string message = $"【GetRawItemId】[{mktId}\n{ex.Message}\n{ex.StackTrace}";
                 NotifyCore.Notify(new NifyMessage
                 {
                     message = message,

+ 47 - 41
molilian.core/Plus/Alimama/parse.cs

@@ -74,7 +74,8 @@ namespace molilian.core
                 result.channel_type = ChannelTypeEnum.tb;
                 result.link_type = LinkTypeEnum.unknown;
                 result.success = false;
-                result.message = "其他推广链接";
+                result.message = "放弃转链";
+                result.reason = "其他推广链接";
                 result.accountName = string.Empty;
                 result.content = content;
                 result.deeplink_url = GetDeeplink(null);
@@ -96,63 +97,51 @@ namespace molilian.core
             CancellationToken cancellationToken = default,
             Dictionary<string, long> swData = null)
         {
-            Stopwatch stopwatch = Stopwatch.StartNew();
+            result.itemName = "点击打开淘宝APP";
             result = await InternalTextProcessingAsync(content, result, cancellationToken, swData);
-            if (swData != null)
-            {
-                stopwatch.Stop();
-                swData.Add("InternalTextProcessingAsync", stopwatch.ElapsedMilliseconds);
-            }
-
 
-            //(result.success, result.content, result.link_type, result.shortLinkurl) = InternalTextProcessing(content);
             if (result.link_type == LinkTypeEnum.other_aff)
             {
+                //============================== 其他推广链接 ==============================
                 result.channel = TkChannelEnum.tb;
                 result.channel_type = ChannelTypeEnum.tb;
-                result.link_type = LinkTypeEnum.unknown;
+                result.link_type = LinkTypeEnum.other_aff;
                 result.success = false;
-                result.message = "其他推广链接";
+                result.message = "放弃转链";
+                result.reason = "其他推广链接";
                 result.accountName = string.Empty;
                 result.content = content;
                 result.deeplink_url = GetDeeplink(null);
                 //result.itemName = GetTitle(content);
-                result.itemName = "点击打开淘宝APP";
+                return result;
             }
-            else
+
+            //处理过后的正文 用于转链
+            if (!result.success)
             {
-                //处理过后的正文 用于转链
-                if (!result.success)
-                {
-                    result.content = content;
-                    result.itemName = "点击打开淘宝APP";
-                    return result;
-                }
+                return result;
+            }
 
-                if (swData != null)
-                {
-                    stopwatch.Reset();
-                    stopwatch.Start();
-                }
-                result = await alimamaParseAsync(result.content, result, cancellationToken);
+            //============================== 放弃转链-地区过滤 ==============================
+            bool is_ignore2 = FlowControlIgnoreRequest(out string reason);
+            if (is_ignore2)
+            {
+                result.success = false;
+                result.message = "放弃转链";
+                result.reason = reason;
+                return result;
+            }
 
-                if (swData != null)
-                {
-                    stopwatch.Stop();
-                    swData.Add("alimamaParseAsync", stopwatch.ElapsedMilliseconds);
-                }
+            result = await alimamaParseAsync(result.content, result, cancellationToken);
 
-                if (!result.success)
-                {
-                    result.itemName = "点击打开淘宝APP";
-                }
-                //if (string.IsNullOrEmpty(result.itemName)) result.itemName = GetTitle(content);
+            if (!result.success)
+            {
+                result.itemName = "点击打开淘宝APP";
             }
             if (string.IsNullOrEmpty(result.itemName) || result.link_type == LinkTypeEnum.profile)
             {
                 result.itemName = "点击打开淘宝APP";
             }
-            result.link_type = result.link_type;
             return result;
         }
 
@@ -328,20 +317,37 @@ namespace molilian.core
                     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.ignorePercentage;
                 if (ignorePercentage == 0) return false;
+
                 var randomValue = (decimal)_random.Next(0, 100);
                 bool result = randomValue <= ignorePercentage; // 如果生成的随机数小于忽略百分比,则返回 true,表示需要忽略请求
-                if (result) reason = "流量控制";
-                return result;
-
+                if (result)
+                {
+                    reason = "流量控制";
+                    return true;
+                }
             }
             catch (Exception ex)
             {
                 reason = $"配置异常";
-                return true;
             }
+            return false;
         }
 
         public static TkDataDTO GetFormattedObject(string content, string ip, string oaid)

+ 22 - 99
molilian.core/Plus/Alimama/parse_2.cs

@@ -49,7 +49,9 @@ namespace molilian.core
             UnionParse(content, ref result);
         }
 
-        public async Task<TkDataDTO> UnionParse2Async(string content, TkDataDTO result, CancellationToken cancellationToken = default, Dictionary<string, long> swData = null)
+        public async Task<TkDataDTO> UnionParse2Async(string content, TkDataDTO result,
+            CancellationToken cancellationToken = default,
+            Dictionary<string, long> swData = null)
         {
             if ("veapi".Equals(_api) && _api_id > 0)
             {
@@ -81,7 +83,7 @@ namespace molilian.core
         }
 
         /// <summary>
-        /// 是否淘宝链接
+        /// 是否淘宝链接,如果是商品链接就格式化成https://item.taobao.com/item.htm?id=****
         /// </summary>
         /// <param name="url"></param>
         /// <returns></returns>
@@ -399,41 +401,20 @@ namespace molilian.core
             result.link_type = LinkTypeEnum.other_aff;
             result.shortLinkurl = null;
         }
+
         private async Task<TkDataDTO> InternalTextProcessingAsync(string content, TkDataDTO result,
             CancellationToken cancellationToken,
             Dictionary<string, long> swData = null)
         {
-            Stopwatch stopwatch = Stopwatch.StartNew();
-
             bool success;
             string resultText;
             LinkTypeEnum link_type = LinkTypeEnum.unknown;
 
-
-            if (swData != null)
-            {
-                stopwatch.Reset();
-                stopwatch.Start();
-            }
+            //============================== 放弃转链-其他推广链接 ==============================
             string url = GetLink(content);
-            if (swData != null)
-            {
-                stopwatch.Stop();
-                swData.Add("\tGetLink", stopwatch.ElapsedMilliseconds);
-            }
             if (!string.IsNullOrEmpty(url))
             {
-                if (swData != null)
-                {
-                    stopwatch.Reset();
-                    stopwatch.Start();
-                }
                 bool is_aff = IsAffLink(url);
-                if (swData != null)
-                {
-                    stopwatch.Stop();
-                    swData.Add("\t\tGetLink", stopwatch.ElapsedMilliseconds);
-                }
                 if (is_aff)
                 {
                     result.success = false;
@@ -442,22 +423,9 @@ namespace molilian.core
                     result.link_type = LinkTypeEnum.other_aff;
                     result.shortLinkurl = url;
                     return result;
-                    //return (false, "排除淘客链接", LinkTypeEnum.other_aff, url);
                 }
 
-                //直接提取
-
-                if (swData != null)
-                {
-                    stopwatch.Reset();
-                    stopwatch.Start();
-                }
                 (success, resultText) = IsTaobaoUrl(url);
-                if (swData != null)
-                {
-                    stopwatch.Stop();
-                    swData.Add("\tIsTaobaoUrl", stopwatch.ElapsedMilliseconds);
-                }
                 if (success)
                 {
                     result.success = true;
@@ -465,7 +433,6 @@ namespace molilian.core
                     result.link_type = LinkTypeEnum.goods;
                     result.shortLinkurl = resultText;
                     return result;
-                    //return (true, result, LinkTypeEnum.goods, result);
                 }
 
                 Stopwatch sw = Stopwatch.StartNew();
@@ -473,39 +440,23 @@ namespace molilian.core
                 sw.Stop();
                 // 获取执行时间
                 result.elapsedTime2 = (int)sw.ElapsedMilliseconds;
-                if (swData != null)
-                {
-                    swData.Add("\tGetDesiredUrlAsync", sw.ElapsedMilliseconds);
-                }
-
+                swData?.Add("\tGetDesiredUrlAsync", sw.ElapsedMilliseconds);
 
+                //============================== 放弃转链-请求超时 ==============================
                 if (result.elapsedTime2 >= _config.rt_max || (!success && resultText.Contains("was canceled")))
                 {
                     result.success = false;
                     result.message = "放弃转链";
                     result.reason = "请求超时";
-                    result.itemName = "点击打开淘宝APP";
                     return result;
-                    //cancellationToken.ThrowIfCancellationRequested();
                 }
 
-
                 if (success)
                 {
-                    //排除已知的淘客链接
-
-                    if (swData != null)
-                    {
-                        stopwatch.Reset();
-                        stopwatch.Start();
-                    }
-                    bool is_aff2 = IsAffLink(resultText);
-                    if (swData != null)
-                    {
-                        stopwatch.Stop();
-                        swData.Add("\t\tIsAffLink", stopwatch.ElapsedMilliseconds);
-                    }
+                    string desiredUrl = resultText;
 
+                    //============================== 放弃转链-其他推广链接 ==============================
+                    bool is_aff2 = IsAffLink(desiredUrl);
                     if (is_aff2)
                     {
                         result.success = false;
@@ -514,64 +465,39 @@ namespace molilian.core
                         result.link_type = LinkTypeEnum.other_aff;
                         result.shortLinkurl = url;
                         return result;
-                        //return (false, "排除淘客链接", LinkTypeEnum.other_aff, url);
                     }
 
-                    if (swData != null)
-                    {
-                        stopwatch.Reset();
-                        stopwatch.Start();
-                    }
-                    (success, resultText) = IsTaobaoUrl(resultText);
-                    if (swData != null)
-                    {
-                        stopwatch.Stop();
-                        swData.Add("\t\tIsTaobaoUrl", stopwatch.ElapsedMilliseconds);
-                    }
+                    (success, desiredUrl) = IsTaobaoUrl(desiredUrl);
                     if (success)
                     {
                         result.success = true;
-                        result.content = resultText;
+                        result.content = desiredUrl;
                         result.link_type = LinkTypeEnum.goods;
-                        result.shortLinkurl = resultText;
+                        result.shortLinkurl = desiredUrl;
                         return result;
-                        //return (true, resultText, LinkTypeEnum.goods, resultText);
                     }
-                    link_type = GetLinkType(resultText);
                 }
-                else
-                {
-                    link_type = GetLinkType(url);
 
-                }
+                link_type = GetLinkType(url);
 
                 result.success = false;
-                result.message= "非标准链接";
+                result.message = "放弃转链";
+                result.reason = "非标准链接";
                 result.content = resultText;
                 result.link_type = link_type;
                 result.shortLinkurl = url;
-
                 return result;
                 //return (false, result, link_type, url);
             }
 
 
-            if (swData != null)
-            {
-                stopwatch.Reset();
-                stopwatch.Start();
-            }
-            bool is_aff3 = ContainsSpecialFormat(content);
-            if (swData != null)
-            {
-                stopwatch.Stop();
-                swData.Add("\tContainsSpecialFormat", stopwatch.ElapsedMilliseconds);
-            }
             //判断淘客的¥羊角符号
+            bool is_aff3 = ContainsSpecialFormat(content);
             if (is_aff3)
             {
                 result.success = false;
-                result.content = "排除淘口令";
+                result.message = "放弃转链";
+                result.reason = "排除淘口令";
                 result.link_type = LinkTypeEnum.other_aff;
                 result.shortLinkurl = null;
                 return result;
@@ -581,7 +507,8 @@ namespace molilian.core
             //todo 临时应急  0614
             //return (false, "纯口令 没链接", link_type, null);
             result.success = false;
-            result.content = "纯口令 没链接";
+            result.message = "放弃转链";
+            result.reason = "纯口令 没链接";
             result.link_type = LinkTypeEnum.other_aff;
             result.shortLinkurl = null;
             return result;
@@ -697,8 +624,6 @@ namespace molilian.core
                 if (!response.Successed)
                 {
                     result.channel = TkChannelEnum.tb;
-                    result.accountId = _accountId;
-                    result.accountName = _accountName;
                     result.link_type = LinkTypeEnum.unknown;
                     result.success = false;
                     result.message = "fail";
@@ -815,8 +740,6 @@ namespace molilian.core
                 string deeplink_url = GetDeeplink(shortLinkurl);
 
                 result.channel = TkChannelEnum.tb;
-                result.accountId = _accountId;
-                result.accountName = _accountName;
                 result.link_type = success ? LinkTypeEnum.goods : result.link_type;
                 result.success = success;
                 result.message = message;

Some files were not shown because too many files changed in this diff