| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751 |
- using molilian.core;
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using Org.BouncyCastle.Ocsp;
- using System.Text.Json;
- using System.Runtime.InteropServices;
- using System.Net;
- using System.Threading.Channels;
- using TencentCloud.Cdwch.V20200915.Models;
- using COSXML.Network;
- using System.Security.Cryptography;
- using System.Threading;
- using TencentCloud.Batch.V20170312.Models;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [Route("[controller]_70160bd632/[action]")]
- public class TaskController : ControllerBase
- {
- protected IHttpContextAccessor _accessor;
- public TaskController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- [HttpGet]
- public ActionResult BatchInsertLogDB(int limit = 100)
- {
- int total = TkLogCore.BatchInsertLogDB(limit);
- return new APIResult(new { success = true, message = "ok", limit, total });
- }
- [HttpGet]
- public async Task<ActionResult> GetSettleBills(int sleep = 2000)
- {
- 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 (!account.enable_sync_order) continue;
- #if DEBUG
- if (13 != account.id) continue;
- #endif
- try
- {
- var alimama = new AlimamaPlus(account);
- total += alimama.GetSettleBills(sleep);
- }
- catch (Exception ex)
- {
- message = $"【收益接口异常】\t{account.name}\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> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
- {
- var list = TkPoolCore.List();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- if (id != account.id) continue;
- try
- {
- //DateTime endTime = DateTime.Now;
- //DateTime startTime = endTime.AddDays(-90);
- if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
- var alimama = new AlimamaPlus(account);
- total += alimama.GetHistoryOrders(sleep, startTime, endTime);
- }
- catch (Exception ex)
- {
- message = $"【历史订单接口异常】[{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> GetIncyOrders(int sleep = 2000)
- {
- 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 != 17) continue;
- #endif
- if (!account.enable_sync_order) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- total += alimama.GetIncyOrders(sleep);
- }
- catch (Exception ex)
- {
- message = $"【新增订单接口异常】[{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)
- {
- var list = TkPoolCore.List();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- if (id != account.id) continue;
- try
- {
- //DateTime endTime = DateTime.Now;
- //DateTime startTime = endTime.AddDays(-90);
- if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
- var alimama = new AlimamaPlus(account);
- total += alimama.GetHistoryRefundOrders(sleep, startTime, endTime);
- }
- catch (Exception ex)
- {
- message = $"【维权订单接口异常】[{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> GetIncyRefundOrders(int sleep = 2000)
- {
- 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 != 17) continue;
- #endif
- if (!account.enable_sync_order) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- total += alimama.GetIncyRefundOrders(sleep);
- }
- catch (Exception ex)
- {
- message = $"【维权订单接口异常】[{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> GetViolationuWarning()
- {
- var list = TkPoolCore.List();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- foreach (var account in list)
- {
- try
- {
- var alimama = new AlimamaPlus(account);
- alimama.GetViolationuWarning();
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】FastReport\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" });
- }
- [HttpGet]
- public async Task<ActionResult> DailyLogs(int intervalDay = 1)
- {
- try
- {
- //本节点统计
- AlimamaPlus.NodeDailyLogs(intervalDay, "parse_", "tb");
- AlimamaPlus.NodeDailyLogs(intervalDay, "coupon_", "tb");
- AlimamaPlus.NodeDailyLogs(intervalDay); //第三方老的统计
- if (CenterHub.IsCenter)
- {
- JdUnionPlus.DailyLogs(intervalDay);
- ToolParsePlus.DailyLogs(intervalDay);
- //中心服务器统计
- AlimamaPlus.AllDailyLogs(intervalDay, "parse_", "tb");
- AlimamaPlus.AllDailyLogs(intervalDay, "coupon_", "tb");
- AlimamaPlus.AllDailyLogs(intervalDay);
- }
- }
- catch (Exception ex)
- {
- string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- if (intervalDay > 0)
- {
- try
- {
- AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.tb);
- AlimamaPlus.ApiCallStatistics(2, intervalDay, TkChannelEnum.tb);
- }
- catch (Exception ex)
- {
- string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> DailyTable(int days = 7)
- {
- try
- {
- for (int i = 0; i < days; i++)
- {
- string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
- string sql = $"CREATE TABLE IF NOT EXISTS tk_parse_logs_{table_suffix} LIKE tk_parse_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS jd_parse_logs_{table_suffix} LIKE jd_parse_logs;";
- DBContext.Execute(sql, null);
- }
- TkLogCore.save_dailys_log = true;
- RedisHelper.Set("turn:save_dailys_log", 1, 86400);
- }
- catch (Exception ex)
- {
- string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
- {
- try
- {
- AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.tb);
- AlimamaPlus.ApiCallStatistics(2, intervalDay, TkChannelEnum.tb);
- }
- catch (Exception ex)
- {
- string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- //[HttpGet]
- //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
- //{
- // try
- // {
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
- // }
- // catch (Exception ex)
- // {
- // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
- // NotifyCore.Notify(new NifyMessage
- // {
- // message = message,
- // priority = NifyMessagePriority.high,
- // tags = ["red_circle"]
- // });
- // }
- // return new APIResult(new { success = true, message = "ok" });
- //}
- [HttpGet]
- public async Task<ActionResult> GetDrawBalance()
- {
- var list = TkPoolCore.List();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- alimama.GetDrawBalance();
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】GetDrawBalance\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" });
- }
- [HttpGet]
- public async Task<ActionResult> FastReport()
- {
- string message = string.Empty;
- var list = TkPoolCore.List();
- if (list != null)
- {
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- alimama.SaveReportOverview();
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- }
- string filter = "";
- #if DEBUG
- filter = "id IN (7,8)";
- #endif
- var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
- if (jd_list != null)
- {
- bool any_jd_changed = false;
- foreach (var account in jd_list)
- {
- bool changed = false;
- try
- {
- account.current_daily_calls = JdPoolCore.SaveCalls(account.id, DateTime.Now.ToString("yyyyMMdd"));
- account.current_hourly_calls = JdPoolCore.SaveCalls(account.id, DateTime.Now.ToString("yyyyMMddHH"));
- changed = true;
- any_jd_changed = true;
- }
- catch (Exception ex)
- {
- message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- if (!account.status) continue;
- if (!string.IsNullOrEmpty(account.cookies))
- {
- try
- {
- var plus = new JdUnionPlus(account);
- var data = await plus.queryTodaySpreadEffectData();
- account.today_clickNum = data.clickNum;
- account.today_cosFee = data.cosFee;
- account.today_cosPrice = data.cosPrice;
- account.today_finishCosFee = data.finishCosFee;
- account.today_finishCosPrice = data.finishCosPrice;
- account.today_finishOrderNum = data.finishOrderNum;
- account.today_orderNum = data.orderNum;
- changed = true;
- any_jd_changed = true;
- }
- catch (Exception ex)
- {
- if (ex.Message.Contains("no login"))
- {
- account.status = false;
- JdPoolCore.Disabled(account.id, account.name, ex.Message);
- }
- message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{account.Convert2Json()}\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- if (changed) JdPoolCore.Update(account);
- }
- if (any_jd_changed) JdPoolCore.Refresh();
- }
- await EndPointCore.NotifyReload(true);
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> SaveReport()
- {
- string message = string.Empty;
- var list = TkPoolCore.List();
- if (list != null)
- {
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- #if DEBUG
- if (account.id != 5) continue;
- #endif
- try
- {
- var alimama = new AlimamaPlus(account);
- alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
- alimama.SaveReportHourtrend(DateTime.Now);
- if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
- {
- DateTime date = DateTime.Now.AddDays(-1);
- alimama.FixReport(date);
- }
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】SaveReport\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" });
- }
- [HttpGet]
- public async Task<ActionResult> JdSaveReport()
- {
- string message = string.Empty;
- var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
- if (jd_list != null)
- {
- DateTime startDate = DateTime.Now.AddDays(-1);
- DateTime endDate = DateTime.Now;
- foreach (var account in jd_list)
- {
- if (!account.status) continue;
- #if DEBUG
- if (account.id != 10) continue;
- #endif
- if (!string.IsNullOrEmpty(account.cookies))
- {
- try
- {
- var plus = new JdUnionPlus(account);
- _ = await plus.querySpreadEffectData(startDate, endDate);
- _ = await plus.queryEstimateCommList();
- }
- catch (Exception ex)
- {
- if (ex.Message.Contains("no login"))
- {
- JdPoolCore.Disabled(account.id, account.name, ex.Message);
- }
- message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\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" });
- }
- [HttpGet]
- public async Task<ActionResult> FixReport(int id, string dt)
- {
- if (!DateTime.TryParse(dt, out DateTime date))
- {
- return new APIResult(new { success = false, message = "日期错误", });
- }
- var list = TkPoolCore.List();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- foreach (var account in list)
- {
- if (id != account.id) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- while (date.Date < DateTime.Now.Date)
- {
- alimama.FixReport(date);
- date = date.AddDays(1);
- }
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】SaveReport\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" });
- }
- [HttpGet]
- public ActionResult RenewCookie(string name)
- {
- var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
- if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
- var alimama = new AlimamaPlus(account);
- (bool success, string message) = alimama.RenewCookie();
- return new APIResult(new { success, message });
- }
- [HttpGet]
- public ActionResult Reload()
- {
- TkConfigCore.Refresh();
- EndPointCore.Refresh();
- ProxyNodesCore.Refresh();
- TkPoolCore.Refresh();
- VeapiPoolCore.Refresh();
- ApiAccountCore.Refresh();
- DataokeCore.Refresh();
- JdPoolCore.Refresh();
- PddPoolCore.Refresh();
- PangolinPoolCore.Refresh();
- return new APIResult(new
- {
- success = true,
- message = "ok",
- });
- }
- [HttpGet]
- public ActionResult ReloadAccount()
- {
- EndPointCore.Refresh();
- ProxyNodesCore.Refresh();
- TkPoolCore.Refresh();
- VeapiPoolCore.Refresh();
- JdPoolCore.Refresh();
- return new APIResult(new
- {
- success = true,
- message = "ok",
- });
- }
- [HttpGet]
- public async Task<ActionResult> CheckDeepUrl(int accountid)
- {
- var postContent = "88✔7Fi43dJwWpV£ https://m.tb.cn/h.g92hfR4JLgn7yvG MF7997 我分享给你了一个超赞的内容,快来看看吧";
- var channel = "tb";
- var ip = "127.0.0.1";
- var oaid = "test-oaid";
- bool success = false;
- string message;
- //============================== 放弃转链-没有匹配账号 ==============================
- TkPoolDTO? account = TkPoolCore.GetOne(accountid);
- if (account == null)
- {
- return new APIResult(new
- {
- success = false,
- message = "没有匹配账号",
- });
- }
- var alimama = new AlimamaPlus(account);
- TkDataDTO result = new TkDataDTO();
- string url = AlimamaPlus.GetLink(postContent);
- if (string.IsNullOrEmpty(url))
- {
- return new APIResult(new
- {
- success = false,
- message = "无效URL",
- });
- }
- (success, string content) = await alimama.GetDesiredUrlAsync(url);
- if (content.Contains("霸下通用 web 页面-验证码"))
- {
- message = "霸下验证码";
- }
- else
- {
- message = content;
- }
- return new APIResult(new
- {
- success = true,
- message,
- });
- }
- }
- }
|