TaskController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using System.Net;
  8. using System.Threading.Channels;
  9. using TencentCloud.Cdwch.V20200915.Models;
  10. using COSXML.Network;
  11. using System.Security.Cryptography;
  12. using System.Threading;
  13. using TencentCloud.Batch.V20170312.Models;
  14. namespace molilian.api.Controllers
  15. {
  16. [ApiController]
  17. [Route("[controller]_70160bd632/[action]")]
  18. public class TaskController : ControllerBase
  19. {
  20. protected IHttpContextAccessor _accessor;
  21. public TaskController(IHttpContextAccessor accessor)
  22. {
  23. _accessor = accessor;
  24. }
  25. [HttpGet]
  26. public async Task<ActionResult> BatchInsertLogDB(int limit = 100)
  27. {
  28. int total = await TkLogCore.BatchInsertLogDBAsync(limit);
  29. return new APIResult(new { success = true, message = "ok", limit, total });
  30. }
  31. [HttpGet]
  32. public async Task<ActionResult> GetSettleBills(int sleep = 2000)
  33. {
  34. var list = TkPoolCore.List();
  35. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  36. string message = string.Empty;
  37. int total = 0;
  38. foreach (var account in list)
  39. {
  40. if (!account.enable_sync_order) continue;
  41. #if DEBUG
  42. if (13 != account.id) continue;
  43. #endif
  44. try
  45. {
  46. var alimama = new AlimamaPlus(account);
  47. total += alimama.GetSettleBills(sleep);
  48. }
  49. catch (Exception ex)
  50. {
  51. message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
  52. NotifyCore.Notify(new NifyMessage
  53. {
  54. message = message,
  55. priority = NifyMessagePriority.high,
  56. tags = ["red_circle"]
  57. });
  58. continue;
  59. }
  60. }
  61. return new APIResult(new { success = true, message = "ok", total });
  62. }
  63. [HttpGet]
  64. public async Task<ActionResult> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  65. {
  66. var list = TkPoolCore.List();
  67. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  68. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  69. string message = string.Empty;
  70. int total = 0;
  71. foreach (var account in list)
  72. {
  73. if (id != account.id) continue;
  74. try
  75. {
  76. //DateTime endTime = DateTime.Now;
  77. //DateTime startTime = endTime.AddDays(-90);
  78. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  79. var alimama = new AlimamaPlus(account);
  80. total += alimama.GetHistoryOrders(sleep, startTime, endTime);
  81. }
  82. catch (Exception ex)
  83. {
  84. message = $"【历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  85. NotifyCore.Notify(new NifyMessage
  86. {
  87. message = message,
  88. priority = NifyMessagePriority.high,
  89. tags = ["red_circle"]
  90. });
  91. continue;
  92. }
  93. }
  94. return new APIResult(new { success = true, message = "ok", total });
  95. }
  96. [HttpGet]
  97. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  98. {
  99. var list = TkPoolCore.List();
  100. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  101. string message = string.Empty;
  102. int total = 0;
  103. foreach (var account in list)
  104. {
  105. #if DEBUG
  106. if (account.id != 17) continue;
  107. #endif
  108. if (!account.enable_sync_order) continue;
  109. try
  110. {
  111. var alimama = new AlimamaPlus(account);
  112. total += alimama.GetIncyOrders(sleep);
  113. }
  114. catch (Exception ex)
  115. {
  116. message = $"【新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  117. NotifyCore.Notify(new NifyMessage
  118. {
  119. message = message,
  120. priority = NifyMessagePriority.high,
  121. tags = ["red_circle"]
  122. });
  123. continue;
  124. }
  125. }
  126. return new APIResult(new { success = true, message = "ok", total });
  127. }
  128. [HttpGet]
  129. public async Task<ActionResult> GetOrdersByAdZone(int id, long adzoneId, int sleep, DateTime startTime, DateTime endTime)
  130. {
  131. var list = TkPoolCore.List();
  132. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  133. string message = string.Empty;
  134. int total = 0;
  135. foreach (var account in list)
  136. {
  137. #if DEBUG
  138. if (account.id != id) continue;
  139. #endif
  140. try
  141. {
  142. var alimama = new AlimamaPlus(account);
  143. total += alimama.GetOrdersByAdZone(adzoneId, startTime, endTime, sleep);
  144. }
  145. catch (Exception ex)
  146. {
  147. message = $"【新增订单接口异常adzone】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  148. NotifyCore.Notify(new NifyMessage
  149. {
  150. message = message,
  151. priority = NifyMessagePriority.high,
  152. tags = ["red_circle"]
  153. });
  154. continue;
  155. }
  156. }
  157. return new APIResult(new { success = true, message = "ok", total });
  158. }
  159. [HttpGet]
  160. public async Task<ActionResult> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  161. {
  162. var list = TkPoolCore.List();
  163. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  164. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  165. string message = string.Empty;
  166. int total = 0;
  167. foreach (var account in list)
  168. {
  169. if (id != account.id) continue;
  170. try
  171. {
  172. //DateTime endTime = DateTime.Now;
  173. //DateTime startTime = endTime.AddDays(-90);
  174. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  175. var alimama = new AlimamaPlus(account);
  176. total += alimama.GetHistoryRefundOrders(sleep, startTime, endTime);
  177. }
  178. catch (Exception ex)
  179. {
  180. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  181. NotifyCore.Notify(new NifyMessage
  182. {
  183. message = message,
  184. priority = NifyMessagePriority.high,
  185. tags = ["red_circle"]
  186. });
  187. continue;
  188. }
  189. }
  190. return new APIResult(new { success = true, message = "ok", total });
  191. }
  192. [HttpGet]
  193. public async Task<ActionResult> GetIncyRefundOrders(int sleep = 2000)
  194. {
  195. var list = TkPoolCore.List();
  196. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  197. string message = string.Empty;
  198. int total = 0;
  199. foreach (var account in list)
  200. {
  201. #if DEBUG
  202. if (account.id != 17) continue;
  203. #endif
  204. if (!account.enable_sync_order) continue;
  205. try
  206. {
  207. var alimama = new AlimamaPlus(account);
  208. total += alimama.GetIncyRefundOrders(sleep);
  209. }
  210. catch (Exception ex)
  211. {
  212. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  213. NotifyCore.Notify(new NifyMessage
  214. {
  215. message = message,
  216. priority = NifyMessagePriority.high,
  217. tags = ["red_circle"]
  218. });
  219. continue;
  220. }
  221. }
  222. return new APIResult(new { success = true, message = "ok", total });
  223. }
  224. [HttpGet]
  225. public async Task<ActionResult> GetViolationuWarning()
  226. {
  227. var list = TkPoolCore.List();
  228. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  229. string message = string.Empty;
  230. foreach (var account in list)
  231. {
  232. try
  233. {
  234. var alimama = new AlimamaPlus(account);
  235. alimama.GetViolationuWarning();
  236. }
  237. catch (Exception ex)
  238. {
  239. message = $"【报表接口异常】GetViolationuWarning\n{ex.Message}\n{ex.StackTrace}";
  240. NotifyCore.Notify(new NifyMessage
  241. {
  242. message = message,
  243. priority = NifyMessagePriority.high,
  244. tags = ["red_circle"]
  245. });
  246. continue;
  247. }
  248. }
  249. return new APIResult(new { success = true, message = "ok" });
  250. }
  251. [HttpGet]
  252. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  253. {
  254. try
  255. {
  256. //本节点统计
  257. AlimamaPlus.NodeDailyLogs(intervalDay, "parse_", "tb");
  258. AlimamaPlus.NodeDailyLogs(intervalDay, "coupon_", "tb");
  259. AlimamaPlus.NodeDailyLogs(intervalDay); //第三方老的统计
  260. if (CenterHub.IsCenter)
  261. {
  262. JdUnionPlus.DailyLogs(intervalDay);
  263. ToolParsePlus.DailyLogs(intervalDay);
  264. //中心服务器统计
  265. AlimamaPlus.AllDailyLogs(intervalDay, "parse_", "tb");
  266. AlimamaPlus.AllDailyLogs(intervalDay, "coupon_", "tb");
  267. KsUnionPlus.DailyLogs(intervalDay);
  268. PddUnionPlus.DailyLogs(intervalDay);
  269. AlimamaPlus.AllDailyLogs(intervalDay);
  270. }
  271. }
  272. catch (Exception ex)
  273. {
  274. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  275. NotifyCore.Notify(new NifyMessage
  276. {
  277. message = message,
  278. priority = NifyMessagePriority.high,
  279. tags = ["red_circle"]
  280. });
  281. }
  282. return new APIResult(new { success = true, message = "ok" });
  283. }
  284. [HttpGet]
  285. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  286. {
  287. try
  288. {
  289. AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.tb);
  290. AlimamaPlus.ApiCallStatistics(2, intervalDay, TkChannelEnum.tb);
  291. }
  292. catch (Exception ex)
  293. {
  294. string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  295. NotifyCore.Notify(new NifyMessage
  296. {
  297. message = message,
  298. priority = NifyMessagePriority.high,
  299. tags = ["red_circle"]
  300. });
  301. }
  302. return new APIResult(new { success = true, message = "ok" });
  303. }
  304. [HttpGet]
  305. public async Task<ActionResult> DailyTable(int days = 3)
  306. {
  307. try
  308. {
  309. for (int i = 0; i < days; i++)
  310. {
  311. if (CenterHub.IsCenter)
  312. {
  313. string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
  314. string sql = $"CREATE TABLE IF NOT EXISTS tk_parse_logs_{table_suffix} LIKE tk_parse_logs;";
  315. DBContext.Execute(sql, null);
  316. sql = $"CREATE TABLE IF NOT EXISTS jd_parse_logs_{table_suffix} LIKE jd_parse_logs;";
  317. DBContext.Execute(sql, null);
  318. sql = $"CREATE TABLE IF NOT EXISTS ks_parse_logs_{table_suffix} LIKE ks_parse_logs;";
  319. DBContext.Execute(sql, null);
  320. sql = $"CREATE TABLE IF NOT EXISTS dy_parse_logs_{table_suffix} LIKE dy_parse_logs;";
  321. DBContext.Execute(sql, null);
  322. sql = $"CREATE TABLE IF NOT EXISTS tk_promotion_logs_{table_suffix} LIKE tk_promotion_logs;";
  323. DBContext.Execute(sql, null);
  324. sql = $"CREATE TABLE IF NOT EXISTS deeplink_parse_logs_{table_suffix} LIKE deeplink_parse_logs;";
  325. DBContext.Execute(sql, null);
  326. sql = $"CREATE TABLE IF NOT EXISTS pdd_parse_logs_{table_suffix} LIKE pdd_parse_logs;";
  327. DBContext.Execute(sql, null);
  328. }
  329. else
  330. {
  331. string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
  332. string sql = $"CREATE TABLE IF NOT EXISTS tk_cps_logs_{table_suffix} LIKE tk_cps_logs;";
  333. DBContext.Execute(sql, null);
  334. }
  335. }
  336. TkLogCore.save_dailys_log = true;
  337. RedisHelper.Set("turn:save_dailys_log", 1, 86400);
  338. }
  339. catch (Exception ex)
  340. {
  341. string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
  342. NotifyCore.Notify(new NifyMessage
  343. {
  344. message = message,
  345. priority = NifyMessagePriority.high,
  346. tags = ["red_circle"]
  347. });
  348. }
  349. return new APIResult(new { success = true, message = "ok" });
  350. }
  351. //[HttpGet]
  352. //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  353. //{
  354. // try
  355. // {
  356. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  357. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  358. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  359. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  360. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  361. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  362. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  363. // }
  364. // catch (Exception ex)
  365. // {
  366. // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  367. // NotifyCore.Notify(new NifyMessage
  368. // {
  369. // message = message,
  370. // priority = NifyMessagePriority.high,
  371. // tags = ["red_circle"]
  372. // });
  373. // }
  374. // return new APIResult(new { success = true, message = "ok" });
  375. //}
  376. [HttpGet]
  377. public async Task<ActionResult> GetDrawBalance()
  378. {
  379. var list = TkPoolCore.List();
  380. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  381. string message = string.Empty;
  382. foreach (var account in list)
  383. {
  384. if (!account.enable_sync_order) continue;
  385. try
  386. {
  387. var alimama = new AlimamaPlus(account);
  388. alimama.GetDrawBalance();
  389. }
  390. catch (Exception ex)
  391. {
  392. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  393. NotifyCore.Notify(new NifyMessage
  394. {
  395. message = message,
  396. priority = NifyMessagePriority.high,
  397. tags = ["red_circle"]
  398. });
  399. continue;
  400. }
  401. }
  402. return new APIResult(new { success = true, message = "ok" });
  403. }
  404. [HttpGet]
  405. public async Task<ActionResult> FastReport()
  406. {
  407. string message = string.Empty;
  408. var list = TkPoolCore.List();
  409. if (list != null)
  410. {
  411. foreach (var account in list)
  412. {
  413. try
  414. {
  415. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMdd"));
  416. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  417. new DBContext.Table("tk_pool")
  418. .Add("current_hourly_calls", account.current_hourly_calls)
  419. .Add("current_daily_calls", account.current_daily_calls)
  420. .Where("id=@id", new { account.id })
  421. .Update();
  422. }
  423. catch (Exception ex)
  424. {
  425. message = $"【TB计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  426. NotifyCore.Notify(new NifyMessage
  427. {
  428. message = message,
  429. priority = NifyMessagePriority.high,
  430. tags = ["red_circle"]
  431. });
  432. continue;
  433. }
  434. if (!account.enable_sync_order) continue;
  435. try
  436. {
  437. var alimama = new AlimamaPlus(account);
  438. alimama.SaveReportOverview();
  439. }
  440. catch (Exception ex)
  441. {
  442. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  443. NotifyCore.Notify(new NifyMessage
  444. {
  445. message = message,
  446. priority = NifyMessagePriority.high,
  447. tags = ["red_circle"]
  448. });
  449. continue;
  450. }
  451. }
  452. }
  453. string filter = "";
  454. var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
  455. if (jd_list != null)
  456. {
  457. bool any_jd_changed = false;
  458. foreach (var account in jd_list)
  459. {
  460. bool changed = false;
  461. try
  462. {
  463. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  464. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  465. changed = true;
  466. any_jd_changed = true;
  467. }
  468. catch (Exception ex)
  469. {
  470. message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  471. NotifyCore.Notify(new NifyMessage
  472. {
  473. message = message,
  474. priority = NifyMessagePriority.high,
  475. tags = ["red_circle"]
  476. });
  477. continue;
  478. }
  479. if (!account.status) continue;
  480. if (!string.IsNullOrEmpty(account.cookies))
  481. {
  482. try
  483. {
  484. var plus = new JdUnionPlus(account);
  485. var data = await plus.queryTodaySpreadEffectData();
  486. account.today_clickNum = data.clickNum;
  487. account.today_cosFee = data.cosFee;
  488. account.today_cosPrice = data.cosPrice;
  489. account.today_finishCosFee = data.finishCosFee;
  490. account.today_finishCosPrice = data.finishCosPrice;
  491. account.today_finishOrderNum = data.finishOrderNum;
  492. account.today_orderNum = data.orderNum;
  493. changed = true;
  494. any_jd_changed = true;
  495. }
  496. catch (Exception ex)
  497. {
  498. if (ex.Message.Contains("no login"))
  499. {
  500. account.status = false;
  501. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  502. }
  503. message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{account.Convert2Json()}\n{ex.Message}\n{ex.StackTrace}";
  504. NotifyCore.Notify(new NifyMessage
  505. {
  506. message = message,
  507. priority = NifyMessagePriority.high,
  508. tags = ["red_circle"]
  509. });
  510. continue;
  511. }
  512. }
  513. if (changed) JdPoolCore.Update(account);
  514. }
  515. if (any_jd_changed) JdPoolCore.Refresh();
  516. }
  517. var pdd_list = new DBContext.Table("pdd_pool").Where(filter, null).Select<PddPoolDTO>();
  518. if (pdd_list != null)
  519. {
  520. bool any_pdd_changed = false;
  521. foreach (var account in pdd_list)
  522. {
  523. bool changed = false;
  524. try
  525. {
  526. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  527. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  528. changed = true;
  529. any_pdd_changed = true;
  530. }
  531. catch (Exception ex)
  532. {
  533. message = $"【Pdd计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  534. NotifyCore.Notify(new NifyMessage
  535. {
  536. message = message,
  537. priority = NifyMessagePriority.high,
  538. tags = ["red_circle"]
  539. });
  540. continue;
  541. }
  542. if (changed) PddPoolCore.Update(account);
  543. }
  544. if (any_pdd_changed) PddPoolCore.Refresh();
  545. }
  546. await EndPointCore.NotifyReload(true);
  547. return new APIResult(new { success = true, message = "ok" });
  548. }
  549. [HttpGet]
  550. public async Task<ActionResult> SaveReport()
  551. {
  552. string message = string.Empty;
  553. var list = TkPoolCore.List();
  554. if (list != null)
  555. {
  556. foreach (var account in list)
  557. {
  558. if (!account.enable_sync_order) continue;
  559. #if DEBUG
  560. if (account.id != 5) continue;
  561. #endif
  562. try
  563. {
  564. var alimama = new AlimamaPlus(account);
  565. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  566. alimama.SaveReportHourtrend(DateTime.Now);
  567. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  568. {
  569. DateTime date = DateTime.Now.AddDays(-1);
  570. alimama.FixReport(date);
  571. }
  572. }
  573. catch (Exception ex)
  574. {
  575. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  576. NotifyCore.Notify(new NifyMessage
  577. {
  578. message = message,
  579. priority = NifyMessagePriority.high,
  580. tags = ["red_circle"]
  581. });
  582. continue;
  583. }
  584. }
  585. }
  586. return new APIResult(new { success = true, message = "ok" });
  587. }
  588. [HttpGet]
  589. public async Task<ActionResult> JdSaveReport()
  590. {
  591. string message = string.Empty;
  592. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  593. if (jd_list != null)
  594. {
  595. DateTime startDate = DateTime.Now.AddDays(-89);
  596. DateTime endDate = DateTime.Now.AddDays(-1);
  597. foreach (var account in jd_list)
  598. {
  599. if (!account.status) continue;
  600. #if DEBUG
  601. if (account.id != 10) continue;
  602. #endif
  603. if (account.is_hide) continue;
  604. if (!string.IsNullOrEmpty(account.cookies))
  605. {
  606. try
  607. {
  608. var plus = new JdUnionPlus(account);
  609. _ = await plus.querySpreadEffectData(startDate, endDate);
  610. _ = await plus.queryEstimateCommList();
  611. }
  612. catch (Exception ex)
  613. {
  614. if (ex.Message.Contains("no login"))
  615. {
  616. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  617. }
  618. message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  619. NotifyCore.Notify(new NifyMessage
  620. {
  621. message = message,
  622. priority = NifyMessagePriority.high,
  623. tags = ["red_circle"]
  624. });
  625. continue;
  626. }
  627. }
  628. }
  629. }
  630. return new APIResult(new { success = true, message = "ok" });
  631. }
  632. [HttpGet]
  633. public async Task<ActionResult> FixReport(int id, string dt)
  634. {
  635. if (!DateTime.TryParse(dt, out DateTime date))
  636. {
  637. return new APIResult(new { success = false, message = "日期错误", });
  638. }
  639. var list = TkPoolCore.List();
  640. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  641. string message = string.Empty;
  642. foreach (var account in list)
  643. {
  644. if (id != account.id) continue;
  645. try
  646. {
  647. var alimama = new AlimamaPlus(account);
  648. while (date.Date < DateTime.Now.Date)
  649. {
  650. alimama.FixReport(date);
  651. date = date.AddDays(1);
  652. }
  653. }
  654. catch (Exception ex)
  655. {
  656. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  657. NotifyCore.Notify(new NifyMessage
  658. {
  659. message = message,
  660. priority = NifyMessagePriority.high,
  661. tags = ["red_circle"]
  662. });
  663. continue;
  664. }
  665. }
  666. return new APIResult(new { success = true, message = "ok" });
  667. }
  668. [HttpGet]
  669. public ActionResult RenewCookie(string name)
  670. {
  671. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  672. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  673. var alimama = new AlimamaPlus(account);
  674. (bool success, string message) = alimama.RenewCookie();
  675. return new APIResult(new { success, message });
  676. }
  677. [HttpGet]
  678. public ActionResult Reload()
  679. {
  680. RiskControlCore.Refresh();
  681. TkConfigCore.Refresh();
  682. EndPointCore.Refresh();
  683. ProxyNodesCore.Refresh();
  684. TkPoolCore.Refresh();
  685. VeapiPoolCore.Refresh();
  686. ApiAccountCore.Refresh();
  687. DataokeCore.Refresh();
  688. JdPoolCore.Refresh();
  689. PddPoolCore.Refresh();
  690. PangolinPoolCore.Refresh();
  691. ReduPoolCore.Refresh();
  692. //ElePoolCore.Refresh();
  693. //MeituanPoolCore.Refresh();
  694. CpsPoolCore.Refresh();
  695. DeeplinkParseRuleCore.Refresh();
  696. return new APIResult(new
  697. {
  698. success = true,
  699. message = "ok",
  700. });
  701. }
  702. [HttpGet]
  703. public ActionResult ReloadAccount()
  704. {
  705. RiskControlCore.Refresh();
  706. EndPointCore.Refresh();
  707. ProxyNodesCore.Refresh();
  708. TkPoolCore.Refresh();
  709. VeapiPoolCore.Refresh();
  710. JdPoolCore.Refresh();
  711. PddPoolCore.Refresh();
  712. //ElePoolCore.Refresh();
  713. //MeituanPoolCore.Refresh();
  714. CpsPoolCore.Refresh();
  715. return new APIResult(new
  716. {
  717. success = true,
  718. message = "ok",
  719. });
  720. }
  721. [HttpGet]
  722. public async Task<ActionResult> CheckDeepUrl(int accountid)
  723. {
  724. var postContent = "88✔7Fi43dJwWpV£ https://m.tb.cn/h.g92hfR4JLgn7yvG MF7997 我分享给你了一个超赞的内容,快来看看吧";
  725. var channel = "tb";
  726. var ip = "127.0.0.1";
  727. var oaid = "test-oaid";
  728. bool success = false;
  729. string message;
  730. //============================== 放弃转链-没有匹配账号 ==============================
  731. TkPoolDTO? account = TkPoolCore.GetOne(accountid);
  732. if (account == null)
  733. {
  734. return new APIResult(new
  735. {
  736. success = false,
  737. message = "没有匹配账号",
  738. });
  739. }
  740. var alimama = new AlimamaPlus(account);
  741. TkDataDTO result = new TkDataDTO();
  742. string url = AlimamaPlus.GetLink(postContent);
  743. if (string.IsNullOrEmpty(url))
  744. {
  745. return new APIResult(new
  746. {
  747. success = false,
  748. message = "无效URL",
  749. });
  750. }
  751. (success, string content) = await alimama.GetDesiredUrlAsync(url);
  752. if (content.Contains("霸下通用 web 页面-验证码"))
  753. {
  754. message = "霸下验证码";
  755. }
  756. else
  757. {
  758. message = content;
  759. }
  760. return new APIResult(new
  761. {
  762. success = true,
  763. message,
  764. });
  765. }
  766. }
  767. }