TkController.cs 27 KB

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