TkController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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.Security.Cryptography;
  9. using Microsoft.AspNetCore.Authentication;
  10. using TencentCloud.Ecm.V20190719.Models;
  11. using COSXML.Network;
  12. using System.Linq;
  13. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  14. namespace molilian.api.Controllers
  15. {
  16. [ApiController]
  17. [Route("[controller]/[action]")]
  18. public class TkController : ControllerBase
  19. {
  20. protected IHttpContextAccessor _accessor;
  21. public TkController(IHttpContextAccessor accessor)
  22. {
  23. _accessor = accessor;
  24. }
  25. [HttpPost]
  26. [Route("/[action]")]
  27. public async Task<ActionResult> PromotionQuery([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  28. {
  29. var img = form.Read("img", string.Empty);
  30. var url = form.Read("url", string.Empty);
  31. var ip = form.Read("ip", string.Empty);
  32. var oaid = form.Read("oaid", string.Empty);
  33. //验证签名
  34. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  35. {
  36. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  37. }
  38. DateTime time1 = t.Convert2Datetime();
  39. if (time1 < DateTime.Now.AddMinutes(-10))
  40. {
  41. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  42. }
  43. var account = ApiAccountCore.GetOne(a);
  44. if (account == null)
  45. {
  46. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  47. }
  48. string app_sign = $"{account.api_secret}@{t}".MD5();
  49. if (sign != app_sign)
  50. {
  51. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  52. }
  53. if (!string.IsNullOrEmpty(url))
  54. {
  55. var bytes = new WebClientUtility().Request(url).ResponseBody;
  56. img = Convert.ToBase64String(bytes);
  57. }
  58. return await TaokeOpenCore.PromotionQueryAsync(img, oaid, ip);
  59. }
  60. [HttpPost]
  61. [Route("/[action]")]
  62. public async Task<ActionResult> unsafePromotionQuery([FromBody] JsonElement form)
  63. {
  64. var img = form.Read("img", string.Empty);
  65. var url = form.Read("url", string.Empty);
  66. var ip = form.Read("ip", string.Empty);
  67. var oaid = form.Read("oaid", string.Empty);
  68. #if DEBUG
  69. ip = "127.0.0.1";
  70. oaid = "test-oaid";
  71. #endif
  72. if (!string.IsNullOrEmpty(url))
  73. {
  74. var bytes = new WebClientUtility().Request(url).ResponseBody;
  75. img = Convert.ToBase64String(bytes);
  76. }
  77. return await TaokeOpenCore.PromotionQueryAsync(img, oaid, ip);
  78. }
  79. /// <summary>
  80. /// oppo调用
  81. /// </summary>
  82. /// <param name="s">正文</param>
  83. /// <param name="c">渠道。tb/jd</param>
  84. /// <param name="a">分配的客户端账号</param>
  85. /// <param name="t">11位时间戳</param>
  86. /// <param name="sign">签名</param>
  87. /// <param name="ip">客户的IP</param>
  88. /// <param name="oaid">客户的唯一ID</param>
  89. /// <returns></returns>
  90. [HttpPost]
  91. public async Task<ActionResult> unionParse([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  92. {
  93. //正文
  94. var content = form.Read("s", string.Empty);
  95. var channel = form.Read("c", string.Empty);
  96. var ip = form.Read("ip", string.Empty);
  97. var oaid = form.Read("oaid", string.Empty);
  98. //验证签名
  99. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  100. {
  101. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  102. }
  103. DateTime time1 = t.Convert2Datetime();
  104. if (time1 < DateTime.Now.AddMinutes(-10))
  105. {
  106. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  107. }
  108. var account = ApiAccountCore.GetOne(a);
  109. if (account == null)
  110. {
  111. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  112. }
  113. string app_sign = $"{account.api_secret}@{t}".MD5();
  114. if (sign != app_sign)
  115. {
  116. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  117. }
  118. return await UnionParseCore.UnionParseAsync(content, channel, ip, oaid);
  119. }
  120. [HttpPost]
  121. public async Task<ActionResult> unsafeParse([FromBody] JsonElement form)
  122. {
  123. var content = form.Read("s", string.Empty);
  124. var channel = form.Read("c", string.Empty);
  125. var ip = form.Read("ip", string.Empty);
  126. var oaid = form.Read("oaid", string.Empty);
  127. int accountid = form.Read("aid", 0);
  128. #if DEBUG
  129. ip = "127.0.0.1";
  130. oaid = "test-oaid";
  131. #endif
  132. return await UnionParseCore.UnionParseAsync(content, channel, ip, oaid, accountid);
  133. }
  134. //[HttpGet]
  135. //public async Task<ActionResult> testParse()
  136. //{
  137. // var ip = "127.0.0.1";
  138. // var oaid = "test-oaid";
  139. // var list = new DBContext.Table("tk_parse_logs")
  140. // .Where("success=1", null)
  141. // .Order("ID DESC")
  142. // .Limit(1000)
  143. // .Select<TkDataDTO>();
  144. // int success_total = 0, error_total = 0;
  145. // foreach (var item in list)
  146. // {
  147. // var result = UnionParseCore.testTaobaoParseAsync(item.rawContent, ip, oaid);
  148. // if (result.success)
  149. // {
  150. // success_total++;
  151. // }
  152. // else
  153. // {
  154. // Console.Write(result);
  155. // }
  156. // }
  157. // var list2 = new DBContext.Table("tk_parse_logs")
  158. // .Where("success=0", null)
  159. // .Order("ID DESC")
  160. // .Limit(100)
  161. // .Select<TkDataDTO>();
  162. // foreach (var item in list2)
  163. // {
  164. // var result = UnionParseCore.testTaobaoParseAsync(item.rawContent, ip, oaid);
  165. // if (result.success)
  166. // {
  167. // Console.Write(result);
  168. // }
  169. // else
  170. // {
  171. // error_total++;
  172. // }
  173. // }
  174. // return new APIResult(new { success_total, error_total });
  175. //}
  176. [HttpPost]
  177. public async Task<ActionResult> unionCoupon([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  178. {
  179. //正文
  180. var content = form.Read("s", string.Empty);
  181. var channel = form.Read("c", string.Empty);
  182. var ip = form.Read("ip", string.Empty);
  183. var oaid = form.Read("oaid", string.Empty);
  184. //验证签名
  185. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  186. {
  187. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  188. }
  189. DateTime time1 = t.Convert2Datetime();
  190. if (time1 < DateTime.Now.AddMinutes(-10))
  191. {
  192. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  193. }
  194. var account = ApiAccountCore.GetOne(a);
  195. if (account == null)
  196. {
  197. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  198. }
  199. string app_sign = $"{account.api_secret}@{t}".MD5();
  200. if (sign != app_sign)
  201. {
  202. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  203. }
  204. return await UnionCouponCore.UnionCouponAsync(content, channel, ip, oaid);
  205. }
  206. [HttpPost]
  207. public async Task<ActionResult> unsafeCoupon([FromBody] JsonElement form)
  208. {
  209. var content = form.Read("s", string.Empty);
  210. var channel = form.Read("c", string.Empty);
  211. var ip = form.Read("ip", string.Empty);
  212. var oaid = form.Read("oaid", string.Empty);
  213. #if DEBUG
  214. ip = "127.0.0.1";
  215. oaid = "test-oaid";
  216. #endif
  217. return await UnionCouponCore.UnionCouponAsync(content, channel, ip, oaid);
  218. }
  219. /// <summary>
  220. /// 第三方调用
  221. /// </summary>
  222. /// <param name="s"></param>
  223. /// <param name="s2"></param>
  224. /// <returns></returns>
  225. [HttpGet]
  226. public async Task<ActionResult> parse(string s, string s2 = "", string ip = "", string oaid = "")
  227. {
  228. AlimamaPlus alimama = null;
  229. ip = AlimamaPlus.OppoDecode(ip);
  230. oaid = AlimamaPlus.OppoDecode(oaid);
  231. var result = AlimamaPlus.GetFormattedObject(s, ip, oaid);
  232. string body = "";
  233. string content = s.UrlDecode();
  234. string content2 = s2.UrlDecode();
  235. string account_name = string.Empty;
  236. result.rawContent = content;
  237. result.rawContent2 = content2;
  238. try
  239. {
  240. if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
  241. {
  242. result.success = false;
  243. result.message = "放弃转链";
  244. result.reason = reason;
  245. _ = TkLogCore.LogAsync(result);
  246. return new APIResult(new
  247. {
  248. result.success,
  249. result.message,
  250. result.content,
  251. result.couponAmount,
  252. result.taoToken,
  253. result.shortLinkurl,
  254. result.deeplink_url,
  255. });
  256. }
  257. var account = TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
  258. if (account == null)
  259. {
  260. result.success = false;
  261. result.message = "放弃转链";
  262. result.reason = "没有匹配账号";
  263. _ = TkLogCore.LogAsync(result);
  264. return new APIResult(new
  265. {
  266. result.success,
  267. result.message,
  268. result.content,
  269. result.couponAmount,
  270. result.taoToken,
  271. result.shortLinkurl,
  272. result.deeplink_url,
  273. });
  274. }
  275. result.accountId = account.id;
  276. result.accountName = account.company;
  277. account_name = account.name;
  278. alimama = new AlimamaPlus(account);
  279. if (alimama.ShouldIgnoreOtherAff(s2))
  280. {
  281. result.success = false;
  282. result.message = "放弃转链";
  283. result.reason = "其他推广链接";
  284. _ = TkLogCore.LogAsync(result);
  285. return new APIResult(new
  286. {
  287. result.success,
  288. result.message,
  289. result.content,
  290. result.couponAmount,
  291. result.taoToken,
  292. result.shortLinkurl,
  293. result.deeplink_url,
  294. });
  295. }
  296. result = await alimama.UnionParseAsync(content, result);
  297. }
  298. catch (Exception ex)
  299. {
  300. if (ex.Message.Contains("was canceled"))
  301. {
  302. result.success = false;
  303. result.message = "放弃转链";
  304. result.reason = "请求超时";
  305. }
  306. else
  307. {
  308. //new LoggerLibrary("api_error", "parse")
  309. //.Info(s, s2)
  310. //.Info($"【taobao】{account_name}", body)
  311. //.Info(ex.Message, ex.StackTrace)
  312. //.SaveAsync();
  313. NotifyCore.Notify(new NifyMessage
  314. {
  315. message = $"【转链接口异常】{result.accountName}\n{content}\n{content2}\n{body}\n\n{ex.Message}\n{ex.StackTrace}",
  316. priority = NifyMessagePriority.high,
  317. tags = ["red_circle"]
  318. });
  319. result.success = false;
  320. result.message = "放弃转链";
  321. result.reason = "转链接口异常";
  322. }
  323. }
  324. _ = TkLogCore.LogAsync(result, alimama);
  325. return new APIResult(new
  326. {
  327. result.success,
  328. result.message,
  329. result.content,
  330. result.couponAmount,
  331. result.taoToken,
  332. result.shortLinkurl,
  333. result.deeplink_url,
  334. });
  335. }
  336. [HttpGet]
  337. public ActionResult parse2(string s, string s2 = "", string ip = "", string oaid = "")
  338. {
  339. AlimamaPlus alimama = null;
  340. ip = AlimamaPlus.OppoDecode(ip);
  341. oaid = AlimamaPlus.OppoDecode(oaid);
  342. var result = AlimamaPlus.GetFormattedObject(s, ip, oaid);
  343. string body = "";
  344. string content = s.UrlDecode();
  345. string content2 = s2.UrlDecode();
  346. string account_name = string.Empty;
  347. result.rawContent = content;
  348. result.rawContent2 = content2;
  349. try
  350. {
  351. if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
  352. {
  353. result.success = false;
  354. result.message = "放弃转链";
  355. result.reason = reason;
  356. _ = TkLogCore.LogAsync(result);
  357. return new APIResult(new
  358. {
  359. result.success,
  360. result.message,
  361. result.content,
  362. result.couponAmount,
  363. result.taoToken,
  364. result.shortLinkurl,
  365. result.deeplink_url,
  366. });
  367. }
  368. var account = TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
  369. if (account == null)
  370. {
  371. result.success = false;
  372. result.message = "放弃转链";
  373. result.reason = "没有匹配账号";
  374. _ = TkLogCore.LogAsync(result);
  375. return new APIResult(new
  376. {
  377. result.success,
  378. result.message,
  379. result.content,
  380. result.couponAmount,
  381. result.taoToken,
  382. result.shortLinkurl,
  383. result.deeplink_url,
  384. });
  385. }
  386. account_name = account.name;
  387. alimama = new AlimamaPlus(account);
  388. if (alimama.ShouldIgnoreOtherAff(s2))
  389. {
  390. result.success = false;
  391. result.message = "放弃转链";
  392. result.reason = "其他推广链接";
  393. _ = TkLogCore.LogAsync(result);
  394. return new APIResult(new
  395. {
  396. result.success,
  397. result.message,
  398. result.content,
  399. result.couponAmount,
  400. result.taoToken,
  401. result.shortLinkurl,
  402. result.deeplink_url,
  403. });
  404. }
  405. alimama.UnionParse(content, ref result);
  406. //result.ip = ip;
  407. //result.oaid = oaid;
  408. }
  409. catch (Exception ex)
  410. {
  411. _ = new LoggerLibrary("api_error", "parse")
  412. .Info(s, s2)
  413. .Info($"【taobao】{account_name}", body)
  414. .Info(ex.Message, ex.StackTrace)
  415. .SaveAsync();
  416. NotifyCore.Notify(new NifyMessage
  417. {
  418. message = $"【转链接口异常】{account_name}\n{content}\n{content2}\n{body}\n\n{ex.Message}\n{ex.StackTrace}",
  419. priority = NifyMessagePriority.high,
  420. tags = ["red_circle"]
  421. });
  422. result.success = false;
  423. result.message = "放弃转链";
  424. result.reason = "转链接口异常";
  425. }
  426. _ = TkLogCore.LogAsync(result, alimama);
  427. return new APIResult(new
  428. {
  429. result.success,
  430. result.message,
  431. result.content,
  432. result.couponAmount,
  433. result.taoToken,
  434. result.shortLinkurl,
  435. result.deeplink_url,
  436. });
  437. }
  438. [HttpGet]
  439. public ActionResult jd_parse(string s, string s2 = "", string ip = "", string oaid = "")
  440. {
  441. var result = JdUnionPlus.GetFormattedObject(s, ip, oaid);
  442. string body = "";
  443. string content = s.UrlDecode();
  444. string content2 = s2.UrlDecode();
  445. try
  446. {
  447. if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
  448. {
  449. result.success = false;
  450. result.message = "放弃转链";
  451. result.reason = reason;
  452. result.rawContent = content;
  453. result.rawContent2 = content2;
  454. _ = TkLogCore.LogAsync(result);
  455. return new APIResult(result);
  456. }
  457. var api = DataokeCore.GetOne();
  458. if (api == null)
  459. {
  460. result.success = false;
  461. result.message = "放弃转链";
  462. result.reason = "没有匹配账号";
  463. result.rawContent = content;
  464. result.rawContent2 = content2;
  465. _ = TkLogCore.LogAsync(result);
  466. return new APIResult(result);
  467. }
  468. var account = JdPoolCore.GetOne();
  469. if (account == null)
  470. {
  471. result.success = false;
  472. result.message = "放弃转链";
  473. result.reason = "没有匹配账号";
  474. result.rawContent = content;
  475. result.rawContent2 = content2;
  476. _ = TkLogCore.LogAsync(result);
  477. return new APIResult(result);
  478. }
  479. result = DataokeCore.JdParse(result, api, account, content);
  480. }
  481. catch (Exception ex)
  482. {
  483. _ = new LoggerLibrary("api_error")
  484. .Info(s, s2)
  485. .Info("【jd】", body)
  486. .Info(ex.Message, ex.StackTrace)
  487. .SaveAsync();
  488. NotifyCore.Notify(new NifyMessage
  489. {
  490. message = $"【转链接口异常】\n{content}\n{content2}\n{body}\n\n{ex.Message}\n{ex.StackTrace}",
  491. priority = NifyMessagePriority.high,
  492. tags = ["red_circle"]
  493. });
  494. result.success = false;
  495. result.message = "放弃转链";
  496. result.reason = "转链接口异常";
  497. }
  498. result.rawContent = content;
  499. result.rawContent2 = content2;
  500. _ = TkLogCore.LogAsync(result);
  501. return new APIResult(new
  502. {
  503. result.success,
  504. result.message,
  505. result.shortLinkurl,
  506. result.itemId,
  507. result.itemName,
  508. result.deeplink_url,
  509. });
  510. }
  511. //[HttpGet]
  512. //public Task<ActionResult> parse3(string s, string s2, string ip = "", string oaid = "")
  513. //{
  514. // var result = AlimamaPlus.GetFormattedObject(s, ip, oaid);
  515. // string body = "";
  516. // string content = s.UrlDecode();
  517. // string content2 = s2.UrlDecode();
  518. // try
  519. // {
  520. // if (AlimamaPlus.ShouldIgnoreRequest("", ""))
  521. // {
  522. // result.success = false;
  523. // result.message = "放弃转链";
  524. // }
  525. // else
  526. // {
  527. // var account = VeapiPoolCore.GetOne();
  528. // if (account == null)
  529. // {
  530. // result.success = false;
  531. // result.message = "内部错误(500)";
  532. // }
  533. // else
  534. // {
  535. // var core = new VeapiPlus(account.name, account.key, account.sessionKey);
  536. // result = core.UnionParse(content);
  537. // }
  538. // }
  539. // }
  540. // catch (Exception ex)
  541. // {
  542. // NotifyCore.Notify(new NifyMessage
  543. // {
  544. // message = $"【转链接口异常】\n{body}",
  545. // priority = NifyMessagePriority.high,
  546. // tags = ["red_circle"]
  547. // });
  548. // result.success = false;
  549. // result.message = "转链接口异常";
  550. // }
  551. // _ = TkLogCore.Log(content, content2, result);
  552. // return Task.FromResult<ActionResult>(new APIResult(result));
  553. //}
  554. [HttpGet("{ignorePercentage}")]
  555. public ActionResult set_ignore(int ignorePercentage = 0)
  556. {
  557. TkConfigCore.Update(ignorePercentage);
  558. return new APIResult(new { success = true, message = "ok" });
  559. }
  560. [HttpGet("{ignorePercentage}")]
  561. public ActionResult set_jd_ignore(int ignorePercentage = 0)
  562. {
  563. TkConfigCore.JdUpdate(ignorePercentage);
  564. return new APIResult(new { success = true, message = "ok" });
  565. }
  566. [HttpGet]
  567. public async Task<ActionResult> Reload()
  568. {
  569. await EndPointCore.NotifyReload();
  570. return new APIResult(new
  571. {
  572. success = true,
  573. message = "ok",
  574. });
  575. }
  576. [HttpGet]
  577. public async Task<ActionResult> dplist([FromQuery] string query = "", [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
  578. {
  579. #if DEBUG
  580. #else
  581. //验证签名
  582. if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
  583. {
  584. return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
  585. }
  586. DateTime time1 = t.Convert2Datetime();
  587. if (time1 < DateTime.Now.AddMinutes(-10))
  588. {
  589. return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
  590. }
  591. var account = ApiAccountCore.GetOne(a);
  592. if (account == null)
  593. {
  594. return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
  595. }
  596. string app_sign = $"{account.api_secret}@{t}".MD5();
  597. if (sign != app_sign)
  598. {
  599. return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
  600. }
  601. if (string.IsNullOrEmpty(query))
  602. {
  603. return new APIResult(new { success = false, message = "查询条件不能为空" });
  604. }
  605. #endif
  606. string filter = $"batchId=@query";
  607. var account_list = TkPoolCore.List();
  608. List<int> account_ids = [];
  609. if (account_list.Any())
  610. {
  611. account_ids = account_list.Where(e => e.enable_fake_click).Select(e => e.id).ToList();
  612. filter += $" AND accountId IN @account_ids";
  613. }
  614. string orderBy = "paid_time ASC";
  615. var data = new DBContext.Table("tk_order_tracking")
  616. .Where(filter, new { query, account_ids })
  617. .Order(orderBy)
  618. .Select<TkOrderTrackingDTO>();
  619. List<object> list = [];
  620. foreach (var item in data)
  621. {
  622. list.Add(new { url = item.deeplinkUrl, item.shortLinkUrl, count = item.click_num, time = item.exp_time });
  623. }
  624. var clientIp = _accessor.HttpContext.GetUserIp();
  625. LoggerLibrary log = new LoggerLibrary("api", "dplist");
  626. log.Info($"{clientIp}\t{query}\tcount:{list.Count}");
  627. var ids = data.Select(e => e.Id).ToArray();
  628. log.Info(string.Join(',', ids));
  629. _ = log.SaveAsync();
  630. return new APIResult(new
  631. {
  632. success = true,
  633. message = list.Count == 0 ? "none" : "ok",
  634. count = list.Count,
  635. data = list,
  636. });
  637. }
  638. [HttpGet]
  639. public async Task<ActionResult> unsafeParseDpList([FromQuery] string query = "")
  640. {
  641. string filter = $"batchId=@query";
  642. var account_list = TkPoolCore.List();
  643. List<int> account_ids = [];
  644. if (account_list.Any())
  645. {
  646. account_ids = account_list.Where(e => e.enable_fake_click).Select(e => e.id).ToList();
  647. filter += $" AND accountId IN @account_ids";
  648. }
  649. string orderBy = "paid_time ASC";
  650. var data = new DBContext.Table("tk_order_tracking")
  651. .Where(filter, new { query, account_ids })
  652. .Order(orderBy)
  653. .Select<TkOrderTrackingDTO>();
  654. List<object> list = [];
  655. foreach (var item in data)
  656. {
  657. list.Add(new { url = item.deeplinkUrl, item.shortLinkUrl, count = item.click_num, time = item.exp_time });
  658. }
  659. var clientIp = _accessor.HttpContext.GetUserIp();
  660. LoggerLibrary log = new LoggerLibrary("api", "unsafeParseDpList");
  661. log.Info($"{clientIp}\t{query}\tcount:{list.Count}");
  662. var ids = data.Select(e => e.Id).ToArray();
  663. log.Info(string.Join(',', ids));
  664. _ = log.SaveAsync();
  665. return new APIResult(new
  666. {
  667. success = true,
  668. message = list.Count == 0 ? "none" : "ok",
  669. count = list.Count,
  670. data = list,
  671. });
  672. }
  673. }
  674. }