Переглянути джерело

cps增加返回title/sub_title 输出

dodo hold 11 місяців тому
батько
коміт
aac8fdb117

+ 4 - 2
molilian.api/Controllers/public/CpsController.cs

@@ -42,6 +42,7 @@ namespace molilian.api.Controllers
             var channel = form.Read("c", string.Empty);
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
+            var style = form.Read("style", string.Empty);
 
 #if DEBUG
 #else
@@ -71,7 +72,7 @@ namespace molilian.api.Controllers
 
 
 #endif 
-            return await UnionCpsCore.UnionCpsAsync(channel, ip, oaid);
+            return await UnionCpsCore.UnionCpsAsync(channel, style, ip, oaid);
         }
 
         [HttpPost]
@@ -80,11 +81,12 @@ namespace molilian.api.Controllers
             var channel = form.Read("c", string.Empty);
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
+            var style = form.Read("style", string.Empty);
 #if DEBUG
             ip = "127.0.0.1";
             oaid = "test-oaid";
 #endif
-            return await UnionCpsCore.UnionCpsAsync(channel, ip, oaid);
+            return await UnionCpsCore.UnionCpsAsync(channel, style, ip, oaid);
         }
 
 

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

@@ -142,6 +142,7 @@ namespace molilian.api.Controllers
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
             var clickId = form.Read("clickId", string.Empty);
+            var style = form.Read("style", string.Empty);
 
             //验证签名
             if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
@@ -165,7 +166,7 @@ namespace molilian.api.Controllers
             {
                 return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
             }
-            return await UnionCouponCore.UnionCouponAsync(content, dplink, channel, ip, oaid, clickId);
+            return await UnionCouponCore.UnionCouponAsync(content, dplink, channel, style, ip, oaid, clickId);
         }
 
 
@@ -177,12 +178,13 @@ namespace molilian.api.Controllers
             var channel = form.Read("c", string.Empty);
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
+            var style = form.Read("style", string.Empty);
             var clickId = form.Read("clickId", string.Empty);
 #if DEBUG
             ip = "127.0.0.1";
             oaid = "test-oaid";
 #endif
-            return await UnionCouponCore.UnionCouponAsync(content, dplink, channel, ip, oaid, clickId);
+            return await UnionCouponCore.UnionCouponAsync(content, dplink, channel, style, ip, oaid, clickId);
         }
 
 

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 34 - 2
molilian.core/Core/aliyun/AliyunCore.cs

@@ -167,6 +167,8 @@ namespace molilian.core
 
         public async Task<(bool, string, string)> ChangePublicIpAsync(string privateIp)
         {
+            LoggerLibrary log = new LoggerLibrary("ChangePublicIp");
+            log.Info($"=====更改公网IP:{privateIp}=====");
             try
             {
                 var regions = _account.regions?.Split(',');
@@ -188,6 +190,7 @@ namespace molilian.core
                         var taraget = privateIps?.PrivateIpSet.Where(e => e.PrivateIpAddress.Equals(privateIp)).FirstOrDefault();
                         if (taraget == null) continue;
 
+
                         //找到当前公网IP
                         string currentPublicIp = taraget?.AssociatedPublicIp?.PublicIpAddress;
                         DescribeEipAddressesResponseBodyEipAddressesEipAddress currentEip;
@@ -222,10 +225,12 @@ namespace molilian.core
                             await Task.Delay(500);
                             currentEip = DescribeEipAddresse(region, currentPublicIp) ?? throw new Exception("没有找到 EIP");
                         }
+                        log.Info($"找到当前公网IP:{currentPublicIp}");
                         if (currentEip == null) throw new Exception("没有找到 EIP");
 
                         //第1步、获取当前的公网EIP
                         var currentAllocationId = currentEip.AllocationId;
+                        log.Info($"获取当前的公网EIP:{currentAllocationId}");
 
                         //第2步、申请新的公网ip
                         await Task.Delay(500);
@@ -233,12 +238,27 @@ namespace molilian.core
                         var allocationId = eip.Body.AllocationId;
                         string eipAddress = eip.Body.EipAddress;
 
+                        if (string.IsNullOrEmpty(eipAddress))
+                        {
+                            log.Info("申请新的公网ip 可能出现异常", eip.Convert2Json());
+                        }
+                        else
+                        {
+                            log.Info($"申请新的公网ip:{eipAddress}");
+                        }
+
+
                         //第3步、解绑当前的公网ip
                         await Task.Delay(500);
                         plus.UnassociateEipAddress(region, currentAllocationId);
 
+                        log.Info("解绑当前的公网ip");
+
                         //第4步、检查公网ip是否成功解绑
                         string unPublicIpAddress = currentPublicIp;
+
+                        log.Info("检查公网ip是否成功解绑");
+
                         while (!string.IsNullOrEmpty(unPublicIpAddress))
                         {
                             await Task.Delay(500);
@@ -247,19 +267,25 @@ namespace molilian.core
 
                             var currentPrivateIpAddress = currentPrivateIpSet.Where(e => e.PrivateIpAddress.Equals(privateIp)).FirstOrDefault();
                             unPublicIpAddress = currentPrivateIpAddress?.AssociatedPublicIp?.PublicIpAddress;
+
+                            log.Info($"{unPublicIpAddress} 还没解绑");
+
                             if (string.IsNullOrEmpty(unPublicIpAddress)) break;
                             await Task.Delay(500);
                         }
+                        log.Info("公网ip成功解绑");
+
 
                         await Task.Delay(1500);
                         //第5步、绑定新的公网ip
                         var AssociateEipAddress =
                             plus.AssociateEipAddress(region, allocationId, networkInterfaceId, EIPInstanceType.NetworkInterface, privateIp);
 
+                        log.Info($"绑定新的公网ip", AssociateEipAddress.Convert2Json());
                         await Task.Delay(500);
                         //第5步、释放当前的公网IP
                         plus.ReleaseEipAddress(region, currentAllocationId);
-
+                        log.Info($"释放当前的公网IP");
                         return (true, currentPublicIp, eipAddress);
                     }
                 }
@@ -268,7 +294,13 @@ namespace molilian.core
             }
             catch (Exception ex)
             {
-                throw new Exception(ex.Message);
+                log.Info($"发生异常:{ex.Message}");
+                throw;
+            }
+            finally
+            {
+                log.Info($"=====结束更改公网IP:{privateIp}=====");
+                log.Save();
             }
         }
 

+ 37 - 21
molilian.core/Core/cps/CpsPoolCore.cs

@@ -18,6 +18,7 @@ namespace molilian.core
 
         private static readonly object _lockObj = new();
         private static IEnumerable<CpsLinksDTO> _links_cached;
+        private static IEnumerable<CpsApiStyleDTO> _api_style_cached;
         private static IEnumerable<CpsPoolDTO> _cached;
 
         public static CpsLinksDTO? GetOne(string channel)
@@ -49,7 +50,6 @@ namespace molilian.core
                 if (randomValue < accumulatedWeight)
                     return link;
             }
-
             // 保险起见返回第一个
             return eligibleLinks.First();
         }
@@ -114,11 +114,6 @@ namespace molilian.core
 
         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;
 
@@ -137,23 +132,10 @@ namespace molilian.core
             }
             _cached = list;
             return list;
-#endif
-        }
 
+        }
         public static IEnumerable<CpsLinksDTO> LinksList(bool force = false)
         {
-#if DEBUG
-            var list = new DBContext.Table("cps_links")
-                        .Where("status=@status", new { status = 1 })
-                        .Select<CpsLinksDTO>();
-            foreach (var item in list)
-            {
-                RiskControlCore.SetCallsAsync(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
-                RiskControlCore.SetCallsAsync(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
-            }
-            return list;
-
-#else
             if (!force && _links_cached != null) return _links_cached;
 
             string cache_key = $"cache:cps_links";
@@ -176,7 +158,27 @@ namespace molilian.core
             }
             _links_cached = list;
             return list;
-#endif
+        }
+
+        public static IEnumerable<CpsApiStyleDTO> ApiStyleList(bool force = false)
+        {
+            if (!force && _api_style_cached != null) return _api_style_cached;
+
+            string cache_key = $"cache:cps_api_style";
+            var list = RedisHelper.Get<IEnumerable<CpsApiStyleDTO>>(cache_key);
+            if (force || list == null)
+            {
+                lock (_lockObj)
+                {
+                    list = new DBContext.Table("cps_api_syle")
+                        .Where("status=@status", new { status = 1 })
+                        .Select<CpsApiStyleDTO>();
+                    if (list == null) return default;
+                    RedisHelper.Set(cache_key, list, 30 * 86400);
+                }
+            }
+            _api_style_cached = list;
+            return list;
         }
         public static int Update(CpsLinksDTO account)
         {
@@ -191,6 +193,7 @@ namespace molilian.core
         {
             _ = List(true);
             _ = LinksList(true);
+            _ = ApiStyleList(true);
         }
 
         internal static void AccountExhausted()
@@ -208,6 +211,19 @@ namespace molilian.core
             _ = NotifyCore.QYWeixinPushNotifyAsync("没账号", $"【CPS优惠券】没有匹配账号");
         }
 
+        public static CpsApiStyleDTO? GetTitle(CpsLinksDTO account, string style)
+        {
+            CpsApiStyleDTO result = null;
+            try
+            {
+                if (string.IsNullOrEmpty(account.style_code)) return null;
+                var list = ApiStyleList();
+                var record = list?.Where(e => e.style_code == account.style_code && e.style_name == style).FirstOrDefault();
+                if (record != null) result = record;
+            }
+            catch { }
+            return result;
+        }
     }
 
 

+ 19 - 4
molilian.core/Core/cps/UnionCpsCore.cs

@@ -43,18 +43,19 @@ namespace molilian.core
         }
 
         #region CPS 相关 
-        public static async Task<APIResult> UnionCpsAsync(string channelStr, string ip, string oaid)
+        public static async Task<APIResult> UnionCpsAsync(string channelStr, string style, string ip, string oaid)
         {
             var channel_list = channelStr.Split(',');
             List<dynamic> list = new List<dynamic>();
             foreach (var channel in channel_list)
             {
-                var result = await CpsCouponAsync(channel, ip, oaid);
+                var result = await CpsCouponAsync(channel, style, ip, oaid);
                 list.Add(new
                 {
                     result.success,
                     result.message,
                     result.title,
+                    result.sub_title,
                     result.deeplink_url,
                     result.token,
                     result.channel,
@@ -67,7 +68,7 @@ namespace molilian.core
             });
         }
 
-        public static async Task<UnionCpsDTO> CpsCouponAsync(string channel, string ip, string oaid)
+        public static async Task<UnionCpsDTO> CpsCouponAsync(string channel, string style, string ip, string oaid)
         {
             UnionCpsDTO result = GetFormattedObject(channel, ip, oaid);
             if (string.IsNullOrEmpty(result.channel))
@@ -106,6 +107,12 @@ namespace molilian.core
             result.category = account.category;
             result.pid = account.pid;
             result.title = account.title;
+            var style_record = CpsPoolCore.GetTitle(account, style);
+            if (style_record != null)
+            {
+                result.title = style_record.title;
+                result.sub_title = style_record.sub_title;
+            }
             result.success = true;
             result.message = "OK";
 
@@ -131,7 +138,7 @@ namespace molilian.core
 
 
 
-        public static async Task<APIResult> CpsCouponAsync22(string channel, string ip, string oaid)
+        public static async Task<APIResult> CpsCouponAsync22(string channel, string style, string ip, string oaid)
         {
             UnionCpsDTO result = GetFormattedObject(channel, ip, oaid);
             if (string.IsNullOrEmpty(result.channel))
@@ -188,6 +195,12 @@ namespace molilian.core
             result.category = account.category;
             result.pid = account.pid;
             result.title = account.title;
+            var style_record = CpsPoolCore.GetTitle(account, style);
+            if (style_record != null)
+            {
+                result.title = style_record.title;
+                result.sub_title = style_record.sub_title;
+            }
             result.success = true;
             result.message = "OK";
 
@@ -197,6 +210,7 @@ namespace molilian.core
                 result.success,
                 result.message,
                 result.title,
+                result.sub_title,
                 result.deeplink_url,
                 result.token,
                 result.channel,
@@ -332,6 +346,7 @@ namespace molilian.core
                 result.success,
                 result.message,
                 result.title,
+                result.sub_title,
                 result.deeplink_url,
                 result.token,
                 result.channel,

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

@@ -118,6 +118,7 @@ namespace molilian.core
                 .Add("category", data.category)
                 .Add("pid", data.pid)
                 .Add("title", data.title)
+                .Add("sub_title", data.sub_title)
                 .Add("itemId", data.itemId)
                 .Add("couponAmount", data.couponAmount)
                 .Create(DBContext.InsertType.NORMAL, transaction);

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

@@ -12,7 +12,7 @@ namespace molilian.core
             _end_point = Environment.GetEnvironmentVariable("EndPoint");
         }
 
-        public static async Task<ActionResult> UnionCouponAsync(string content, string dplink, string channel, string ip, string oaid, string clickId)
+        public static async Task<ActionResult> UnionCouponAsync(string content, string dplink, string channel, string style, string ip, string oaid, string clickId)
         {
             switch (channel)
             {
@@ -25,7 +25,7 @@ namespace molilian.core
                     {
                         return await UnionCpsCore.TbtCouponAsync(content, channel, ip, oaid);
                     }
-                    var result = await UnionCpsCore.CpsCouponAsync(channel, ip, oaid);
+                    var result = await UnionCpsCore.CpsCouponAsync(channel, style, ip, oaid);
                     if (result.success)
                     {
                         return new APIResult(new
@@ -33,6 +33,7 @@ namespace molilian.core
                             result.success,
                             result.message,
                             result.title,
+                            result.sub_title,
                             result.deeplink_url,
                             result.token,
                             result.channel,

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

@@ -2,6 +2,22 @@
 
 namespace molilian.core
 {
+    [Table("cps_api_syle")]
+    public class CpsApiStyleDTO
+    {
+        [Key]
+        public int id { get; set; }
+        public string style_code { get; set; }
+        public string title { get; set; }
+        public string sub_title { get; set; }
+        public string style_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; }
+    }
+
+
     [Table("cps_pool")]
     public class CpsPoolDTO
     {
@@ -26,6 +42,7 @@ namespace molilian.core
         public int id { get; set; }
         public int channel_id { get; set; }
         public string channel_code { get; set; }
+        public string style_code { get; set; }
         public string pid { get; set; } = string.Empty;
         public string category { get; set; } = string.Empty;
         public string name { get; set; }

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

@@ -38,6 +38,7 @@ namespace molilian.core
         public string category { get; set; } = string.Empty;
         public string pid { get; set; } = string.Empty;
         public string title { get; set; } = string.Empty;
+        public string sub_title { get; set; } = string.Empty;
 
 
         public string rawContent2 { get; set; } = string.Empty;

Деякі файли не було показано, через те що забагато файлів було змінено