dodo hold há 2 anos atrás
pai
commit
b22f3c08af

+ 40 - 4
molilian.api/Controllers/public/TaskController.cs

@@ -144,6 +144,40 @@ namespace molilian.api.Controllers
         }
 
 
+
+        [HttpGet]
+        public async Task<ActionResult> GetOrdersByAdZone(int id, long adzoneId, int sleep, DateTime startTime, DateTime endTime)
+        {
+            var list = TkPoolCore.List();
+            if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
+            string message = string.Empty;
+            int total = 0;
+            foreach (var account in list)
+            {
+#if DEBUG
+                if (account.id != id) continue;
+#endif
+                try
+                {
+                    var alimama = new AlimamaPlus(account);
+                    total += alimama.GetOrdersByAdZone(adzoneId, startTime, endTime, sleep);
+                }
+                catch (Exception ex)
+                {
+                    message = $"【新增订单接口异常adzone】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
+                    NotifyCore.Notify(new NifyMessage
+                    {
+                        message = message,
+                        priority = NifyMessagePriority.high,
+                        tags = ["red_circle"]
+                    });
+                    continue;
+                }
+            }
+            return new APIResult(new { success = true, message = "ok", total });
+        }
+
+
         [HttpGet]
         public async Task<ActionResult> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
         {
@@ -694,8 +728,9 @@ namespace molilian.api.Controllers
             PddPoolCore.Refresh();
             PangolinPoolCore.Refresh();
 
-            ElePoolCore.Refresh();
-            MeituanPoolCore.Refresh();
+            //ElePoolCore.Refresh();
+            //MeituanPoolCore.Refresh();
+            CpsPoolCore.Refresh();
             DeeplinkParseRuleCore.Refresh();
 
             return new APIResult(new
@@ -715,8 +750,9 @@ namespace molilian.api.Controllers
             JdPoolCore.Refresh();
             PddPoolCore.Refresh();
 
-            ElePoolCore.Refresh();
-            MeituanPoolCore.Refresh();
+            //ElePoolCore.Refresh();
+            //MeituanPoolCore.Refresh();
+            CpsPoolCore.Refresh();
 
             return new APIResult(new
             {

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 127 - 0
molilian.core/Core/cps/CpsPoolCore.cs

@@ -0,0 +1,127 @@
+using dodohold.core;
+using System.Threading.Channels;
+
+namespace molilian.core
+{
+
+    public partial class CpsPoolCore
+    {
+        private static string _end_point;
+        private static Dictionary<string, decimal> _incomeAmt = new();
+        private static Dictionary<string, int> _calls = new();
+        static CpsPoolCore()
+        {
+            _end_point = Environment.GetEnvironmentVariable("EndPoint");
+        }
+
+        private static readonly object _lockObj = new();
+        private static IEnumerable<CpsLinksDTO> _links_cached;
+        private static IEnumerable<CpsPoolDTO> _cached;
+
+        public static CpsLinksDTO? GetOne(string channel)
+        {
+            var list = List();
+            if (!list.Any()) return null;
+
+            var pool = list.Where(e => e.channel_code == channel && e.status).FirstOrDefault();
+            if (pool == null) return null;
+
+            var links = LinksList();
+            if (!links.Any()) return null;
+
+            return links.Where(e => IsEligible(e, channel)).OrderByDescending(e => e.priority_weight).FirstOrDefault();
+        }
+
+
+        private static bool IsEligible(CpsLinksDTO item, string channel)
+        {
+            if (item.channel_code != channel) return false;
+
+            // 使用初始化参数创建工作时间表
+            if (!new WorkSchedule(item.time_range).IsWorkHour()) return false;
+
+            var now = DateTime.Now;
+            if (item.start_time > now || now > item.end_time) return false;
+            return true;
+        }
+
+        public static IEnumerable<CpsPoolDTO> List(bool force = false)
+        {
+#if DEBUG
+            return new DBContext.Table("cps_pool")
+                .Where("status=@status", new { status = 1 })
+                .Select<CpsPoolDTO>();
+#else
+
+            if (!force && _cached != null) return _cached;
+
+            string cache_key = $"cache:cps_pool";
+            var list = RedisHelper.Get<IEnumerable<CpsPoolDTO>>(cache_key);
+            if (force || list == null)
+            {
+                lock (_lockObj)
+                {
+                    list = new DBContext.Table("cps_pool")
+                        .Where("status=@status", new { status = 1 })
+                        .Select<CpsPoolDTO>();
+                    if (list == null) return default;
+                    RedisHelper.Set(cache_key, list, 30 * 86400);
+                }
+            }
+            _cached = list;
+            return list;
+#endif
+        }
+
+        public static IEnumerable<CpsLinksDTO> LinksList(bool force = false)
+        {
+#if DEBUG
+            return new DBContext.Table("cps_links")
+                        .Where("status=@status", new { status = 1 })
+                        .Select<CpsLinksDTO>();
+#else
+            if (!force && _links_cached != null) return _links_cached;
+
+            string cache_key = $"cache:cps_links";
+            var list = RedisHelper.Get<IEnumerable<CpsLinksDTO>>(cache_key);
+            if (force || list == null)
+            {
+                lock (_lockObj)
+                {
+                    list = new DBContext.Table("cps_links")
+                        .Where("status=@status", new { status = 1 })
+                        .Select<CpsLinksDTO>();
+                    if (list == null) return default;
+                    RedisHelper.Set(cache_key, list, 30 * 86400);
+                }
+            }
+            _links_cached = list;
+            return list;
+#endif
+        }
+
+        public static void Refresh()
+        {
+            _ = List(true);
+            _ = LinksList(true);
+        }
+
+        internal static void AccountExhausted()
+        {
+            string cache_key = $"cache:tk_pool:account:exhausted";
+            long count = RedisHelper.IncrBy(cache_key);
+            if (count > 1) return;
+            RedisHelper.Expire(cache_key, 3600);
+            NotifyCore.Notify(new NifyMessage
+            {
+                message = $"【CPS优惠券】没有匹配账号",
+                priority = NifyMessagePriority.high,
+                tags = ["red_circle"]
+            });
+            NotifyCore.AnPushNotify("没账号", $"【CPS优惠券】没有匹配账号");
+        }
+
+    }
+
+
+}

+ 121 - 51
molilian.core/Core/cps/UnionCpsCore.cs

@@ -30,7 +30,7 @@ namespace molilian.core
             _end_point = Environment.GetEnvironmentVariable("EndPoint");
         }
 
-        public static UnionCpsDTO GetFormattedObject(CpsChannelEnum channel, string ip = "", string oaid = "")
+        public static UnionCpsDTO GetFormattedObject(string channel, string ip = "", string oaid = "")
         {
             return new()
             {
@@ -41,65 +41,26 @@ namespace molilian.core
             };
         }
 
-
-        #region CPS 相关
-        public static async Task<APIResult> EleAsync(string ip, string oaid)
+        #region CPS 相关 
+        public static async Task<APIResult> CpsCouponAsync(string channel, string ip, string oaid)
         {
-            UnionCpsDTO result = GetFormattedObject(CpsChannelEnum.eleme, ip, oaid);
-            var config = TkConfigCore.Get();
-
-            //============================== 放弃转链-地区过滤 ==============================
-            if (CpsShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
-            {
-                result.success = false;
-                result.message = "流量控制";
-                result.reason = reason;
-                _ = TkLogCore.CpsLogAsync(result);
-                return new APIResult(new
-                {
-                    result.success,
-                    result.message,
-                    result.reason,
-                    channel = result.channel.ToString(),
-                });
-            }
-
-            var account = ElePoolCore.GetOne();
-            if (account == null)
+            UnionCpsDTO result = GetFormattedObject(channel, ip, oaid);
+            if (string.IsNullOrEmpty(result.channel))
             {
                 result.success = false;
                 result.message = "放弃转链";
-                result.reason = "没有匹配账号";
+                result.reason = "无效渠道";
                 _ = TkLogCore.CpsLogAsync(result);
                 return new APIResult(new
                 {
                     result.success,
                     result.message,
                     result.reason,
-                    channel = result.channel.ToString(),
+                    channel,
                 });
             }
-            result.accountId = account.id;
-            result.accountName = account.name;
-            result.deeplink_url = account.deeplink;
-            result.success = true;
-            result.message = "OK";
-
-            _ = TkLogCore.CpsLogAsync(result);
-            return new APIResult(new
-            {
-                result.success,
-                result.message,
-                result.deeplink_url,
-                channel = result.channel.ToString(),
-            });
-        }
 
-        public static async Task<APIResult> MeituanAsync(string ip, string oaid)
-        {
-            UnionCpsDTO result = GetFormattedObject(CpsChannelEnum.meituan, ip, oaid);
             var config = TkConfigCore.Get();
-
             //============================== 放弃转链-地区过滤 ==============================
             if (CpsShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
             {
@@ -112,11 +73,11 @@ namespace molilian.core
                     result.success,
                     result.message,
                     result.reason,
-                    channel = result.channel.ToString(),
+                    result.channel,
                 });
             }
 
-            var account = MeituanPoolCore.GetOne();
+            var account = CpsPoolCore.GetOne(result.channel);
             if (account == null)
             {
                 result.success = false;
@@ -128,12 +89,15 @@ namespace molilian.core
                     result.success,
                     result.message,
                     result.reason,
-                    channel = result.channel.ToString(),
+                    result.channel,
                 });
             }
             result.accountId = account.id;
             result.accountName = account.name;
             result.deeplink_url = account.deeplink;
+            result.token = account.token;
+            result.category = account.category;
+            result.pid = account.pid;
             result.success = true;
             result.message = "OK";
 
@@ -143,11 +107,117 @@ namespace molilian.core
                 result.success,
                 result.message,
                 result.deeplink_url,
-                channel = result.channel.ToString(),
+                result.token,
+                result.channel,
             });
         }
 
-        public static bool CpsShouldIgnoreRequest(TkConfigDTO config, CpsChannelEnum channel, string ip, string oaid, out string reason)
+
+        //public static async Task<APIResult> EleAsync(string ip, string oaid)
+        //{
+        //    UnionCpsDTO result = GetFormattedObject(CpsChannelEnum.eleme, ip, oaid);
+        //    var config = TkConfigCore.Get();
+
+        //    //============================== 放弃转链-地区过滤 ==============================
+        //    if (CpsShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
+        //    {
+        //        result.success = false;
+        //        result.message = "流量控制";
+        //        result.reason = reason;
+        //        _ = TkLogCore.CpsLogAsync(result);
+        //        return new APIResult(new
+        //        {
+        //            result.success,
+        //            result.message,
+        //            result.reason,
+        //            channel = result.channel.ToString(),
+        //        });
+        //    }
+
+        //    var account = ElePoolCore.GetOne();
+        //    if (account == null)
+        //    {
+        //        result.success = false;
+        //        result.message = "放弃转链";
+        //        result.reason = "没有匹配账号";
+        //        _ = TkLogCore.CpsLogAsync(result);
+        //        return new APIResult(new
+        //        {
+        //            result.success,
+        //            result.message,
+        //            result.reason,
+        //            channel = result.channel.ToString(),
+        //        });
+        //    }
+        //    result.accountId = account.id;
+        //    result.accountName = account.name;
+        //    result.deeplink_url = account.deeplink;
+        //    result.success = true;
+        //    result.message = "OK";
+
+        //    _ = TkLogCore.CpsLogAsync(result);
+        //    return new APIResult(new
+        //    {
+        //        result.success,
+        //        result.message,
+        //        result.deeplink_url,
+        //        channel = result.channel.ToString(),
+        //    });
+        //}
+
+        //public static async Task<APIResult> MeituanAsync(string ip, string oaid)
+        //{
+        //    UnionCpsDTO result = GetFormattedObject(CpsChannelEnum.meituan, ip, oaid);
+        //    var config = TkConfigCore.Get();
+
+        //    //============================== 放弃转链-地区过滤 ==============================
+        //    if (CpsShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
+        //    {
+        //        result.success = false;
+        //        result.message = "流量控制";
+        //        result.reason = reason;
+        //        _ = TkLogCore.CpsLogAsync(result);
+        //        return new APIResult(new
+        //        {
+        //            result.success,
+        //            result.message,
+        //            result.reason,
+        //            channel = result.channel.ToString(),
+        //        });
+        //    }
+
+        //    var account = MeituanPoolCore.GetOne();
+        //    if (account == null)
+        //    {
+        //        result.success = false;
+        //        result.message = "放弃转链";
+        //        result.reason = "没有匹配账号";
+        //        _ = TkLogCore.CpsLogAsync(result);
+        //        return new APIResult(new
+        //        {
+        //            result.success,
+        //            result.message,
+        //            result.reason,
+        //            channel = result.channel.ToString(),
+        //        });
+        //    }
+        //    result.accountId = account.id;
+        //    result.accountName = account.name;
+        //    result.deeplink_url = account.deeplink;
+        //    result.success = true;
+        //    result.message = "OK";
+
+        //    _ = TkLogCore.CpsLogAsync(result);
+        //    return new APIResult(new
+        //    {
+        //        result.success,
+        //        result.message,
+        //        result.deeplink_url,
+        //        channel = result.channel.ToString(),
+        //    });
+        //}
+
+        public static bool CpsShouldIgnoreRequest(TkConfigDTO config, string channel, string ip, string oaid, out string reason)
         {
             reason = string.Empty;
             try

+ 26 - 1
molilian.core/Core/log/base.cs

@@ -198,6 +198,19 @@ namespace molilian.core
                 RedisHelper.Expire(cacheKey, 86400);
             }
         }
+        private static void saveClientRequestTotal(string channel, string ip, string oaid)
+        {
+            string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
+            RedisHelper.IncrBy(cacheKey);
+            RedisHelper.Expire(cacheKey, 86400);
+
+            if (!string.IsNullOrEmpty(oaid))
+            {
+                cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
+                RedisHelper.IncrBy(cacheKey);
+                RedisHelper.Expire(cacheKey, 86400);
+            }
+        }
         public static int getClientRequestTotalByOAID(TkChannelEnum channel, string oaid)
         {
             if (string.IsNullOrEmpty(oaid)) return 0;
@@ -210,6 +223,18 @@ namespace molilian.core
             string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
             return RedisHelper.Get<int>(cacheKey);
         }
+        public static int getClientRequestTotalByOAID(string channel, string oaid)
+        {
+            if (string.IsNullOrEmpty(oaid)) return 0;
+            string cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
+            return RedisHelper.Get<int>(cacheKey);
+        }
+        public static int getClientRequestTotalByIp(string channel, string ip)
+        {
+            if (string.IsNullOrEmpty(ip)) return 0;
+            string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
+            return RedisHelper.Get<int>(cacheKey);
+        }
 
 
         private static void saveClientRequestTotal(CpsChannelEnum channel, string ip, string oaid)
@@ -252,7 +277,7 @@ namespace molilian.core
                 "pinduoduo://com.xunmeng.pinduoduo/" or
                 "snssdk1128://feed?refer=web" or
                 "bdnetdisk://n/action.EXTERNAL_ACTIVITY" or
-                "openapp.jdmobile://virtual?params=" => "home",
+                "openapp.jdmobile://virtual?params=" or "openapp.jdmobile://" => "home",
                 _ => success ? "success" : "fail",
             };
 

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

@@ -49,7 +49,7 @@ namespace molilian.core
 
                 if (!response.ip.Contains("127.0.0"))
                 {
-                    saveCpsCache(response.channel.ToString(), response.accountId,
+                    saveCpsCache(response.channel, response.accountId,
                         response.success, response.message, response.reason);
                 }
             }

+ 2 - 3
molilian.core/Core/taoke/UnionCouponCore.cs

@@ -35,9 +35,8 @@ namespace molilian.core
             return channel switch
             {
                 "jd" => await JdCouponAsync(content, dplink, ip, oaid),
-                "eleme" => await UnionCpsCore.EleAsync(ip, oaid),
-                "meituan" => await UnionCpsCore.MeituanAsync(ip, oaid),
-                _ => await TaobaoCouponAsync(content, dplink, ip, oaid),
+                "tb" => await TaobaoCouponAsync(content, dplink, ip, oaid),
+                _ => await UnionCpsCore.CpsCouponAsync(channel, ip, oaid),
             };
         }
 

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

@@ -511,12 +511,15 @@ namespace molilian.core
             bool IfExceptional = false;
             try
             {
+#if DEBUG
+#else
                 // 2024-06-19 联盟业务下线
                 result.success = false;
                 result.message = "放弃转链";
                 result.reason = "联盟下线";
                 _ = TkLogCore.ParseLogAsync(result);
                 return new APIResult(result);
+#endif
 
 
                 if (DyUnionPlus.ShouldIgnoreRequest(ip, oaid, out string reason))

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

@@ -2,6 +2,7 @@
 using dodohold.core;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.FileSystemGlobbing.Internal;
+using Sayaka.Common;
 using Spire.Pdf.Annotations;
 using System.Text.RegularExpressions;
 using System.Xml.Linq;
@@ -131,6 +132,7 @@ namespace molilian.core
                             var response = await new WebClientUtility
                             {
                                 Proxy = ProxyNodesCore.RandomOne(),
+                                UserAgent = ProviderFakeUserAgent.RandomMobile,
                                 AllowAutoRedirect = true
                             }.RequestAsync(url);
                             content = response.Body();
@@ -159,6 +161,14 @@ namespace molilian.core
             }
 
 
+            if (!string.IsNullOrEmpty(rule.body_pattern))
+            {
+                var regex = new Regex(rule.body_pattern);
+                var match = regex.Match(content);
+                if (!match.Success) return null;
+
+            }
+
             var deeplink = rule.deeplink_template;
             var prompt_text = rule.prompt_text;
 

+ 17 - 0
molilian.core/DTO/Emun/TkChannelEnum.cs

@@ -51,7 +51,24 @@
     public enum CpsChannelEnum
     {
         invalid = 0,
+        /// <summary>
+        /// 美团
+        /// </summary>
         meituan = 1,
+        /// <summary>
+        /// 饿了么
+        /// </summary>
         eleme = 2,
+
+        /// <summary>
+        /// 淘宝优惠券Deeplink
+        /// </summary>
+        tbc = 3,
+        /// <summary>
+        /// 淘宝口令
+        /// </summary>
+        tbt = 4,
     }
+
+
 }

+ 7 - 2
molilian.core/DTO/alimama/TkOrderDetailDTO.cs

@@ -21,10 +21,15 @@ namespace molilian.core
         public decimal alimmTechServiceRate { get; set; } = 10.0m;
     }
 
+    [Table("tk_order_details_adzone")]
+    public class TkOrderDetailAdZoneDTO : BaseTkOrderDetailDTO;
+
     [Table("tk_order_details")]
-    public class TkOrderDetailDTO
-    {
+    public class TkOrderDetailDTO : BaseTkOrderDetailDTO;
 
+
+    public class BaseTkOrderDetailDTO
+    {
         [Key]
         public int id { get; set; }
         public int accountId { get; set; } = 0;

+ 44 - 0
molilian.core/DTO/cps/CpsPoolDTO.cs

@@ -0,0 +1,44 @@
+using dodohold.core;
+
+namespace molilian.core
+{
+    [Table("cps_pool")]
+    public class CpsPoolDTO
+    {
+        [Key]
+        public int id { get; set; }
+        public int channel_id { get; set; }
+        public string channel_code { get; set; }
+        public string name { get; set; }
+        public string end_point { get; set; }
+        public string nodeName { get; set; }
+        public string company { get; set; }
+        public string description { get; set; }
+        public DateTime create_time { get; set; }
+        public DateTime last_time { get; set; }
+        public bool status { get; set; }
+    }
+
+    [Table("cps_links")]
+    public class CpsLinksDTO
+    {
+        [Key]
+        public int id { get; set; }
+        public int channel_id { get; set; }
+        public string channel_code { get; set; }
+        public string pid { get; set; } = string.Empty;
+        public string category { get; set; } = string.Empty;
+        public string name { get; set; }
+        public string description { get; set; }
+        public DateTime create_time { get; set; }
+        public DateTime last_time { get; set; }
+        public bool status { get; set; }
+        public string deeplink { get; set; }
+        public string token { get; set; }
+        public DateTime start_time { get; set; }
+        public DateTime end_time { get; set; }
+        public int priority_weight { get; set; }
+        public int time_range { get; set; }
+    }
+
+}

+ 26 - 0
molilian.core/DTO/cps/ElePoolDTO - 复制.cs

@@ -0,0 +1,26 @@
+namespace molilian.core
+{
+    public class YourEntityClass
+    {
+        public int id { get; set; }
+        public int channel_id { get; set; }
+        public string channel_code { get; set; }
+        public string name { get; set; }
+        public string end_point { get; set; }
+        public string nodeName { get; set; }
+        public string company { get; set; }
+        public string description { get; set; }
+        public DateTime create_time { get; set; }
+        public DateTime last_time { get; set; }
+        public sbyte status { get; set; }
+        public string deeplink { get; set; }
+        public string token { get; set; }
+        public DateTime start_time { get; set; }
+        public DateTime end_time { get; set; }
+        public sbyte priority_weight { get; set; }
+        public int current_hourly_calls { get; set; }
+        public int current_daily_calls { get; set; }
+        public int time_range { get; set; }
+    }
+
+}

+ 4 - 1
molilian.core/DTO/cps/UnionCpsDTO.cs

@@ -20,7 +20,7 @@ namespace molilian.core
     {
         [Key]
         public long id { get; set; }
-        public CpsChannelEnum channel { get; set; }
+        public string channel { get; set; }
         public int accountId { get; set; } = 0;
         public string accountName { get; set; } = string.Empty;
         public string rawContent { get; set; } = string.Empty;
@@ -28,10 +28,13 @@ namespace molilian.core
         public string reason { get; set; } = string.Empty;
         public string message { get; set; } = string.Empty;
         public string deeplink_url { get; set; } = string.Empty;
+        public string token { get; set; } = string.Empty;
         public int elapsedTime { get; set; } = 0;
         public string ip { get; set; } = string.Empty;
         public string oaid { get; set; } = string.Empty;
         public DateTime create_time { get; set; } = DateTime.Now;
         public string end_point { get; set; } = string.Empty;
+        public string category { get; set; } = string.Empty;
+        public string pid { get; set; } = string.Empty;
     }
 }

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

@@ -12,6 +12,7 @@ namespace molilian.core
     public class DeeplinkParseRule
     {
         public UrlAction url_action { get; set; } = UrlAction.None;
+        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 deeplink_template { get; set; } = string.Empty;

+ 194 - 13
molilian.core/Plus/Alimama/orders.cs

@@ -18,28 +18,28 @@ namespace molilian.core
             //DateTime endTime = DateTime.Now;
             //DateTime startTime = endTime.AddDays(-90);
             //if (_accountId == 3) endTime = DateTime.Parse("2024-04-07");
-#if DEBUG
+//#if DEBUG
 
-            startTime = DateTime.Parse("2024-05-01");
-            endTime = DateTime.Parse("2024-06-01");
+//            startTime = DateTime.Parse("2024-05-01");
+//            endTime = DateTime.Parse("2024-06-01");
 
 
-            int total = 0;
+//            int total = 0;
 
-            List<DateTime> orderTimes = new List<DateTime>();
+//            List<DateTime> orderTimes = new List<DateTime>();
 
-            for (DateTime date = startTime; date <= endTime; date = date.AddDays(1))
-            {
-                orderTimes.Add(date);
-            }
+//            for (DateTime date = startTime; date <= endTime; date = date.AddDays(1))
+//            {
+//                orderTimes.Add(date);
+//            }
 
 
-#else
-            //当日往前查询
-            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkOrders(startTime, endTime, DateTime.MinValue, false, sleep);
+//#else
 
+//#endif       
 
-#endif       
+            //当日往前查询
+            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkOrders(startTime, endTime, DateTime.MinValue, false, sleep);
 
             string sql = @"
 UPDATE tk_report tr
@@ -211,6 +211,187 @@ SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + ord
             return total;
         }
 
+        public int GetOrdersByAdZone(long adzoneId, DateTime startTime, DateTime endTime, int sleep)
+        {
+            string cacheKey = $":cache:GetOrdersByAdZone:{_accountName}";
+            string cacheKey2 = $":cache:GetOrdersByAdZone:{_accountId}";
+
+            DateTime last_modifiedTime = RedisHelper.Get<DateTime>(cacheKey);
+
+            if (last_modifiedTime != DateTime.MinValue)
+            {
+                startTime = last_modifiedTime;
+            }
+            else
+            {
+                last_modifiedTime = startTime;
+            }
+
+            //当日往前查询
+            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkOrdersByAdZone(adzoneId, startTime, endTime, last_modifiedTime, true, sleep);
+            if (max_modifiedTime != DateTime.MinValue)
+            {
+                RedisHelper.Set(cacheKey, max_modifiedTime);
+                RedisHelper.Set(cacheKey2, max_modifiedTime);
+            }
+
+            return total;
+        }
+        public (int, DateTime, List<DateTime>) GetTkOrdersByAdZone(long adzoneId, DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
+        {
+            List<DateTime> orderTimes = [];
+
+            if (startTime > endTime)
+            {
+                (startTime, endTime) = (endTime, startTime);
+            }
+
+            DateTime max_modifiedTime = last_modifiedTime;
+
+            int pageNo = 1;
+            string positionIndex = string.Empty;
+            int pageSize = 100;
+
+            bool hasNext = true;
+            int total = 0;
+            while (hasNext)
+            {
+                var ts = DateTime.Now.Convert2UnixTimestamp(true);
+                string jumpType = pageNo == 1 ? "0" : "1";
+
+#if DEBUG
+                jumpType = pageNo == 1 ? "0" : "1";
+
+
+#endif
+                string queryType = desc ? "4" : "2";
+
+                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.UrlEncode()}";
+                string body = "";
+
+                JsonElement data;
+                try
+                {
+                    for (var i = 1; i <= 5; i++)
+                    {
+                        var client = new WebClientUtility().SetContentType("application/json;charset=utf-8")
+                              .AddHeaders("X-Requested-With", "XMLHttpRequest")
+                              .AddHeaders("Cookie", _cookies);
+#if DEBUG
+#else
+                        client.Proxy = _proxy;
+#endif
+                        if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
+                        var response = client.Request(url);
+
+                        if (response.ResponseException != null)
+                        {
+                            _ = new LoggerLibrary("api_error", "fail")
+                                .Info(response.ResponseException.Message, response.ResponseException.StackTrace)
+                                .SaveAsync();
+                            throw response.ResponseException;
+                        }
+                        body = response.Body();
+#if DEBUG
+                        _ = new LoggerLibrary("debug", "GetTkOrdersByAdZone")
+                            .Info(body)
+                            .SaveAsync();
+#endif
+                        if (body.Contains("{\"action\":\"captcha\""))
+                        {
+                            string message = $"【GetTkOrdersByAdZone】【{_accountId}:{_accountName}】第 {i} 次出现滑动验证码";
+                            NotifyCore.Notify(new NifyMessage
+                            {
+                                message = message,
+                                priority = NifyMessagePriority.high,
+                                tags = ["red_circle"]
+                            });
+                            Thread.Sleep(i * 60 * 1000);
+                            continue;
+                        }
+
+                        if (body.Contains("\"resultCode\":500"))
+                        {
+                            string message = $"【GetTkOrdersByAdZone】【{_accountId}:{_accountName}】第 {i} 次出现错误\n{body}";
+                            NotifyCore.Notify(new NifyMessage
+                            {
+                                message = message,
+                                priority = NifyMessagePriority.high,
+                                tags = ["red_circle"]
+                            });
+                            Thread.Sleep(i * 60 * 1000);
+                            continue;
+                        }
+                        break;
+                    }
+                    var root = body.Convert2JsonElement();
+                    var success = root.Read<bool>("success");
+                    data = root.ElementRead("data");
+
+                    if (!success && body.Contains("nologin"))
+                    {
+                        (success, string message) = RenewCookie();
+                        if (!success)
+                        {
+                            TkPoolCore.Disabled(_accountId, _accountName, $"{body}");
+                        }
+                        return (0, DateTime.MinValue, new List<DateTime>());
+                    }
+
+                    if (!success)
+                    {
+                        throw new APIException(body);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    throw new APIException(body);
+                }
+                using var conn = DBContext.GetOpenConnection();
+                conn.Open();
+
+                try
+                {
+                    foreach (var order in data.ElementRead("result").EnumerateArray())
+                    {
+                        TkOrderDetailAdZoneDTO item = order.GetRawText().Convert2Object<TkOrderDetailAdZoneDTO>();
+                        // 处理每个订单数据 
+                        if (item.adzoneId != adzoneId) continue;
+
+                        item.accountId = _accountId;
+                        item.accountName = _company;
+
+                        if (item.modifiedTime > max_modifiedTime) max_modifiedTime = item.modifiedTime;
+
+                        if (last_modifiedTime != DateTime.MinValue && last_modifiedTime >= item.modifiedTime)
+                        {
+                            return (total, max_modifiedTime, orderTimes);
+                        }
+
+                        if (item.tkStatus == 3 && item.tbPaidTime != DateTime.MinValue) orderTimes.Add(item.tbPaidTime.Date);
+                        int? id = conn.Replace(item);
+
+                        total++;
+                    }
+                }
+                catch (Exception ex)
+                {
+                    throw;
+                }
+                finally
+                {
+                    conn.Dispose();
+                }
+                pageNo++;
+                hasNext = data.Read<bool>("hasNext");
+                positionIndex = data.Read<string>("positionIndex");
+
+                if (sleep > 0) Thread.Sleep(sleep);
+            }
+            return (total, max_modifiedTime, orderTimes);
+        }
+
+
         public (int, DateTime, List<DateTime>) GetTkOrders(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
         {
             List<DateTime> orderTimes = [];

+ 1 - 1
molilian.core/Plus/JDUnion/JdUnionPlus.cs

@@ -59,7 +59,7 @@ namespace molilian.core
 
         public static string GetDeeplink(string url)
         {
-            if (string.IsNullOrEmpty(url)) return "openapp.jdmobile://virtual?params=";
+            if (string.IsNullOrEmpty(url)) return "openapp.jdmobile://";
             string virtual_params = $"{{\"category\":\"jump\",\"des\":\"m\",\"sourceValue\":\"babel-act\",\"sourceType\":\"babel\",\"url\":\"{url}\",\"M_sourceFrom\":\"h5auto\",\"msf_type\":\"auto\"}}";
             string result = $"openapp.jdmobile://virtual?params={virtual_params.UrlEncode()}";
             return result;

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

@@ -229,6 +229,11 @@ namespace molilian.core
         {
             var plus = new DyUnionPlus(account.app_key, account.app_secret);
 
+#if DEBUG
+            string test = await plus.AggregateH5Async("7369141045465973001", cancellationToken);
+#endif
+
+
             string message = "OK";
             string url = GetLink(content);
             string? desired_url = url;

+ 22 - 51
molilian.core/Plus/Pangolin/DyUnion/base.cs

@@ -82,58 +82,29 @@ namespace molilian.core
         }
 
 
-        //public async Task<DyDataDTO> GetLiveOpenId(string live_id, DyDataDTO result)
-        //{
-        //    string path = "/live/search";
-        //    string post = new { author_buyin_id = live_id, share_type = new int[] { 1, 3 } }.Convert2Json();
-
-        //    var body = await RequestAsync(path, post);
-        //    var root = body.Convert2JsonElement();
-        //    int code = root.Read<int>("code");
-        //    if (code == 0)
-        //    {
-        //        var share_info = root.ElementRead("data").ElementRead("product_info").ElementRead("share_info");
-
-        //        result.deeplink_url = share_info.Read<string>("deeplink");
-        //        result.content = share_info.Read<string>("share_command");
-        //        result.shortLinkurl = share_info.Read<string>("share_link");
-        //        result.success = true;
-        //        result.message = "OK";
-        //    }
-        //    else
-        //    {
-        //        result.success = false;
-        //        result.message = "转链失败";
-        //        result.reason = "";
-        //        result.success = false;
-        //    }
-        //    return result;
-        //}
-        //public async Task<string> GetLiveOpenId(string room_id)
-        //{
-        //    try
-        //    {
-
-        //        string url = $"https://webcast.amemv.com/webcast/room/reflow/info/?type_id=0&live_id=1&room_id={room_id}&app_id=1128";
-        //        WebClientUtility client = new();
-        //        client.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/92.0.4515.131";
-        //        var result = client.Request(url);
-
-        //        if (!result.Successed)
-        //        {
-        //            new LoggerLibrary("pangolin", "webcast_room_reflow").Info($"{room_id}").Info(result.ResponseException.Message, result.ResponseException.StackTrace).SaveAsync();
-        //            return null;
-        //        }
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        new LoggerLibrary("pangolin", "webcast_room_reflow").Info($"{room_id}").Info(ex.Message, ex.StackTrace).SaveAsync();
-        //        return null;
-        //    }
-
-        //    return result;
-        //}
+        public async Task<string> AggregateH5Async(string material_id, CancellationToken cancellationToken = default)
+        {
+            //string path = "/aggregate/h5";
+            //string post = new { material_id }.Convert2Json();
+
+
+            //material_id = "1796636629603354";
+            //string path = "/life/product/detail";
+            //string post = new
+            //{
+            //    product_id_list = new string[] { material_id },
+            //}.Convert2Json();
+
+            string path = "/life/product/search";
+            string post = new
+            {
+                keyword = material_id,
+            }.Convert2Json();
+
 
+            var body = await RequestAsync(path, post, cancellationToken);
+            return body;
+        }
 
         public async Task<string> RequestAsync(string path, string data, CancellationToken cancellationToken = default)
         {

+ 2 - 2
molilian.core/Plus/ks/open.cs

@@ -79,7 +79,7 @@ namespace molilian.core
         {
             //todo 写死 
             var _ticket = new dodohold.core.kwaixiaodian.AccessTokenDTO();
-            _ticket.access_token = "ChFvYXV0aC5hY2Nlc3NUb2tlbhJgiUxQMorqEhwJeNGcTk-ihdeaHUB7Q8z3C0vUUgqzC3gjX93_ZoCSJQVp1_uZjj_6myeHUILcNTvxOtiTXPdCF_YgS-Sgl3SPwxQgeVd62ltjj63-gQAm4PzEZawyxAEqGhLmzpljLPVHbK1DJTZ-cNTpKfIiIDMWIXZK5-NgxjH205_ulDVmPZBcMx8f14Nkd4l2b0sXKAUwAQ";
+            _ticket.access_token = "ChFvYXV0aC5hY2Nlc3NUb2tlbhIwbmKPStYeS1x-ZvbjXU5Di0DQpSKhBSpJr8Zni_S0ltA0di1ryALJD4K_4tF1ovA6GhLiICkHPKJFr7JGeErh7m5jzagiIJ5kqUgNpOvl9uBTg4gE4DiEc84Mu8ssnaAInrHmwbmtKAUwAQ";
 
 
             string action = "open.distribution.cps.kwaimoney.link.parse";
@@ -95,7 +95,7 @@ namespace molilian.core
         {
             //todo 写死 
             var _ticket = new dodohold.core.kwaixiaodian.AccessTokenDTO();
-            _ticket.access_token = "ChFvYXV0aC5hY2Nlc3NUb2tlbhJgiUxQMorqEhwJeNGcTk-ihdeaHUB7Q8z3C0vUUgqzC3gjX93_ZoCSJQVp1_uZjj_6myeHUILcNTvxOtiTXPdCF_YgS-Sgl3SPwxQgeVd62ltjj63-gQAm4PzEZawyxAEqGhLmzpljLPVHbK1DJTZ-cNTpKfIiIDMWIXZK5-NgxjH205_ulDVmPZBcMx8f14Nkd4l2b0sXKAUwAQ";
+            _ticket.access_token = "ChFvYXV0aC5hY2Nlc3NUb2tlbhIwbmKPStYeS1x-ZvbjXU5Di0DQpSKhBSpJr8Zni_S0ltA0di1ryALJD4K_4tF1ovA6GhLiICkHPKJFr7JGeErh7m5jzagiIJ5kqUgNpOvl9uBTg4gE4DiEc84Mu8ssnaAInrHmwbmtKAUwAQ";
 
 
             string action = "open.distribution.cps.kwaimoney.link.create";

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff