瀏覽代碼

支持h5接口走魔力连

dodo hold 1 年之前
父節點
當前提交
a6f16a7781

+ 78 - 4
molilian.api/Controllers/public/H5Controller.cs

@@ -36,7 +36,7 @@ namespace molilian.api.Controllers
                 return new APIResult(new
                 {
                     success = false,
-                    message = "没有可用签名账户"
+                    message = "娌℃湁鍙�敤绛惧悕璐︽埛"
                 });
             }
 
@@ -64,7 +64,7 @@ namespace molilian.api.Controllers
                 return new APIResult(new
                 {
                     success = false,
-                    message = "没有可用签名账户"
+                    message = "娌℃湁鍙�敤绛惧悕璐︽埛"
                 });
             }
 
@@ -77,7 +77,7 @@ namespace molilian.api.Controllers
                 { "timestamp", ts }
             };
 
-            // 提取客户端的业务参数并排除 "client_id" 和 "timestamp"
+            // 鎻愬彇瀹㈡埛绔�殑涓氬姟鍙傛暟骞舵帓闄� "client_id" 鍜� "timestamp"
             foreach (JsonProperty prop in form.EnumerateObject())
             {
                 if (prop.Name != "client_id" && prop.Name != "timestamp")
@@ -87,7 +87,7 @@ namespace molilian.api.Controllers
             }
 
 
-            ////其他业务参数接收客户端的form,记得排除client_id 和 timestamp
+            ////鍏朵粬涓氬姟鍙傛暟鎺ユ敹瀹㈡埛绔�殑form锛岃�寰楁帓闄�lient_id 鍜� timestamp
             //args.Add("type", "pdd.ddk.goods.recommend.get");
             //args.Add("data_type", "JSON");
             //args.Add("custom_parameters", "5");
@@ -108,5 +108,79 @@ namespace molilian.api.Controllers
             //var body = response.Body();
             //return Content(body);
         }
+        [HttpPost]
+        public ActionResult jdsign([FromBody] JsonElement form)
+        {
+            var accountid = form.Read<int>("aid", 4);
+            var method = form.Read<string>("method", string.Empty);
+            var version = form.Read<string>("v", string.Empty);
+            var param_json = form.Read<string>("param_json", string.Empty);
+
+            var api = new DBContext.Table("jd_pool").Get<JdPoolDTO>("id=@id", new { id = accountid });
+
+            string url = "https://api.jd.com/routerjson";
+            string ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            Dictionary<string, string> args = new()
+            {
+                { "access_token", ""},
+                { "app_key", api.app_key },
+                { "method", method },
+                { "v", version },
+                { "360buy_param_json", param_json },
+                { "timestamp", ts }
+            };
+
+            var plus = new JdUnionPlus(api);
+            string sign = plus._sign(method, version, param_json, ts);
+            args.Add("sign", sign);
+
+            string queryString = string.Join("&", args.Select(kv => $"{HttpUtility.UrlEncode(kv.Key)}={HttpUtility.UrlEncode(kv.Value)}"));
+            string sign_url = $"{url}?{queryString}";
+            return new APIResult(new
+            {
+                success = true,
+                message = "ok",
+                sign_url
+            });
+        }
+
+        [HttpPost]
+        public ActionResult jdrequest([FromBody] JsonElement form)
+        {
+
+            var accountid = form.Read<int>("aid", 4);
+            var method = form.Read<string>("method", string.Empty);
+            var version = form.Read<string>("v", string.Empty);
+            var param_json = form.Read<string>("param_json", string.Empty);
+
+            var api = new DBContext.Table("jd_pool").Get<JdPoolDTO>("id=@id", new { id = accountid });
+
+            if (api == null)
+            {
+                return new APIResult(new
+                {
+                    success = false,
+                    message = "娌℃湁鍙�敤绛惧悕璐︽埛"
+                });
+            }
+
+            string url = "https://api.jd.com/routerjson";
+            string ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            Dictionary<string, string> args = new()
+            {
+                { "access_token", ""},
+                { "app_key", api.app_key },
+                { "method", method },
+                { "v", version },
+                { "360buy_param_json", param_json },
+                { "timestamp", ts }
+            };
+
+            var plus = new JdUnionPlus(api);
+
+            var result = plus.Request(method, version, param_json);
+            return Content(result, "application/json");
+        }
+
     }
 }

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

@@ -342,6 +342,7 @@ namespace molilian.api.Controllers
                 AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.tb);
                 AlimamaPlus.ApiCallStatistics(2, intervalDay, TkChannelEnum.tb);
                 AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.jd);
+                AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.pdd);
 #endif
             }
             catch (Exception ex)

+ 12 - 0
molilian.api/Controllers/public/TestController.cs

@@ -37,6 +37,18 @@ namespace molilian.api.Controllers
         }
 
 
+        //[HttpGet]
+        //public async Task<ActionResult> ChangePublicIp(int id, string ecsid, string privateIp)
+        //{
+        //    AliyunCore core = new AliyunCore(id);
+        //    //创建弹性网卡并绑定公网IP
+        //    var success = core.ChangePublicIp("cn-beijing", ecsid, privateIp);
+
+        //    return new APIResult(new { success });
+        //}
+
+
+
         [HttpGet]
         public async Task<ActionResult> CreateNetworkInterface(int id, string ecsid)
         {

+ 5 - 0
molilian.api/Program.cs

@@ -67,6 +67,11 @@ if (app.Environment.IsDevelopment())
 //app.UseSwagger();
 //app.UseSwaggerUI();
 
+app.UseRequestLocalization();
+
+// Ìí¼ÓÏÂÃæÕâÐÐ
+System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
+
 app.UseHttpsRedirection();
 
 app.UseAuthorization();

文件差異過大導致無法顯示
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 1 - 1
molilian.api/Properties/launchSettings.json

@@ -11,7 +11,7 @@
         "ANPush": "",
         "DBType": "MySQL",
         "DBConfig": "Server=rm-2zey1jqxnoqy9mcc0uo.rwlb.rds.aliyuncs.com; Port=3306; Database=taoke; Uid=taoke; Pwd=67ktWBmw5G4yMs4J;SslMode=None;CharSet=utf8mb4;ConnectionTimeout=60",
-        "RedisConfig": "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook",
+        "RedisConfig": "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook",
         "CenterDB": "",
         "CenterRedis": ""
       },

+ 20 - 0
molilian.core/Core/aliyun/AliyunCore.cs

@@ -27,6 +27,26 @@ namespace molilian.core
         {
             return plus.QueryAccountBalance();
         }
+        //public bool ChangePublicIp(string region, string instanceId, string privateIp)
+        //{
+        //    try
+        //    {
+        //        //查询实例信息
+        //        var instance = plus.DescribeInstanceAttribute(region, instanceId);
+        //        var vswitchId = instance.Body.VpcAttributes.VSwitchId;
+        //        var securityGroupId = instance.Body.SecurityGroupIds.SecurityGroupId;
+
+        //        //释放弹性网卡
+        //        ReleaseEipAddress("cn-beijing", allocationId);
+        //        //申请并绑定公网IP
+        //        EcsAssociateEipAddress(region, networkInterfaceId, privateIpAddress);
+        //        return true;
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        throw new Exception(ex.Message);
+        //    }
+        //}
 
         public bool EcsCreateNetworkInterface(string region, string instanceId)
         {

+ 38 - 10
molilian.core/Core/jd/JdPoolCore.cs

@@ -20,6 +20,7 @@ namespace molilian.core
         public enum JdAction
         {
             all,
+            api,
             parse,
             coupon,
             promotionQuery
@@ -33,6 +34,7 @@ namespace molilian.core
 
         private static readonly object _lockObj = new();
         private static IEnumerable<JdPoolDTO> _cached;
+        private static IEnumerable<JdPoolDTO> _all_cached;
         public static JdPoolDTO? GetOne()
         {
             var list = List();
@@ -40,11 +42,11 @@ namespace molilian.core
             return list.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
         }
 
-        public static JdPoolDTO? GetOne(JdAction action)
+        public static JdPoolDTO? GetSpecialOne(int accountid)
         {
-            var list = List();
+            var list = AllList();
             if (!list.Any()) return null;
-            return list.Where(e => IsNotExceedDailyIncomeLimit(e, action)).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
+            return list.Where(e => e.id == accountid).FirstOrDefault();
         }
 
 
@@ -54,6 +56,13 @@ namespace molilian.core
             if (!list.Any()) return null;
             return list.Where(e => e.id == id && IsNotExceedDailyIncomeLimit(e, action)).FirstOrDefault();
         }
+
+        public static JdPoolDTO? GetOne(JdAction action)
+        {
+            var list = List();
+            if (!list.Any()) return null;
+            return list.Where(e => IsNotExceedDailyIncomeLimit(e, action)).FirstOrDefault();
+        }
         private static bool IsNotExceedDailyIncomeLimit(JdPoolDTO item, JdAction action)
         {
             if (!string.IsNullOrEmpty(_end_point) && !string.IsNullOrEmpty(item.end_point))
@@ -62,6 +71,9 @@ namespace molilian.core
             }
             switch (action)
             {
+                case JdAction.api:
+                    if (item.work_mode != JdUnionWorkMode.SiteApi) return false;
+                    break;
                 case JdAction.parse:
                     if (!item.enable_parse) return false;
                     break;
@@ -86,16 +98,28 @@ namespace molilian.core
             return true;
         }
 
-        public static IEnumerable<JdPoolDTO> List(bool force = false)
+        public static IEnumerable<JdPoolDTO> AllList(bool force = false)
         {
-#if DEBUG
-            return new DBContext.Table("jd_pool")
-                .Where("", new { status = 1 })
-                .Select<JdPoolDTO>();
-#endif
-            if (!force && _cached != null) return _cached;
+            if (!force && _all_cached != default) return _all_cached;
+            string cache_key = $"cache:all_jd_pool";
+            var list = RedisHelper.Get<IEnumerable<JdPoolDTO>>(cache_key);
+            if (force || list == default)
+            {
+                lock (_lockObj)
+                {
+                    list = new DBContext.Table("jd_pool").Select<JdPoolDTO>();
+                    if (list == null) return default;
 
+                    RedisHelper.Set(cache_key, list, 30 * 86400);
+                }
+            }
+            _all_cached = list;
+            return list;
+        }
 
+        public static IEnumerable<JdPoolDTO> List(bool force = false)
+        {
+            if (!force && _cached != null) return _cached;
             string cache_key = $"cache:jd_pool";
             var list = RedisHelper.Get<IEnumerable<JdPoolDTO>>(cache_key);
             if (force || list == null)
@@ -118,9 +142,13 @@ namespace molilian.core
             _cached = list;
             return list;
         }
+
         public static void Refresh()
         {
+            _all_cached = [];
+            _cached = [];
             _ = List(true);
+            _ = AllList();
         }
 
         public static int Update(JdPoolDTO account)

+ 1 - 1
molilian.core/DTO/alimama/TkDataDTO.cs

@@ -50,7 +50,7 @@ namespace molilian.core
         Other = 109,
 
         /// <summary>
-        /// 商放弃
+        /// 商放弃
         /// </summary>
         PartnersDrop = 110,
 

+ 1 - 0
molilian.core/DTO/alimama/TkPoolDTO.cs

@@ -54,5 +54,6 @@
         public string appkey { get; set; } = string.Empty;
         public string appSecret { get; set; } = string.Empty;
         public string open_pid { get; set; } = string.Empty;
+        public bool is_banned { get; set; } = false;
     }
 }

+ 2 - 0
molilian.core/DTO/pdd/PddEstimateRevenueDTO.cs

@@ -50,6 +50,8 @@ namespace molilian.core
         /// 应该是锁定金额?
         /// </summary>
         public int lockFeeAmount { get; set; } = 0;
+        public DateTime create_time { get; set; } = DateTime.MinValue;
+        public DateTime last_time { get; set; } = DateTime.MinValue;
 
     }
 

+ 58 - 46
molilian.core/Plus/Alimama/crawler.cs

@@ -1,4 +1,5 @@
 using dodohold.core;
+using Google.Protobuf.WellKnownTypes;
 using System.Text.Json;
 using TencentCloud.Cdn.V20180606.Models;
 using TencentCloud.Tse.V20201207.Models;
@@ -251,7 +252,7 @@ namespace molilian.core
             //tableName2
         }
 
-        public static DBContext.Table FillLinkTypeData(DBContext.Table update, int data_type, DateTime report_date)
+        public static DBContext.Table FillLinkTypeData(DBContext.Table update, int data_type, DateTime report_date, TkChannelEnum channel)
         {
             long req_other_aff_num = 0;//1
             long req_goods_num = 0;//2
@@ -264,50 +265,55 @@ namespace molilian.core
 
             try
             {
-                string tableName = $"tk_parse_logs_{report_date:yyyyMMdd}";
-
-                string exist_sql = @$"SELECT IF( EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name = '{tableName}'), 1, 0) AS table_exists;";
-
-                int exist_table = DBContext.ExecuteScalar<int>(exist_sql);
-                if (exist_table == 1)
+                switch (channel)
                 {
-                    var linkTypeTotal = new DBContext.Table(tableName)
-                                    .Fields("linkType, count(*) AS total")
-                                    .GroupBy("linkType")
-                                    .Select<dynamic>();
+                    case TkChannelEnum.tb:
+                        string tableName = $"tk_parse_logs_{report_date:yyyyMMdd}";
+                        string exist_sql = @$"SELECT IF( EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name = '{tableName}'), 1, 0) AS table_exists;";
 
-                    foreach (var t in linkTypeTotal)
-                    {
-                        int linkType = t.linkType;
-                        long total = t.total;
-                        switch (linkType)
+                        int exist_table = DBContext.ExecuteScalar<int>(exist_sql);
+                        if (exist_table == 1)
                         {
-                            case 1: req_other_aff_num = total; break;
-                            case 2: req_goods_num = total; break;
-                            case 3: req_live_num = total; break;
-                            case 4: req_video_num = total; break;
-                            case 5: req_shop_num = total; break;
-                            case 6: req_base_num = total; break;
-                            case 7: req_note_num = total; break;
+                            var linkTypeTotal = new DBContext.Table(tableName)
+                                            .Fields("linkType, count(*) AS total")
+                                            .GroupBy("linkType")
+                                            .Select<dynamic>();
+
+                            foreach (var t in linkTypeTotal)
+                            {
+                                int linkType = t.linkType;
+                                long total = t.total;
+                                switch (linkType)
+                                {
+                                    case 1: req_other_aff_num = total; break;
+                                    case 2: req_goods_num = total; break;
+                                    case 3: req_live_num = total; break;
+                                    case 4: req_video_num = total; break;
+                                    case 5: req_shop_num = total; break;
+                                    case 6: req_base_num = total; break;
+                                    case 7: req_note_num = total; break;
+                                }
+                            }
                         }
-                    }
-                }
 
-                string total_key = data_type switch
-                {
-                    1 => "parse_total",
-                    2 or _ => "coupon_total",
-                };
+                        string total_key = data_type switch
+                        {
+                            1 => "parse_total",
+                            2 or _ => "coupon_total",
+                        };
 
-                string[] deeplink_keys = ["home", "success", "fail"];
-                string accountName = "all";
-                foreach (var keyname in deeplink_keys)
-                {
-                    string cacheKey = $":{total_key}:dp_{keyname}:{accountName}:{report_date:yyyyMMdd}";
-                    int value = TkLogCore.GetTotal(cacheKey);
-                    if (value == 0) continue;
-                    resp_deeplink_num += value;
+                        string[] deeplink_keys = ["home", "success", "fail"];
+                        string accountName = "all";
+                        foreach (var keyname in deeplink_keys)
+                        {
+                            string cacheKey = $":{total_key}:dp_{keyname}:{accountName}:{report_date:yyyyMMdd}";
+                            int value = TkLogCore.GetTotal(cacheKey);
+                            if (value == 0) continue;
+                            resp_deeplink_num += value;
+                        }
+                        break;
                 }
+
             }
             catch (Exception e)
             {
@@ -412,9 +418,9 @@ namespace molilian.core
                                 .Add("pay_ord_amt", exist_report_dailys.cosPrice) //付款金额
                                 .Add("pay_ord_num", exist_report_dailys.orderNum)
                                 .Add("order_ord_num", 0)
-                                .Add("eff_ord_amt", exist_report_dailys.finishCosPrice) //有效订单金额 有效订单金额
-                                .Add("eff_ord_num", exist_report_dailys.finishOrderNum) //有效付款笔数 
-                                .Add("eff_tk_disp_tfee", exist_report_dailys.finishCosFee); //有效付款预估收入 预估收入
+                                .Add("eff_ord_amt", exist_report_dailys.cosPrice) //有效订单金额 有效订单金额
+                                .Add("eff_ord_num", exist_report_dailys.orderNum) //有效付款笔数 
+                                .Add("eff_tk_disp_tfee", exist_report_dailys.cosFee); //有效付款预估收入 预估收入
                         }
 
                         var exist = new DBContext.Table(center_conn, "center_daily_logs")
@@ -435,16 +441,22 @@ namespace molilian.core
 
                         if (exist_report_dailys != null)
                         {
+                            decimal feeAmount = Math.Round(0.01m * (decimal)exist_report_dailys.feeAmount, 2);
+                            decimal orderAmount = Math.Round(0.01m * (decimal)exist_report_dailys.orderAmount, 2);
+
+
+
+
                             update.Add("uclk_uv", 0)
                                 .Add("pay_ord_uv", 0)//付款人数
                                 .Add("uclk_pv", 0) //点击量 点击次数
-                                .Add("pay_tk_disp_tfee", exist_report_dailys.feeAmount)//预估收入 付款预估收入
-                                .Add("pay_ord_amt", exist_report_dailys.orderAmount) //付款金额
+                                .Add("pay_tk_disp_tfee", feeAmount)//预估收入 付款预估收入
+                                .Add("pay_ord_amt", orderAmount) //付款金额
                                 .Add("pay_ord_num", exist_report_dailys.orderNum)
                                 .Add("order_ord_num", 0)
-                                .Add("eff_ord_amt", exist_report_dailys.orderAmount) //有效订单金额 有效订单金额
+                                .Add("eff_ord_amt", orderAmount) //有效订单金额 有效订单金额
                                 .Add("eff_ord_num", exist_report_dailys.orderNum) //有效付款笔数 
-                                .Add("eff_tk_disp_tfee", exist_report_dailys.feeAmount); //有效付款预估收入 预估收入
+                                .Add("eff_tk_disp_tfee", feeAmount); //有效付款预估收入 预估收入
                         }
 
                         var exist = new DBContext.Table(center_conn, "center_daily_logs")
@@ -463,7 +475,7 @@ namespace molilian.core
             if (data_type == 1)
             {
                 //todo 只有转链需要处理,优惠券和京东(未上线)暂不处理
-                update = FillLinkTypeData(update, data_type, log_date);
+                update = FillLinkTypeData(update, data_type, log_date, channel);
             }
             if (record == null)
             {

+ 1 - 1
molilian.core/Plus/Alimama/parse.cs

@@ -176,7 +176,7 @@ namespace molilian.core
                 case 2:
                     result.success = false;
                     result.message = "放弃转链";
-                    result.reason = $"商放弃{commerceType}";
+                    result.reason = $"商放弃{commerceType}";
                     result.subCode = TkSubCodeEnum.PartnersDrop;
                     return result;
             }

+ 5 - 3
molilian.core/Plus/JDUnion/JdUnionPlus.cs

@@ -292,7 +292,7 @@ namespace molilian.core
                         !url.StartsWith("http://item.m.jd.com/product/")))
                     {
                         result.success = false;
-                        result.link_type = LinkTypeEnum.unknown;
+                        //result.link_type = LinkTypeEnum.unknown;
                         result.channel_type = ChannelTypeEnum.jd;
                         result.message = "放弃转链";
                         result.reason = "非标链接";
@@ -302,7 +302,9 @@ namespace molilian.core
                         result.shortLinkurl = url;
                         result.deeplink_url = result.link_type switch
                         {
-                            LinkTypeEnum.other_aff or LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
+                            LinkTypeEnum.other_aff or
+                            LinkTypeEnum.baseDomain or
+                            LinkTypeEnum.goods => JdUnionPlus.GetDeeplink(result.shortLinkurl),
                             _ => JdUnionPlus.GetDeeplink(string.Empty),
                         };
                         return result;
@@ -335,7 +337,7 @@ namespace molilian.core
                 case 2:
                     result.success = false;
                     result.message = "放弃转链";
-                    result.reason = $"商放弃{commerceType}";
+                    result.reason = $"商放弃{commerceType}";
                     return result;
             }
 

+ 2 - 3
molilian.core/Plus/JDUnion/base.cs

@@ -32,7 +32,7 @@ namespace molilian.core
         }
 
 
-        private string _sign(string method, string version, string param_json, string timestamp)
+        public string _sign(string method, string version, string param_json, string timestamp)
         {
             Dictionary<string, string> sysParameters = new()
             {
@@ -60,7 +60,7 @@ namespace molilian.core
         {
             var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             var sign = _sign(method, version, param_json, timestamp);
-            timestamp = timestamp.UrlEncode().Replace(" ", "+");
+            timestamp = timestamp.UrlEncode();
 
             string api = "https://api.jd.com/routerjson";
             string url = api;
@@ -72,7 +72,6 @@ namespace molilian.core
             url += $"&360buy_param_json={param_json.UrlEncode()}";
             url += $"&timestamp={timestamp}";
 
-
             var log = new LoggerLibrary("jdunion", method).Info(url);
             var client = new WebClientUtility();
             var response = client.Request(url);

+ 1 - 1
molilian.core/Plus/Pangolin/DyUnion/DyUnionPlus.cs

@@ -275,7 +275,7 @@ namespace molilian.core
                             case 2:
                                 result.success = false;
                                 result.message = "放弃转链";
-                                result.reason = $"商放弃{commerceType}";
+                                result.reason = $"商放弃{commerceType}";
                                 return result;
                         }
 

+ 1 - 1
molilian.core/Plus/ks/KsUnionPlus.cs

@@ -264,7 +264,7 @@ namespace molilian.core
                 case 2:
                     result.success = false;
                     result.message = "放弃转链";
-                    result.reason = $"商放弃{commerceType}";
+                    result.reason = $"商放弃{commerceType}";
                     return result;
             }
 

+ 1 - 1
molilian.core/Plus/pdd/PddUnionPlus.cs

@@ -212,7 +212,7 @@ namespace molilian.core
                 case 2:
                     result.success = false;
                     result.message = "放弃转链";
-                    result.reason = $"商放弃{commerceType}";
+                    result.reason = $"商放弃{commerceType}";
                     return result;
             }
 

部分文件因文件數量過多而無法顯示