ソースを参照

dp账号增加指定供应商

dodo hold 1 年間 前
コミット
252c3ebd72

+ 120 - 0
molilian.api/Controllers/admin/ApiAccountController.cs

@@ -0,0 +1,120 @@
+using molilian.core;
+using dodohold.core;
+using Microsoft.AspNetCore.Mvc;
+using System.Text.Json;
+using static molilian.core.ChartDataCore;
+using TencentCloud.Soe.V20180724.Models;
+using TencentCloud.Mrs.V20200910.Models;
+using System.Xml.Linq;
+using System.Security.Cryptography;
+using TencentCloud.Bi.V20220105.Models;
+namespace molilian.api.Controllers
+{
+    [ApiController]
+    [MyAuthorize("admin")]
+    [Route("api/[controller]/[action]")]
+    public class ApiAccountController : ControllerBase
+    {
+        readonly IAuthorizationProvider provider = new AdminProvider();
+        protected IHttpContextAccessor _accessor;
+        public ApiAccountController(IHttpContextAccessor accessor)
+        {
+            _accessor = accessor;
+        }
+
+        [HttpPost]
+        public ActionResult list([FromBody] JsonElement form)
+        {
+            var token = provider.Get(_accessor.HttpContext);
+
+            int page = form.Read("current", 1);
+            int size = form.Read("pageSize", 10);
+            bool getTotal = form.Read("getTotal", true);
+
+            string sort = form.Read<string>("sort");
+            string order = form.Read<string>("order");
+
+            string filter = string.Empty;
+
+            var keyword = form.Read("keyword", string.Empty);
+
+            if (!string.IsNullOrEmpty(keyword))
+            {
+                filter += $" AND (name like @keyword OR description like @keyword OR api_key like @keyword)";
+                keyword = $"%{keyword}%";
+            }
+            filter = filter.StringTrimStart(" AND ");
+
+            string orderBy = "id DESC";
+            if (!string.IsNullOrEmpty(order))
+            {
+                order = "descending".Equals(order) ? "DESC" : "ASC";
+                orderBy = sort switch
+                {
+                    _ => $"{sort} {order}",
+                };
+            }
+
+            var result = new DBContext.Table("api_account")
+               .Where(filter, new { keyword })
+               .Page(size, page)
+               .Order(orderBy)
+               .PageList<dynamic>(getTotal);
+
+            return new APIResult(new { data = result });
+        }
+
+
+
+        [HttpPost]
+        public async Task<ActionResult> update([FromBody] ApiAccountDTO data)
+        {
+            var clientIp = _accessor.HttpContext.GetUserIp();
+            var token = provider.Get(_accessor.HttpContext);
+
+            using var conn = DBContext.GetOpenConnection();
+            if (data.id == 0) return new APIResult(new { data = new { success = false, msg = "更新失败,请检查输入参数" } });
+
+            var item = new DBContext.Table(conn, "api_account").Get<ApiAccountDTO>("id=@id", new { data.id });
+            if (item == null) return new APIResult(new { data = new { success = false, msg = "更新失败,记录不存在" } });
+
+            data.last_time = DateTime.Now;
+            var result = ApiAccountCore.Update(data, conn);
+            bool success = result > 0;
+            if (success)
+            {
+
+                string desc = ObjectComparer.PrintCompareToString(item, data).Trim();
+                OperationLogCore.LogOperation(token.AccessKey, clientIp, $"api_account:{data.name}", item.Convert2Json(), desc);
+            }
+            return new APIResult(new
+            {
+                data = new { success, msg = success ? "更新成功" : "更新失败,请检查输入信息" },
+            });
+        }
+
+        [HttpPost]
+        public async Task<ActionResult> create([FromBody] ApiAccountDTO data)
+        {
+            var clientIp = _accessor.HttpContext.GetUserIp();
+            var token = provider.Get(_accessor.HttpContext);
+
+            data.create_time = DateTime.Now;
+            data.last_time = DateTime.Now;
+
+            using var conn = DBContext.GetOpenConnection();
+            var result = ApiAccountCore.Create(data, conn);
+            bool success = result > 0;
+            if (success)
+            {
+                OperationLogCore.LogOperation(token.AccessKey, clientIp, $"api_account:{data.name}", string.Empty, data.Convert2Json());
+            }
+            return new APIResult(new
+            {
+                data = new { success, msg = success ? "更新成功" : "更新失败,请检查输入信息" },
+            });
+        }
+
+
+    }
+}

+ 0 - 1
molilian.api/Controllers/admin/PddUnionController.cs

@@ -168,7 +168,6 @@ namespace molilian.api.Controllers
             {
                 OperationLogCore.LogOperation(token.AccessKey, clientIp, $"pdd_pool:{id}:{name}", string.Empty, val);
                 await EndPointCore.NotifyReload(true);
-
             }
             return new APIResult(new
             {

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

@@ -14,6 +14,7 @@ using System.Net.Http.Json;
 using System.Text.RegularExpressions;
 using System.Text;
 using TencentCloud.Oceanus.V20190422.Models;
+using YunhuiKit;
 
 namespace molilian.api.Controllers
 {
@@ -29,6 +30,17 @@ namespace molilian.api.Controllers
         }
 
 
+        [HttpGet]
+        public async Task<ActionResult> testReconnectionRedis()
+        {
+            string cacheKey = "test";
+            RedisKit.SetAsync(cacheKey, 1, 3600);
+            string val = await RedisKit.GetAsync<string>(cacheKey);
+            return new APIResult(new { success = "ok", val });
+
+        }
+
+
         [HttpGet]
         public async Task<ActionResult> ChangePublicIp(int id)
         {

+ 47 - 1
molilian.api/Controllers/public/TkController.cs

@@ -13,6 +13,7 @@ using System.Linq;
 using static dodohold.core.ZTOExpress.CreateOrderArgs;
 using MySqlX.XDevAPI;
 using TencentCloud.Ame.V20190916.Models;
+using YunhuiKit;
 
 namespace molilian.api.Controllers
 {
@@ -417,12 +418,25 @@ namespace molilian.api.Controllers
             {
                 return new APIResult(new { success = false, message = "查询条件不能为空" });
             }
+            int[] report_account_ids = account.report_account_ids.ToArray<int>(',');
+            int[] report_exclude_account_ids = account.report_exclude_account_ids.ToArray<int>(',');
+
             string filter = $"batchId=@query";
             var account_list = await TkPoolCore.ListAsync();
             List<int> account_ids = [];
             if (account_list.Any())
             {
                 account_ids = account_list.Where(e => e.enable_fake_click).Select(e => e.id).ToList();
+
+                if (report_account_ids.Length > 0)
+                {
+                    account_ids = account_ids.Intersect(report_account_ids).ToList();
+                }
+
+                if (report_exclude_account_ids.Length > 0)
+                {
+                    account_ids = account_ids.Except(report_exclude_account_ids).ToList();
+                }
                 filter += $" AND accountId IN @account_ids";
             }
             string orderBy = "paid_time ASC";
@@ -449,6 +463,8 @@ namespace molilian.api.Controllers
             _ = log.SaveAsync();
 
             var update = new DBContext.Table("tk_order_tracking")
+                .Add("last_pull_time", DateTime.Now)
+                .Add("last_pull_account", account.name)
                 .Add("clicked_num:", "clicked_num+1")
                 .Where("id IN @ids", new { ids })
                 .Update();
@@ -464,16 +480,46 @@ namespace molilian.api.Controllers
 
 
         [HttpGet]
-        public async Task<ActionResult> unsafeParseDpList([FromQuery] string query = "")
+        public async Task<ActionResult> unsafeParseDpList([FromQuery] string a = "", [FromQuery] string query = "")
         {
+            if (string.IsNullOrEmpty(a))
+            {
+                return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
+            }
+
+            var account = await ApiAccountCore.GetOneAsync(a);
+            if (account == null || !account.enable_report)
+            {
+                return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
+            }
+
+            if (string.IsNullOrEmpty(query))
+            {
+                return new APIResult(new { success = false, message = "查询条件不能为空" });
+            }
+
+            int[] report_account_ids = account.report_account_ids.TryToArray<int>(',');
+            int[] report_exclude_account_ids = account.report_exclude_account_ids.TryToArray<int>(',');
+
             string filter = $"batchId=@query";
             var account_list = await TkPoolCore.ListAsync();
             List<int> account_ids = [];
             if (account_list.Any())
             {
                 account_ids = account_list.Where(e => e.enable_fake_click).Select(e => e.id).ToList();
+
+                if (report_account_ids.Length > 0)
+                {
+                    account_ids = account_ids.Intersect(report_account_ids).ToList();
+                }
+
+                if (report_exclude_account_ids.Length > 0)
+                {
+                    account_ids = account_ids.Except(report_exclude_account_ids).ToList();
+                }
                 filter += $" AND accountId IN @account_ids";
             }
+
             string orderBy = "paid_time ASC";
 
             var data = new DBContext.Table("tk_order_tracking")

ファイルの差分が大きいため隠しています
+ 0 - 0
molilian.api/Properties/PublishProfiles/tester.pubxml.user


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

@@ -22,7 +22,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": "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook",
+        "RedisConfig": "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook",
         "CenterDB": "",
         "CenterRedis": ""
       },

+ 1 - 2
molilian.api/molilian.api.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
+<Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
     <TargetFramework>net8.0</TargetFramework>
@@ -15,7 +15,6 @@
     <PackageReference Include="dodohold.core" Version="1.0.1.17" />
     <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.0-Preview.1" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
-    <PackageReference Include="YunhuiKit" Version="0.0.16" />
   </ItemGroup>
 
   <ItemGroup>

+ 26 - 14
molilian.core/Core/API/ApiAccountCore.cs

@@ -7,24 +7,13 @@ using System.Linq;
 using System.Text;
 using dodohold.core;
 using Dataoke;
+using System.Xml.Linq;
+using System.Data;
+using YunhuiKit;
 
 
 namespace molilian.core
 {
-    public class ApiAccountDTO
-    {
-        public int id { get; set; }
-        public string name { get; set; } = string.Empty;
-        public string api_key { get; set; } = string.Empty;
-        public string api_secret { get; set; } = string.Empty;
-        public string description { get; set; } = string.Empty;
-        public DateTime create_time { get; set; }
-        public DateTime last_time { get; set; }
-        public bool status { get; set; }
-        public int interval { get; set; }
-        public bool enable_report { get; set; } = false;
-    }
-
     public partial class ApiAccountCore
     {
         private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
@@ -111,6 +100,29 @@ namespace molilian.core
         }
 
 
+        public static int Update(ApiAccountDTO data, IDbConnection conn)
+        {
+            var result = (int)conn.Update<ApiAccountDTO>(data, new { data.id });
+            _ = ListAsync(true);
+#if DEBUG
+#else
+            EndPointCore.NotifyReload();
+#endif
+            return result;
+        }
+
+        public static int Create(ApiAccountDTO data, IDbConnection conn)
+        {
+            var result = (int)conn.Insert(data);
+            _ = ListAsync(true);
+#if DEBUG
+#else
+            EndPointCore.NotifyReload();
+#endif
+            return result;
+        }
+
+
     }
 
 

+ 34 - 0
molilian.core/DTO/api/ApiAccountDTO.cs

@@ -0,0 +1,34 @@
+
+using dodohold.core;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using System.Text.Json.Serialization;
+using TencentCloud.Mrs.V20200910.Models;
+using YunhuiKit;
+
+namespace molilian.core
+{
+    [Table("api_account")]
+    public class ApiAccountDTO
+    {
+        [Key]
+        public int id { get; set; }
+        public string name { get; set; } = string.Empty;
+        public string description { get; set; } = string.Empty;
+        public string api_key { get; set; } = string.Empty;
+        public string api_secret { get; set; } = string.Empty;
+
+        [IgnoreUpdate]
+        [JsonConverter(typeof(NullableDateTimeConverter))]
+        public DateTime create_time { get; set; }
+        [JsonConverter(typeof(NullableDateTimeConverter))]
+        public DateTime last_time { get; set; }
+        [JsonConverter(typeof(NumericBooleanConverter))]
+        public bool status { get; set; }
+        [JsonConverter(typeof(NumericBooleanConverter))]
+        public bool enable_report { get; set; }
+        public string report_account_ids { get; set; } = string.Empty;
+        public string report_exclude_account_ids { get; set; } = string.Empty;
+    }
+
+}

+ 7 - 1
molilian.core/Plus/JDUnion/H5stHack.cs

@@ -12,7 +12,9 @@ namespace molilian.core
             string body = string.Empty;
             string useragent = _account.user_agent;
             if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
-
+#if DEBUG
+            _config.jd_h5st_sign_version = "5.0.6";
+#endif
             var args = new
             {
                 version = _config.jd_h5st_sign_version,
@@ -31,6 +33,7 @@ namespace molilian.core
 
 #if DEBUG
                 url = "http://bjapi.molilian.com:3001/h5st";
+                //url = "http://127.0.0.1:3002/h5st";
 #endif
 
                 WebClientUtility client = new WebClientUtility();
@@ -40,6 +43,9 @@ namespace molilian.core
                 var response = await client.RequestAsync(url, "POST", cancellationToken);
 
                 body = response.Body();
+                /*
+{"code":200,"body":{"qs":"20250210183653774;a3a3wa33x9spd3n1;fb5df;tk04w1f0304bd41lMXgzeDN4MSsxXRJNrMWApMCLhMmN48iN4MGBZZJZFbr_lex8lZ2-o927yUFH3I1Hr4mBgVDLoBjN;75b9569aad0b0363efa5729431ead43c95ddd8ca7acb28bb8c4f9b3b101b373e;5.0;1739183813774;WNpZcw5Rph3NrZ2R5x2RoFyB3ZXRPp3RohjN1Yi9g5iNmVj8mVjN4QXRfRX9zQXR5xZO3B2OphHMjcEAt0zA6EW-3Z3L3ByR5Z3XtR3R5x2RnEz90ADAnQXR5xZO31U-0gzGmYUMQA1FIQXRfRH_qIz_4QyR5Z3XtlSR5xJN5x2RpVG83QXR5ZXRPpXN5x2RhFyB3ZXR5Z3XtZWRfRnMkQzR5ZXR5xZOoZ3L3BG83QXR5ZXRPpXN5x2RkFyB3ZXR5Z3XtZWRfRXMkQzR5ZXR5xZOgVWRfRnNkQzR5ZXR5xZOolXRfR3NkQzR5ZXR5xZO3F2OohXN3Z3L3VG83QXR5ZXRPpXN5x2Ru8yR5ZXR5xZOpZ3L3NS_3ZXR5Z3XtZWRfRX_3ZXR5Z3XtZWRfRXAiQXR5ZXRPpXN5x2RsYyR5ZXR5xp75x2R1gDAl4CA3ZXRPpH6eY3L3ZS93ZXRPp3RlBW75tWMjhD-CYnLphXNoZXELYn9icTAr0jE3Z3L3VD8mQXR5xp7;7c14c57d9aab873cc3805f9d02740b727fe3fb9720394a5e33240b303aaee289"}}                 
+                 */
                 var root = body.Convert2JsonElement();
                 int code = root.Read<int>("code");
                 string qs = root.PathRead<string>("body.qs");

+ 13 - 5
molilian.core/middleware/CustomToken.cs

@@ -32,9 +32,6 @@ namespace molilian.core
             //var appSettings = Configuration.GetSection("AppSettings");
             //appSettings.Bind(AppUtility.AppSettings);
 
-            //初始化Redis
-            RedisUtility.Init();
-
             //定期任务
             TimerScheduler.TaskContainers taskContainers = new();
             TimerScheduler timerScheduler = new TimerScheduler(taskContainers);
@@ -42,9 +39,20 @@ namespace molilian.core
 
             SystemMonitor.StartMonitoring(30);
 
-            var connstr = Environment.GetEnvironmentVariable("RedisConfig") ?? throw new ArgumentNullException("找不到对应的RedisConfig配置!");
-            RedisKit.Initialize(connstr);
+            try
+            {
+                var connstr = Environment.GetEnvironmentVariable("RedisConfig") ?? throw new ArgumentNullException("找不到对应的RedisConfig配置!");
+                RedisKit.InitializeAsync(connstr);
 
+                //初始化Redis
+                RedisUtility.Init();
+            }
+            catch (Exception ex)
+            {
+                var endPoint = Environment.GetEnvironmentVariable("EndPoint");
+                string message = $"【{endPoint}系统异常】初始化Redis失败 \n{ex.Message}\n{ex.StackTrace}";
+                NotifyCore.Notify(message);
+            }
 
 
             //services.AddMvc(option =>

+ 1 - 1
molilian.core/molilian.core.csproj

@@ -25,7 +25,7 @@
     <PackageReference Include="IP2Region.Net" Version="2.0.2" />
     <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
     <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
-    <PackageReference Include="YunhuiKit" Version="0.0.16" />
+    <PackageReference Include="YunhuiKit" Version="0.0.31" />
   </ItemGroup>
 
   <ItemGroup>

+ 6 - 0
molilian.sln

@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
 		nuget.config = nuget.config
 	EndProjectSection
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YunhuiKit", "..\..\..\yunhui\NuGet\YunhuiKit\YunhuiKit.csproj", "{4D738C33-2313-44D3-8589-76A54E8D272F}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -32,6 +34,10 @@ Global
 		{FF4DAE2A-8937-446C-B5D6-7736150021B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{FF4DAE2A-8937-446C-B5D6-7736150021B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{FF4DAE2A-8937-446C-B5D6-7736150021B6}.Release|Any CPU.Build.0 = Release|Any CPU
+		{4D738C33-2313-44D3-8589-76A54E8D272F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4D738C33-2313-44D3-8589-76A54E8D272F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4D738C33-2313-44D3-8589-76A54E8D272F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4D738C33-2313-44D3-8589-76A54E8D272F}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません