Kaynağa Gözat

京东转链work_mode 增加4ddx(临时)

dodo hold 1 yıl önce
ebeveyn
işleme
a04f6e5bf3

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

@@ -13,6 +13,7 @@ using System.Threading;
 using TencentCloud.Batch.V20170312.Models;
 using Org.BouncyCastle.Bcpg.OpenPgp;
 using Microsoft.VisualBasic;
+using static System.Runtime.InteropServices.JavaScript.JSType;
 
 namespace molilian.api.Controllers
 {
@@ -38,6 +39,37 @@ namespace molilian.api.Controllers
             return new APIResult(new { success = true, count });
         }
 
+        [HttpGet]
+        public async Task<ActionResult> testReloadPushReortData()
+        {
+            PushDataReportCore core = new();
+            DateTime sdate = DateTime.Parse("2025-01-01");
+            DateTime edate = DateTime.Parse("2025-03-24");
+            int count = 0;
+            while (sdate < edate)
+            {
+                count += await core.FillParseData(sdate.Date);
+                sdate = sdate.AddDays(1);
+            }
+            return new APIResult(new { success = true, count });
+        }
+        [HttpGet]
+        public async Task<ActionResult> testPushReportData()
+        {
+            PushDataReportCore core = new();
+            DateTime sdate = DateTime.Parse("2025-01-01");
+            DateTime edate = DateTime.Parse("2025-03-24");
+            int count = 0;
+            while (sdate < edate)
+            {
+
+                count += await core.PushReportData(sdate, true);
+                sdate = sdate.AddDays(1);
+            }
+
+            return new APIResult(new { success = true, count });
+        }
+
 
         [HttpGet]
         public async Task<ActionResult> PushReportData(int repush = 0, DateTime date = default)

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 4 - 1
molilian.core/Core/PushDataReport/PushDataReportCore.cs

@@ -263,6 +263,9 @@ namespace molilian.core
         public async Task<int> PushReportData(DateTime report_date, bool repush = false, CancellationToken cancellationToken = default)
         {
             string filter = "report_date=@report_date";
+#if DEBUG
+            filter += " AND sub_type=100000 AND platform IN (1,9,13)";
+#endif
             if (!repush)
             {
                 filter += " AND status=@status";
@@ -288,7 +291,7 @@ namespace molilian.core
                 new DBContext.Table("push_data_report")
                     .Add("status", status)
                     .Add("request_id", item.request_id)
-                    .Add("update_time", DateTime.Now)
+                    .Add("last_push_time", DateTime.Now)
                     .Where("id=@id", new { item.id })
                     .Update();
             }

+ 0 - 6
molilian.core/Core/PushDataReport/PushDataReportPush.cs

@@ -23,16 +23,10 @@ namespace molilian.core
         private string _app_secret = "fHTPd7RK7OnpIv7zGvPgL2Wv8P3pDYfW";
         public PushDataReportPush()
         {
-#if DEBUG
-            _url = "http://adx-ads-test.wanyol.com";
-#endif
         }
 
         public PushDataReportPush(string url, string app_key, string app_secret)
         {
-#if DEBUG
-            _url = "http://adx-ads-test.wanyol.com";
-#endif
             _url = url;
             _app_key = app_key;
             _app_secret = app_secret;

+ 4 - 1
molilian.core/Core/jd/JdPoolCore.cs

@@ -70,7 +70,7 @@ namespace molilian.core
             return eligibleItems.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
         }
 
-        public static async Task<JdPoolDTO?> GetOneAsync(JdAction action)
+        public static async Task<JdPoolDTO?> GetOneAsync(JdAction action, bool? is_numeric)
         {
             var list = await ListAsync();
             if (!list.Any()) return null;
@@ -80,6 +80,9 @@ namespace molilian.core
             {
                 if (await IsNotExceedDailyIncomeLimitAsync(item, action))
                 {
+                    // 如果 is_numeric 为 true,则排除 work_mode = Ddx (4) 的记录
+                    if (is_numeric == true && item.work_mode == JdUnionWorkMode.Ddx)
+                        continue;
                     eligibleItems.Add(item);
                 }
             }

+ 28 - 8
molilian.core/Core/taoke/TkPoolCore.cs

@@ -54,6 +54,16 @@ namespace molilian.core
             if (!list.Any())
                 return null;
 
+#if DEBUG
+            list = list.Where(e => e.id != 50).ToList();
+
+
+#endif
+            // 获取所有账号(包括离线账号)
+            var allAccounts = await AllListAsync().ConfigureAwait(false);
+            if (allAccounts == null)
+                allAccounts = list; // 如果获取失败,至少使用在线账号列表
+
             if ("brw".Equals(riskStrategy))
             {
                 list = list.Where(item => "brw".Equals(item.riskStrategy)).ToList();
@@ -65,24 +75,34 @@ namespace molilian.core
                 if (!list.Any()) return null;
             }
 
+
             var filteredList = new List<TkPoolDTO>();
             foreach (var item in list)
             {
-                // 检查是否有账号关联了当前账号
-                var ownerAccount = list.FirstOrDefault(other =>
+                // 在所有账号中检查是否有账号关联了当前账号
+                var ownerAccount = allAccounts.FirstOrDefault(other =>
                     other.id != item.id &&
                     !string.IsNullOrEmpty(other.related_account_ids) &&
                     other.related_account_ids.Split(',').Contains(item.id.ToString()));
 
-                // 如果没有账号关联它,或者关联它的账号在线,则可以使用
+                // 如果没有账号关联它,或者关联它的账号在线(在list中),则可以使用
                 if (ownerAccount == null || list.Any(a => a.id == ownerAccount.id))
                 {
-                    // 如果收单账号不在线,跳过这个关联账号
-                    if (!list.Any(a => a.id == ownerAccount.id))
-                        continue;
+                    filteredList.Add(item);
                 }
-                
-                // 如果不是关联账号,或者收单账号在线,则可以使用
+            }
+
+            foreach (var item in list)
+            {
+                // 在所有账号中检查是否有账号关联了当前账号
+                var ownerAccount = allAccounts.FirstOrDefault(other =>
+                    other.id != item.id &&
+                    !string.IsNullOrEmpty(other.related_account_ids) &&
+                    other.related_account_ids.Split(',').Contains(item.id.ToString()));
+
+                // 如果没有账号关联它,或者关联它的账号在线(在list中),则可以使用
+                if (ownerAccount == null || list.Any(a => a.id == ownerAccount.id))
+                {
                     filteredList.Add(item);
                 }
             }

+ 10 - 2
molilian.core/Core/taoke/UnionParseCore.cs

@@ -513,11 +513,13 @@ namespace molilian.core
                         return JdParseOutput(result);
                     }
                 }
+                string out_url = null;
+                string itemId = null;
 
                 //============================== 放弃转链-地区过滤 ==============================
                 if (!result.ip.StartsWith("127.0.0") && accountid == 0 && JdUnionPlus.ShouldIgnoreRequest(config, ip, oaid, out string reason))
                 {
-                    result.link_type = JdUnionPlus.GetLinkType(result.shortLinkurl, out string out_url, out string itemId);
+                    result.link_type = JdUnionPlus.GetLinkType(result.shortLinkurl, out out_url, out itemId);
 
                     result.deeplink_url = result.link_type switch
                     {
@@ -565,7 +567,13 @@ namespace molilian.core
                 //                    return JdParseOutput(result);
                 //                }
 
-                var account = accountid > 0 ? await JdPoolCore.GetOneAsync(accountid, JdPoolCore.JdAction.parse) : await JdPoolCore.GetOneAsync(JdPoolCore.JdAction.parse);
+                result.shortLinkurl = JdUnionPlus.GetLink(content);
+                result.content = result.shortLinkurl;
+                result.link_type = JdUnionPlus.GetLinkType(result.shortLinkurl, out out_url, out itemId);
+
+                bool is_numeric = result.shortLinkurl.Contains(itemId);
+
+                var account = accountid > 0 ? await JdPoolCore.GetOneAsync(accountid, JdPoolCore.JdAction.parse) : await JdPoolCore.GetOneAsync(JdPoolCore.JdAction.parse, is_numeric);
                 if (account == null)
                 {
                     result.success = false;

+ 8 - 0
molilian.core/DTO/jd/JdPoolDTO.cs

@@ -5,6 +5,7 @@
         SiteApi = 1,
         AffApi = 2,
         Crawler = 3,
+        Ddx = 4, //临时加的 0529
 
     }
     public class JdPoolDTO
@@ -51,5 +52,12 @@
         public bool is_hide { get; set; } = false;
         public bool enable_call_stats { get; set; } = true;
 
+        public bool other_api_enabled { get; set; } = false;
+        public string other_api_platform_id { get; set; } = string.Empty;
+        public string other_api_key { get; set; } = string.Empty;
+        public bool other_api_non_numeric_required { get; set; } = true;
+
+
+
     }
 }

+ 4 - 0
molilian.core/Plus/JDUnion/JdUnionPlus.cs

@@ -313,6 +313,7 @@ namespace molilian.core
             string shortLinkurl = url;
 
             //result.link_type = plus.IsAffLlink(url) ? LinkTypeEnum.other_aff : LinkTypeEnum.goods;
+            result.shortLinkurl = url;
             result.link_type = GetLinkType(url, out string out_url, out string itemId);
             url = out_url;
             result.itemId = itemId;
@@ -418,6 +419,9 @@ namespace molilian.core
                 case JdUnionWorkMode.AffApi:
                     result = await GetPromotionByAffAsync(result, url, clickId, cancellationToken);
                     break;
+                case JdUnionWorkMode.Ddx:
+                    result = await GetPromotionByDdxAsync(result, url, clickId, cancellationToken);
+                    break;
                 case JdUnionWorkMode.Crawler:
                 default:
                     result = await GetPromotionByCrawlerAsync(result, url, clickId, cancellationToken);

+ 41 - 17
molilian.core/Plus/JDUnion/goods.cs

@@ -142,6 +142,45 @@ namespace molilian.core
             _ = new LoggerLibrary("JdUnion", "bysubunionid_get_error").Info(body).SaveAsync();
             return result;
         }
+        public async Task<JdDataDTO> GetPromotionByDdxAsync(JdDataDTO result, string wareUrl, string clickId, CancellationToken cancellationToken = default)
+        {
+            string url = $"http://api.tbk.dingdanxia.com/jd/url_privilege?apikey={_account.app_key}&unionId={_account.unionid}&materialId={result.shortLinkurl.UrlDecode()}";
+
+            WebClientUtility client = new WebClientUtility();
+            var response = await client.RequestAsync(url, "GET", cancellationToken);
+
+            string body = response.Body();
+            var root = body.Convert2JsonElement();
+            int code = root.Read<int>("code");
+            string message = root.Read<string>("msg");
+            string shortURL = root.PathRead<string>("data.shortURL");
+
+            if (code == 200)
+            {
+                result.success = true;
+                result.message = "OK";
+                result.shortLinkurl = shortURL;
+                result.content = result.shortLinkurl;
+                result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
+            }
+            else
+            {
+                if (string.IsNullOrEmpty(body)) message = "网络异常";
+                if (body.Contains("数据返回失败【(sceneId未入参)或(sceneId和商品格式不匹配)"))
+                {
+                    message = "不支持数字ID";
+                }
+
+                result.success = false;
+                result.message = "转链失败";
+                result.reason = message;
+                result.shortLinkurl = wareUrl;
+                result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
+                _ = new LoggerLibrary("JdUnion", "GetPromotionByDdxAsync").Info(body).SaveAsync();
+            }
+            return result;
+        }
+
         public async Task<JdDataDTO> GetPromotionByCrawlerAsync(JdDataDTO result, string wareUrl, string clickId, CancellationToken cancellationToken = default)
         {
             string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None);
@@ -204,7 +243,7 @@ namespace molilian.core
                 result.message = "转链失败";
                 result.reason = "签名失败";
                 result.shortLinkurl = wareUrl;
-                result.deeplink_url =  (result.shortLinkurl);
+                result.deeplink_url = (result.shortLinkurl);
                 return result;
             }
 
@@ -222,22 +261,7 @@ namespace molilian.core
             client.AddHeaders("Cookie", cookies);
             client.Post($"body={data}");
             var response = await client.RequestAsync(url, "GET", cancellationToken);
-
-
-            https://api.m.jd.com/api?functionId=unionPromoteLinkService&appid=unionpc&_=1734447407687&loginType=3&uuid=1734444378650448359604&x-api-eid-token=jdd03YJZYUINYGLWQKYT2SFR5PF5CNZ5PK5SQB3SOWOR5DHKS62647SPYBXWBMLYF7YEFH7RDZG22SM77HWYSFKYKTZJICUAAAAMT2TYOUQQAAAAADOZREVGL2Z3VVEX&h5st=20241217225647690;ff8lvy5fkzklklr1;586ae;tk03wb3c71ba318nQZgEdIpw3aqKhQNr_DOL4ffKT_bx3botkXGLthFRyT-TL0p502UEdMny0L0mZSLWUXs6264cdk-I;45b11a32199c9d0e995efe3339eff00f;4.9;1734447407690;pjbMhjZf561R-_FNASVeySkQzTFSJrJdJrESJrpjh7Je6rJdJz1TIipjLDrgJf4f5n1e7XldHe4e6TIS1f1f7rITHeof0b1TFeVf6nVSJrJdJrEa-OFTGOEjLrJp-jpe7PYSHKYeIWlf1roeJaleJq4e2XYd3fVS5X1ezHIS4jpjxj5PKSEQKeFjLrJp-j5e9HIg3T0UG6VRFuWeDipjxjJOJrpjh7JjSOUbA_nOyroNneWbJrJdJ31QHyVT5ipjLDrgJj4f9G1WJrJdJTlPJrpjh7ZMLrJp7rJdJLYOJipjLrpjh7JjJrJdJPYOJipjLrpjh7Je6rJdJTYOJipjLrpjh7pfLDIj2XETJrpjLrJp-rojxjpe2iFjLrpjLDrgzjYfLDIj4XETJrpjLrJp-jYgLDIj5XETJrpjLrJp-jZe9nIg7jpjxjZf2iFjLrpjLDrg7rJdJ-1OJrpjLrJp-Xojxj5P-ipjLrpjh7pfLDIj-ipjLrpjh7pfLDIjHOEjLrpjLD7NLDIjHyVS3KUSJrpjh7ZMLrJpJrUO3ekQJrJdJjoPJrpjLrJpwqJdJrkPJrpjh7Jj3ToNL-oe1zVRUq5d7zpf6rpWdq5P0ulS9G1WJrJdJnVO4ipjLD7N;76beaa50fd5fe694a2824d4dbde781c0
-
-
-            //if (response.ResponseMessage.StatusCode == HttpStatusCode.Forbidden)
-            //{
-            //    result.success = false;
-            //    result.message = "转链失败";
-            //    result.reason = "nologin";
-            //    result.shortLinkurl = wareUrl;
-            //    result.deeplink_url = GetDeeplink(result.shortLinkurl);
-            //    return result;  
-            //}
-
-
+ 
             string body = response.Body();
             var root = body.Convert2JsonElement();
             int code = root.Read<int>("code");

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor