orders.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. using dodohold.core;
  2. using System.Text.Json;
  3. namespace molilian.core
  4. {
  5. public partial class AlimamaPlus
  6. {
  7. private const string base_orders_url = "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json";
  8. public async Task<int> GetHistoryOrdersAsync(int sleep, DateTime startTime, DateTime endTime)
  9. {
  10. //DateTime endTime = DateTime.Now;
  11. //DateTime startTime = endTime.AddDays(-90);
  12. //if (_accountId == 3) endTime = DateTime.Parse("2024-04-07");
  13. //#if DEBUG
  14. // startTime = DateTime.Parse("2024-05-01");
  15. // endTime = DateTime.Parse("2024-06-01");
  16. // int total = 0;
  17. // List<DateTime> orderTimes = new List<DateTime>();
  18. // for (DateTime date = startTime; date <= endTime; date = date.AddDays(1))
  19. // {
  20. // orderTimes.Add(date);
  21. // }
  22. //#else
  23. //#endif
  24. //当日往前查询
  25. (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = await GetTkOrdersAsync(startTime, endTime, DateTime.MinValue, false, sleep);
  26. if (_account.is_hide) return total;
  27. string sql = @"
  28. UPDATE tk_report tr
  29. JOIN (
  30. SELECT
  31. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  32. COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
  33. FROM tk_order_details
  34. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@accountId
  35. GROUP BY DATE(tbPaidTime), accountId
  36. ) AS sub
  37. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  38. SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_num_3 = sub.order_ord_num,
  39. tr.order_ord_tfee = sub.order_ord_tfee;";
  40. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  41. sql = @"
  42. UPDATE tk_report tr
  43. JOIN (
  44. SELECT
  45. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  46. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  47. FROM tk_order_details
  48. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
  49. GROUP BY DATE(tbPaidTime), accountId
  50. ) AS sub
  51. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  52. SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_num_12 = sub.order_ord_num,
  53. tr.order_ord_tfee_12 = sub.order_ord_tfee;";
  54. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  55. sql = @"
  56. UPDATE tk_report tr
  57. JOIN (
  58. SELECT
  59. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  60. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  61. FROM tk_order_details
  62. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
  63. GROUP BY DATE(tbPaidTime), accountId
  64. ) AS sub
  65. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  66. SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_num_13 = sub.order_ord_num,
  67. tr.order_ord_tfee_13 = sub.order_ord_tfee;";
  68. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  69. sql = @"
  70. UPDATE tk_report tr
  71. JOIN (
  72. SELECT
  73. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  74. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  75. FROM tk_order_details
  76. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
  77. GROUP BY DATE(tbPaidTime), accountId
  78. ) AS sub
  79. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  80. SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_num_14 = sub.order_ord_num,
  81. tr.order_ord_tfee_14 = sub.order_ord_tfee;";
  82. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  83. sql = @"UPDATE tk_report
  84. SET order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
  85. WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
  86. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  87. return total;
  88. }
  89. public async Task<int> GetIncyOrdersAsync(int sleep)
  90. {
  91. string cacheKey = $":cache:GetIncyOrders:{_accountName}";
  92. string cacheKey2 = $":cache:GetIncyOrders:{_accountId}";
  93. DateTime endTime = DateTime.Now;
  94. DateTime startTime = endTime.AddDays(-1);
  95. DateTime last_modifiedTime = RedisHelper.Get<DateTime>(cacheKey);
  96. ////找出数据库最新的一天
  97. //var last = new DBContext.Table("tk_order_details")
  98. // .Order("modifiedTime DESC")
  99. // .Get<TkOrderDetailDTO>("accountId=@accountId", new { accountId = _accountId });
  100. if (last_modifiedTime != DateTime.MinValue)
  101. {
  102. startTime = last_modifiedTime;
  103. }
  104. else
  105. {
  106. last_modifiedTime = startTime;
  107. }
  108. //当日往前查询
  109. (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = await GetTkOrdersAsync(startTime, endTime, last_modifiedTime, true, sleep);
  110. if (max_modifiedTime != DateTime.MinValue)
  111. {
  112. RedisHelper.Set(cacheKey, max_modifiedTime);
  113. RedisHelper.Set(cacheKey2, max_modifiedTime);
  114. }
  115. if (_account.is_hide) return total;
  116. //todo 根据orderTimes、settlementTimes 更新被影响的相关行
  117. string sql = @"
  118. UPDATE tk_report tr
  119. JOIN (
  120. SELECT
  121. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  122. COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
  123. FROM tk_order_details
  124. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@accountId
  125. GROUP BY DATE(tbPaidTime), accountId
  126. ) AS sub
  127. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  128. SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_num_3 = sub.order_ord_num,
  129. tr.order_ord_tfee = sub.order_ord_tfee;";
  130. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  131. sql = @"
  132. UPDATE tk_report tr
  133. JOIN (
  134. SELECT
  135. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  136. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  137. FROM tk_order_details
  138. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
  139. GROUP BY DATE(tbPaidTime), accountId
  140. ) AS sub
  141. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  142. SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_num_12 = sub.order_ord_num,
  143. tr.order_ord_tfee_12 = sub.order_ord_tfee;";
  144. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  145. sql = @"
  146. UPDATE tk_report tr
  147. JOIN (
  148. SELECT
  149. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  150. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  151. FROM tk_order_details
  152. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
  153. GROUP BY DATE(tbPaidTime), accountId
  154. ) AS sub
  155. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  156. SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_num_13 = sub.order_ord_num,
  157. tr.order_ord_tfee_13 = sub.order_ord_tfee;";
  158. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  159. sql = @"
  160. UPDATE tk_report tr
  161. JOIN (
  162. SELECT
  163. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  164. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  165. FROM tk_order_details
  166. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
  167. GROUP BY DATE(tbPaidTime), accountId
  168. ) AS sub
  169. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  170. SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_num_14 = sub.order_ord_num,
  171. tr.order_ord_tfee_14 = sub.order_ord_tfee;";
  172. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  173. sql = @"UPDATE tk_report
  174. SET order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
  175. WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
  176. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  177. return total;
  178. }
  179. public async Task<int> GetOrdersByAdZoneAsync(long adzoneId, DateTime startTime, DateTime endTime, int sleep)
  180. {
  181. string cacheKey = $":cache:GetOrdersByAdZone:{_accountName}";
  182. string cacheKey2 = $":cache:GetOrdersByAdZone:{_accountId}";
  183. DateTime last_modifiedTime = RedisHelper.Get<DateTime>(cacheKey);
  184. if (last_modifiedTime != DateTime.MinValue)
  185. {
  186. startTime = last_modifiedTime;
  187. }
  188. else
  189. {
  190. last_modifiedTime = startTime;
  191. }
  192. //当日往前查询
  193. (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = await GetTkOrdersByAdZoneAsync(adzoneId, startTime, endTime, last_modifiedTime, true, sleep);
  194. if (max_modifiedTime != DateTime.MinValue)
  195. {
  196. RedisHelper.Set(cacheKey, max_modifiedTime);
  197. RedisHelper.Set(cacheKey2, max_modifiedTime);
  198. }
  199. return total;
  200. }
  201. public async Task<(int, DateTime, List<DateTime>)> GetTkOrdersByAdZoneAsync(long adzoneId, DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
  202. {
  203. List<DateTime> orderTimes = [];
  204. if (startTime > endTime)
  205. {
  206. (startTime, endTime) = (endTime, startTime);
  207. }
  208. DateTime max_modifiedTime = last_modifiedTime;
  209. int pageNo = 1;
  210. string positionIndex = string.Empty;
  211. int pageSize = 100;
  212. bool hasNext = true;
  213. int total = 0;
  214. while (hasNext)
  215. {
  216. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  217. string jumpType = pageNo == 1 ? "0" : "1";
  218. #if DEBUG
  219. jumpType = pageNo == 1 ? "0" : "1";
  220. #endif
  221. string queryType = desc ? "4" : "2";
  222. string url = $"{base_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&jumpType={jumpType}&tkTradeId=&positionIndex={positionIndex.UrlEncode()}";
  223. string body = "";
  224. JsonElement data;
  225. try
  226. {
  227. for (var i = 1; i <= 5; i++)
  228. {
  229. var client = new WebClientUtility().SetContentType("application/json;charset=utf-8")
  230. .AddHeaders("X-Requested-With", "XMLHttpRequest")
  231. .AddHeaders("Cookie", _cookies);
  232. #if DEBUG
  233. #else
  234. client.Proxy = _proxy;
  235. #endif
  236. if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
  237. var response = client.Request(url);
  238. if (response.ResponseException != null)
  239. {
  240. _ = new LoggerLibrary("api_error", "fail")
  241. .Info(response.ResponseException.Message, response.ResponseException.StackTrace)
  242. .SaveAsync();
  243. throw response.ResponseException;
  244. }
  245. body = response.Body();
  246. #if DEBUG
  247. _ = new LoggerLibrary("debug", "GetTkOrdersByAdZone")
  248. .Info(body)
  249. .SaveAsync();
  250. #endif
  251. if (body.Contains("{\"action\":\"captcha\""))
  252. {
  253. string message = $"【GetTkOrdersByAdZone】【{_accountId}:{_accountName}】第 {i} 次出现滑动验证码";
  254. NotifyCore.Notify(new NifyMessage
  255. {
  256. message = message,
  257. priority = NifyMessagePriority.high,
  258. tags = ["red_circle"]
  259. });
  260. if (!_account.is_hide)
  261. {
  262. _ = NotifyCore.QYWeixinPushNotifyAsync("GetTkOrders【出现滑动验证码】", message);
  263. }
  264. await Task.Delay(i * 60 * 1000);
  265. continue;
  266. }
  267. if (body.Contains("\"resultCode\":500"))
  268. {
  269. string message = $"【GetTkOrdersByAdZone】【{_accountId}:{_accountName}】第 {i} 次出现错误\n{body}";
  270. NotifyCore.Notify(new NifyMessage
  271. {
  272. message = message,
  273. priority = NifyMessagePriority.high,
  274. tags = ["red_circle"]
  275. });
  276. await Task.Delay(i * 60 * 1000);
  277. continue;
  278. }
  279. break;
  280. }
  281. var root = body.Convert2JsonElement();
  282. var success = root.Read<bool>("success");
  283. data = root.ElementRead("data");
  284. if (!success && body.Contains("nologin"))
  285. {
  286. (success, string message) = RenewCookie();
  287. if (!success)
  288. {
  289. TkPoolCore.Disabled(_accountId, _accountName, $"{body}", _account.is_hide);
  290. }
  291. return (0, DateTime.MinValue, new List<DateTime>());
  292. }
  293. if (!success)
  294. {
  295. throw new APIException(body);
  296. }
  297. }
  298. catch (Exception ex)
  299. {
  300. throw new APIException(body);
  301. }
  302. using var conn = DBContext.GetOpenConnection();
  303. conn.Open();
  304. try
  305. {
  306. foreach (var order in data.ElementRead("result").EnumerateArray())
  307. {
  308. TkOrderDetailAdZoneDTO item = order.GetRawText().Convert2Object<TkOrderDetailAdZoneDTO>();
  309. // 处理每个订单数据
  310. if (item.adzoneId != adzoneId) continue;
  311. item.accountId = _accountId;
  312. item.accountName = _company;
  313. if (item.modifiedTime > max_modifiedTime) max_modifiedTime = item.modifiedTime;
  314. if (last_modifiedTime != DateTime.MinValue && last_modifiedTime >= item.modifiedTime)
  315. {
  316. return (total, max_modifiedTime, orderTimes);
  317. }
  318. if (item.tkStatus == 3 && item.tbPaidTime != DateTime.MinValue) orderTimes.Add(item.tbPaidTime.Date);
  319. int? id = conn.Replace(item);
  320. total++;
  321. }
  322. }
  323. catch (Exception ex)
  324. {
  325. throw;
  326. }
  327. finally
  328. {
  329. conn.Dispose();
  330. }
  331. pageNo++;
  332. hasNext = data.Read<bool>("hasNext");
  333. positionIndex = data.Read<string>("positionIndex");
  334. if (sleep > 0) await Task.Delay(sleep);
  335. }
  336. return (total, max_modifiedTime, orderTimes);
  337. }
  338. public async Task<(int, DateTime, List<DateTime>)> GetTkOrdersAsync(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
  339. {
  340. List<DateTime> orderTimes = [];
  341. // 确保 startTime 小于 endTime
  342. if (startTime > endTime)
  343. {
  344. (startTime, endTime) = (endTime, startTime);
  345. }
  346. DateTime max_modifiedTime = last_modifiedTime;
  347. int pageNo = 1;
  348. string positionIndex = string.Empty;
  349. int pageSize = 100;
  350. bool hasNext = true;
  351. int total = 0;
  352. while (hasNext)
  353. {
  354. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  355. //string jumpType = desc ? pageNo == 1 ? "0" : "1" : "-1";
  356. string jumpType = pageNo == 1 ? "0" : "1";
  357. #if DEBUG
  358. jumpType = pageNo == 1 ? "0" : "1";
  359. #endif
  360. //string queryType = "1";
  361. //1 创建时间;3结算时间 2付款时间 4更新时间
  362. //string queryType = "2";
  363. string queryType = desc ? "4" : "2";
  364. string url = $"{base_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&jumpType={jumpType}&tkTradeId=&positionIndex={positionIndex.UrlEncode()}";
  365. //https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json?t=1719477837298&_tb_token_=7537e7ed93338&pageNo=92&pageSize=20&startTime=2024-03-31&endTime=2024-03-31&payStatus=&queryType=2&jumpType=1&tkTradeId=&positionIndex=1711883373_2vtPPr7CyYX2%7C1711883522_4zcICUeUevh2
  366. //https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json?t=1719477942492&_tb_token_=7537e7ed93338&pageNo=7&pageSize=20&startTime=2024-03-31&endTime=2024-03-31&payStatus=&queryType=2&jumpType=1&tkTradeId=&positionIndex=1711899163_4zdpOH1mbTQ2%7C1711899483_4zbH9BHqgl82
  367. string body = "";
  368. JsonElement data;
  369. try
  370. {
  371. bool success = false;
  372. for (var i = 1; i <= 5; i++)
  373. {
  374. var client = new WebClientUtility().SetContentType("application/json;charset=utf-8")
  375. .AddHeaders("X-Requested-With", "XMLHttpRequest")
  376. .AddHeaders("Cookie", _cookies);
  377. #if DEBUG
  378. #else
  379. client.Proxy = _proxy;
  380. #endif
  381. if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
  382. var response = client.Request(url);
  383. if (response.ResponseException != null)
  384. {
  385. _ = new LoggerLibrary("api_error", "fail")
  386. .Info(response.ResponseException.Message, response.ResponseException.StackTrace)
  387. .SaveAsync();
  388. throw response.ResponseException;
  389. }
  390. body = response.Body();
  391. _ = new LoggerLibrary("debug", "GetTkOrders")
  392. .Info(body)
  393. .SaveAsync();
  394. #if DEBUG
  395. body = "<a id=\"a-link\"></a>\r\n<script>\r\n localStorage.x5referer = \"https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json?t=1753926991809&_tb_token_=63a173be-1d48-4b35-9365-c9e88d80bd22&pageNo=1&pageSize=100&startTime=2025-07-31&endTime=2025-07-31&payStatus=&queryType=4&jumpType=0&tkTradeId=&positionIndex=\";\t\r\n var link = document.getElementById(\"a-link\");\r\n var isMobile = navigator.userAgent.match(/.*(iPhone|iPad|Android|ios|SymbianOS|Windows Phone).*/i);\r\n var host = isMobile ? \"https://login.m.taobao.com/login.htm?from=sm&ttid=h5@iframe&redirectURL=\" : \"https://login.taobao.com/member/login.jhtml?redirectURL=\";\r\n try {\r\n\tvar hostValue = window.location.host;\r\n\tvar parts = hostValue && hostValue.split('.');\r\n\tvar exp = new Date();\r\n\tvar maxAge = -100;\r\n\texp.setTime(exp.getTime() + maxAge);\r\n\tvar cookie = 'x5secdata=;maxAge=' + maxAge + ';expires=' + exp.toUTCString() + ';path=/;domain=.' + parts.slice(-2).join('.') + ';';\r\n\tdocument.cookie = cookie;\r\n\tdocument.cookie = cookie + 'Secure;SameSite=None';\r\n } catch(e) {}\r\n link.href = host + \"https%3a%2f%2fpub.alimama.com:443/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json%2F_____tmd_____%2Fpage%2Flogin_jump%3Frand%3DS3WxGHAgAt756EpznwfNzJq2AFA2qBNla3j6EINUS8We9dazM_iKElp8DwVSHZUevpC41Bx7RzivXIj9RnZgdg%26_lgt_%3Db3cd621c481534716e8a6746557d7819___315550___5c0b95bde5166ee3786b77616fa971f7___eaebc79cac1eb5d2f7d8b4595e00ec73344a42d5a0b8cf56539c823cd24ac06c20ec1211b42711a826d58cd8cc1119e8aeead8c3f9de63d3f506b5ed39a5726cb02971d4a9f502dbbd27c123102f3e837a98f6e85580eaccf7dc1693a9bfecc80fa5a006f894296684ae17bbd0aade11384dbaad7a6f2f5737085962fcc5af80ade51d97d2e647bab64fddca4d953edcddcdd4efcab95bde0aac94906316beed64dfc0747a2c2bccdd8dd524cefc683b5028ae43f400dfe7a9e046153cc6fc64915ffee67e86ab66ccfcc8264300c5965152ff3956aba31cae08472d1a4d65c3eafcd446c082ebfc155e4340468745122140eb8fe5a81dc799be2cb689849e0cdafb6de28903c5fe87717cf30f66324d86d4e68d65d250200d2d0f7a91452e483d4a43213597d5e2249ec2536825bd75918316a8d62033b9ebf7b284e2a36b48&uuid=b3cd621c481534716e8a6746557d7819\";\r\n link.click();\r\n window._config_ = {\r\n \"action\": \"login\",\r\n \"url\": \"https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&from=sm&full_redirect=false&redirectURL=https%3a%2f%2fpub.alimama.com:443/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json%2F_____tmd_____%2Fpage%2Fclose_iframe_page%3Frand%3DS3WxGHAgAt756EpznwfNzJq2AFA2qBNla3j6EINUS8We9dazM_iKElp8DwVSHZUevpC41Bx7RzivXIj9RnZgdg%26uuid%3Db3cd621c481534716e8a6746557d7819%26_lgt_%3Db3cd621c481534716e8a6746557d7819___315550___5c0b95bde5166ee3786b77616fa971f7___eaebc79cac1eb5d2f7d8b4595e00ec73344a42d5a0b8cf56539c823cd24ac06c20ec1211b42711a826d58cd8cc1119e8aeead8c3f9de63d3f506b5ed39a5726cb02971d4a9f502dbbd27c123102f3e837a98f6e85580eaccf7dc1693a9bfecc80fa5a006f894296684ae17bbd0aade11384dbaad7a6f2f5737085962fcc5af80ade51d97d2e647bab64fddca4d953edcddcdd4efcab95bde0aac94906316beed64dfc0747a2c2bccdd8dd524cefc683b5028ae43f400dfe7a9e046153cc6fc64915ffee67e86ab66ccfcc8264300c5965152ff3956aba31cae08472d1a4d65c3eafcd446c082ebfc155e4340468745122140eb8fe5a81dc799be2cb689849e0cdafb6de28903c5fe87717cf30f66324d86d4e68d65d250200d2d0f7a91452e483d4a43213597d5e2249ec2536825bd75918316a8d62033b9ebf7b284e2a36b48\",\r\n \"h5url\": \"https://login.m.taobao.com/login.htm?from=sm&ttid=h5@iframe&redirectURL=https%3a%2f%2fpub.alimama.com:443/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json%2F_____tmd_____%2Fpage%2Fclose_iframe_page%3Frand%3DS3WxGHAgAt756EpznwfNzJq2AFA2qBNla3j6EINUS8We9dazM_iKElp8DwVSHZUevpC41Bx7RzivXIj9RnZgdg%26uuid%3Db3cd621c481534716e8a6746557d7819%26_lgt_%3Db3cd621c481534716e8a6746557d7819___315550___5c0b95bde5166ee3786b77616fa971f7___eaebc79cac1eb5d2f7d8b4595e00ec73344a42d5a0b8cf56539c823cd24ac06c20ec1211b42711a826d58cd8cc1119e8aeead8c3f9de63d3f506b5ed39a5726cb02971d4a9f502dbbd27c123102f3e837a98f6e85580eaccf7dc1693a9bfecc80fa5a006f894296684ae17bbd0aade11384dbaad7a6f2f5737085962fcc5af80ade51d97d2e647bab64fddca4d953edcddcdd4efcab95bde0aac94906316beed64dfc0747a2c2bccdd8dd524cefc683b5028ae43f400dfe7a9e046153cc6fc64915ffee67e86ab66ccfcc8264300c5965152ff3956aba31cae08472d1a4d65c3eafcd446c082ebfc155e4340468745122140eb8fe5a81dc799be2cb689849e0cdafb6de28903c5fe87717cf30f66324d86d4e68d65d250200d2d0f7a91452e483d4a43213597d5e2249ec2536825bd75918316a8d62033b9ebf7b284e2a36b48\",\r\n \"dialogSize\": {\"width\": \"\", \"height\": \"\"}\r\n};\r\n</script>\r\n<!--rgv587_flag:sm-->\r\n2025-07-31 09:56:31.854\t\r\n<a id=\"a-link\"></a>\r\n<script>\r\n localStorage.x5referer = \"https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json?t=1753926991809&_tb_token_=63a173be-1d48-4b35-9365-c9e88d80bd22&pageNo=1&pageSize=100&startTime=2025-07-31&endTime=2025-07-31&payStatus=&queryType=4&jumpType=0&tkTradeId=&positionIndex=\";\t\r\n var link = document.getElementById(\"a-link\");\r\n var isMobile = navigator.userAgent.match(/.*(iPhone|iPad|Android|ios|SymbianOS|Windows Phone).*/i);\r\n var host = isMobile ? \"https://login.m.taobao.com/login.htm?from=sm&ttid=h5@iframe&redirectURL=\" : \"https://login.taobao.com/member/login.jhtml?redirectURL=\";\r\n try {\r\n\tvar hostValue = window.location.host;\r\n\tvar parts = hostValue && hostValue.split('.');\r\n\tvar exp = new Date();\r\n\tvar maxAge = -100;\r\n\texp.setTime(exp.getTime() + maxAge);\r\n\tvar cookie = 'x5secdata=;maxAge=' + maxAge + ';expires=' + exp.toUTCString() + ';path=/;domain=.' + parts.slice(-2).join('.') + ';';\r\n\tdocument.cookie = cookie;\r\n\tdocument.cookie = cookie + 'Secure;SameSite=None';\r\n } catch(e) {}\r\n link.href = host + \"https%3a%2f%2fpub.alimama.com:443/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json%2F_____tmd_____%2Fpage%2Flogin_jump%3Frand%3DS3WxGHAgAt756EpznwfNzJq2AFA2qBNla3j6EINUS8We9dazM_iKElp8DwVSHZUevpC41Bx7RzivXIj9RnZgdg%26_lgt_%3Db3cd621c481534716e8a6746557d7819___315550___5c0b95bde5166ee3786b77616fa971f7___eaebc79cac1eb5d2f7d8b4595e00ec73344a42d5a0b8cf56539c823cd24ac06c20ec1211b42711a826d58cd8cc1119e8aeead8c3f9de63d3f506b5ed39a5726cb02971d4a9f502dbbd27c123102f3e837a98f6e85580eaccf7dc1693a9bfecc80fa5a006f894296684ae17bbd0aade11384dbaad7a6f2f5737085962fcc5af80ade51d97d2e647bab64fddca4d953edcddcdd4efcab95bde0aac94906316beed64dfc0747a2c2bccdd8dd524cefc683b5028ae43f400dfe7a9e046153cc6fc64915ffee67e86ab66ccfcc8264300c5965152ff3956aba31cae08472d1a4d65c3eafcd446c082ebfc155e4340468745122140eb8fe5a81dc799be2cb689849e0cdafb6de28903c5fe87717cf30f66324d86d4e68d65d250200d2d0f7a91452e483d4a43213597d5e2249ec2536825bd75918316a8d62033b9ebf7b284e2a36b48&uuid=b3cd621c481534716e8a6746557d7819\";\r\n link.click();\r\n window._config_ = {\r\n \"action\": \"login\",\r\n \"url\": \"https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&from=sm&full_redirect=false&redirectURL=https%3a%2f%2fpub.alimama.com:443/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json%2F_____tmd_____%2Fpage%2Fclose_iframe_page%3Frand%3DS3WxGHAgAt756EpznwfNzJq2AFA2qBNla3j6EINUS8We9dazM_iKElp8DwVSHZUevpC41Bx7RzivXIj9RnZgdg%26uuid%3Db3cd621c481534716e8a6746557d7819%26_lgt_%3Db3cd621c481534716e8a6746557d7819___315550___5c0b95bde5166ee3786b77616fa971f7___eaebc79cac1eb5d2f7d8b4595e00ec73344a42d5a0b8cf56539c823cd24ac06c20ec1211b42711a826d58cd8cc1119e8aeead8c3f9de63d3f506b5ed39a5726cb02971d4a9f502dbbd27c123102f3e837a98f6e85580eaccf7dc1693a9bfecc80fa5a006f894296684ae17bbd0aade11384dbaad7a6f2f5737085962fcc5af80ade51d97d2e647bab64fddca4d953edcddcdd4efcab95bde0aac94906316beed64dfc0747a2c2bccdd8dd524cefc683b5028ae43f400dfe7a9e046153cc6fc64915ffee67e86ab66ccfcc8264300c5965152ff3956aba31cae08472d1a4d65c3eafcd446c082ebfc155e4340468745122140eb8fe5a81dc799be2cb689849e0cdafb6de28903c5fe87717cf30f66324d86d4e68d65d250200d2d0f7a91452e483d4a43213597d5e2249ec2536825bd75918316a8d62033b9ebf7b284e2a36b48\",\r\n \"h5url\": \"https://login.m.taobao.com/login.htm?from=sm&ttid=h5@iframe&redirectURL=https%3a%2f%2fpub.alimama.com:443/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json%2F_____tmd_____%2Fpage%2Fclose_iframe_page%3Frand%3DS3WxGHAgAt756EpznwfNzJq2AFA2qBNla3j6EINUS8We9dazM_iKElp8DwVSHZUevpC41Bx7RzivXIj9RnZgdg%26uuid%3Db3cd621c481534716e8a6746557d7819%26_lgt_%3Db3cd621c481534716e8a6746557d7819___315550___5c0b95bde5166ee3786b77616fa971f7___eaebc79cac1eb5d2f7d8b4595e00ec73344a42d5a0b8cf56539c823cd24ac06c20ec1211b42711a826d58cd8cc1119e8aeead8c3f9de63d3f506b5ed39a5726cb02971d4a9f502dbbd27c123102f3e837a98f6e85580eaccf7dc1693a9bfecc80fa5a006f894296684ae17bbd0aade11384dbaad7a6f2f5737085962fcc5af80ade51d97d2e647bab64fddca4d953edcddcdd4efcab95bde0aac94906316beed64dfc0747a2c2bccdd8dd524cefc683b5028ae43f400dfe7a9e046153cc6fc64915ffee67e86ab66ccfcc8264300c5965152ff3956aba31cae08472d1a4d65c3eafcd446c082ebfc155e4340468745122140eb8fe5a81dc799be2cb689849e0cdafb6de28903c5fe87717cf30f66324d86d4e68d65d250200d2d0f7a91452e483d4a43213597d5e2249ec2536825bd75918316a8d62033b9ebf7b284e2a36b48\",\r\n \"dialogSize\": {\"width\": \"\", \"height\": \"\"}\r\n};\r\n</script>\r\n<!--rgv587_flag:sm-->";
  396. #endif
  397. if (body.Contains("{\"action\":\"login\"") || body.Contains("\"action\": \"login\""))
  398. {
  399. (success, string message) = RenewCookie();
  400. if (!success)
  401. {
  402. TkPoolCore.Disabled(_accountId, _accountName, $"{body}", _account.is_hide);
  403. }
  404. return (0, DateTime.MinValue, new List<DateTime>());
  405. }
  406. if (body.Contains("{\"action\":\"captcha\""))
  407. {
  408. string message = $"【GetTkOrders】【{_accountId}:{_accountName}】第 {i} 次出现滑动验证码";
  409. NotifyCore.Notify(new NifyMessage
  410. {
  411. message = message,
  412. priority = NifyMessagePriority.high,
  413. tags = ["red_circle"]
  414. });
  415. if (!_account.is_hide)
  416. {
  417. _ = NotifyCore.QYWeixinPushNotifyAsync("GetTkOrders【出现滑动验证码】", message);
  418. }
  419. await Task.Delay(i * 60 * 1000);
  420. continue;
  421. }
  422. if (body.Contains("\"resultCode\":500"))
  423. {
  424. //{"success":false,"resultCode":500,"bizErrorDesc":"系统繁忙,请稍后重试!","bizErrorCode":3001}
  425. string message = $"【GetTkOrders】【{_accountId}:{_accountName}】第 {i} 次出现错误\n{body}";
  426. NotifyCore.Notify(new NifyMessage
  427. {
  428. message = message,
  429. priority = NifyMessagePriority.high,
  430. tags = ["red_circle"]
  431. });
  432. await Task.Delay(i * 60 * 1000);
  433. continue;
  434. }
  435. break;
  436. }
  437. /*
  438. <script>sessionStorage.x5referer = window.location.href;var url = window.location.protocol + "//pub.alimama.com//openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json/_____tmd_____/punish?x5secdata=xc1iwR0XfHknuQ2tGhtadtTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsVOy7o75Rw8uuycKT3Rpx30%2fB5H0gRc0%2fJVGQUcV5g%2fsAmZ%2bc46eyD7DXSdA4R3mLnmtbp9wuZ1vmrG3ZPlH7brUilFbXBdZ7EBrru1X7wPfC05Eq3g4mhDFiGq39xUtwQcC%2f%2bPbtekcm8%2fVJ%2brVt8aExunwzXzJPJJTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsiXIkw%2ffMWwebJ3zxCja5CzSu%2ffTA%3d%3d__bx__pub.alimama.com%2fopenapi%2fparam2%2f1%2fgateway.unionpub%2freport.getTbkOrderDetails.json&x5step=1";window.location.replace(url);window._config_ = {"action":"captcha","url":"https://pub.alimama.com//openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json/_____tmd_____/punish?x5secdata=xc1iwR0XfHknuQ2tGhtadtTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsVOy7o75Rw8uuycKT3Rpx30%2fB5H0gRc0%2fJVGQUcV5g%2fsAmZ%2bc46eyD7DXSdA4R3mLnmtbp9wuZ1vmrG3ZPlH7brUilFbXBdZ7EBrru1X7wPfC05Eq3g4mhDFiGq39xUtwQcC%2f%2bPbtekcm8%2fVJ%2brVt8aExunwzXzJPJJTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsiXIkw%2ffMWwebJ3zxCja5CzSu%2ffTA%3d%3d__bx__pub.alimama.com%2fopenapi%2fparam2%2f1%2fgateway.unionpub%2freport.getTbkOrderDetails.json&x5step=1"};</script><!--rgv587_flag:sm--> */
  439. var root = body.Convert2JsonElement();
  440. success = root.Read<bool>("success");
  441. data = root.ElementRead("data");
  442. //{"code":601,"info":{"ok":false,"message":"nologin"}}
  443. if (!success && body.Contains("nologin"))
  444. {
  445. (success, string message) = RenewCookie();
  446. if (!success)
  447. {
  448. TkPoolCore.Disabled(_accountId, _accountName, $"{body}", _account.is_hide);
  449. }
  450. return (0, DateTime.MinValue, new List<DateTime>());
  451. }
  452. if (!success)
  453. {
  454. throw new APIException(body);
  455. }
  456. }
  457. catch (Exception ex)
  458. {
  459. _ = new LoggerLibrary("debug", "GetTkOrders")
  460. .Info(body)
  461. .Info(ex.Message, ex.StackTrace)
  462. .SaveAsync();
  463. string message = $"【GetRawItemId】{_accountId}:{_accountName}\t{_proxy?.Address}\n" +
  464. $"{body}\n{ex.Message}\n{ex.StackTrace}";
  465. if (sleep > 0) await Task.Delay(sleep);
  466. throw new APIException(body);
  467. }
  468. try
  469. {
  470. foreach (var order in data.ElementRead("result").EnumerateArray())
  471. {
  472. TkOrderDetailDTO item = order.GetRawText().Convert2Object<TkOrderDetailDTO>();
  473. // 处理每个订单数据
  474. item.accountId = _accountId;
  475. item.accountName = _company;
  476. if (item.modifiedTime > max_modifiedTime) max_modifiedTime = item.modifiedTime;
  477. if (last_modifiedTime != DateTime.MinValue && last_modifiedTime >= item.modifiedTime)
  478. {
  479. return (total, max_modifiedTime, orderTimes);
  480. }
  481. //进行订单和转链匹配
  482. (int state, item.itemId) = GetRawItemId(item.mktId);
  483. if (item.tkStatus == 3 && item.tbPaidTime != DateTime.MinValue) orderTimes.Add(item.tbPaidTime.Date);
  484. using var conn = DBContext.GetOpenConnection();
  485. int? id = conn.Replace(item);
  486. if (id != null)
  487. {
  488. item.id = (int)id;
  489. TkOrderTrackingCore.MatchOrder(_account, item);
  490. }
  491. total++;
  492. }
  493. }
  494. catch (Exception ex)
  495. {
  496. if (sleep > 0) await Task.Delay(sleep);
  497. throw;
  498. }
  499. pageNo++;
  500. hasNext = data.Read<bool>("hasNext");
  501. positionIndex = data.Read<string>("positionIndex");
  502. if (sleep > 0) await Task.Delay(sleep);
  503. }
  504. return (total, max_modifiedTime, orderTimes);
  505. }
  506. public (int, string) GetRawItemId(string mktId)
  507. {
  508. ////
  509. ///
  510. string body = string.Empty, location = string.Empty;
  511. var proxy = ProxyNodesCore.RandomOne();
  512. try
  513. {
  514. string cacheKey = $":cache:mkt2itemId:{mktId}";
  515. string itemId = RedisHelper.Get(cacheKey);
  516. if (itemId != null) return (1, itemId);
  517. string mktItemLink = $"https://uland.taobao.com/item/edetail?id={mktId}";
  518. ////uland.taobao.com/item/edetail?id=98t7UOZmNWX4dh2eJSQt6-b7Y8yZVuBQ5ywoz7TDA
  519. ////uland.taobao.com/item/edetail?id=98t7UOZmNWX4dh2eJSQt6-b7Y8yZVuBQ5ywoz7TD
  520. ///
  521. var client = new WebClientUtility();
  522. client.Proxy = proxy;
  523. client.AddHeaders("accept-language", "zh-CN,zh;q=0.9");
  524. client.AllowAutoRedirect = false;
  525. var response = client.Request(mktItemLink);
  526. if (!response.Successed)
  527. {
  528. throw response.ResponseException;
  529. }
  530. location = response.ResponseMessage?.Headers?.Location?.ToString();
  531. string message;
  532. if (!string.IsNullOrEmpty(location) && location.Contains("err.taobao.com/error1.html"))
  533. {
  534. message = $"【GetRawItemId】{_accountId}:{_accountName}\t{proxy?.Address}\n" +
  535. $"{mktId}\n{location}";
  536. //NotifyCore.Notify(new NifyMessage
  537. //{
  538. // message = message,
  539. // priority = NifyMessagePriority.high,
  540. // tags = ["red_circle"]
  541. //});
  542. return (0, null);
  543. }
  544. if (!string.IsNullOrEmpty(location) && location.Contains("item.htm?id="))
  545. {
  546. itemId = location.GetContentPart("?id=", "");
  547. }
  548. if (!string.IsNullOrEmpty(itemId))
  549. {
  550. RedisHelper.Set(cacheKey, itemId, 86400 * 7);
  551. }
  552. else
  553. {
  554. }
  555. return (1, itemId);
  556. }
  557. catch (Exception ex)
  558. {
  559. string message = $"【GetRawItemId】{_accountId}:{_accountName}\t{proxy?.Address}\n" +
  560. $"{mktId}\n{location}\n{body}\n{ex.Message}";
  561. NotifyCore.Notify(new NifyMessage
  562. {
  563. message = message,
  564. priority = NifyMessagePriority.high,
  565. tags = ["red_circle"]
  566. });
  567. }
  568. return (0, null);
  569. }
  570. public (int, string) GetRawItemId22(string mktId)
  571. {
  572. string body = string.Empty, location = string.Empty;
  573. try
  574. {
  575. string lock_key = $"lock:GetRawItemId:disabled";
  576. int count = RedisHelper.Get<int>(lock_key);
  577. if (count > 0) return (0, null);
  578. string cacheKey = $":cache:mkt2itemId:{mktId}";
  579. string itemId = RedisHelper.Get(cacheKey);
  580. if (itemId != null) return (1, itemId);
  581. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  582. string url = "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/union.moose.content.entry";
  583. //string url = $"{base_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&jumpType={jumpType}&tkTradeId=&positionIndex={positionIndex}";
  584. var client = new WebClientUtility()
  585. .SetContentType("application/x-www-form-urlencoded")
  586. .AddHeaders("Cookie", _cookies)
  587. .AddHeaders("Origin", "https://pub.alimama.com")
  588. .Post("_tb_token_", _tb_token)
  589. .Post("t", ts.ToString())
  590. .Post("bizType", "detailPage")
  591. .Post("bizParam", $"{{\"itemId\":\"{mktId}\"}}");
  592. //_tb_token_=3b88755bbe3f7&t=1718896771391&bizType=detailPage&bizParam=%7B%22itemId%22%3A%22JbtMUqkGMQvagTNb2Fvta-9ag242pu7MOX5e0bsrY%22%7D
  593. //_tb_token_=361e383eb61e5&t=1718895935097&bizType=detailPage&bizParam=%7B%22itemId%22%3A%22JbtMUqkGMQvagTNb2Fvta-9ag242pu7MOX5e0bsrY%22%7D
  594. #if DEBUG
  595. #else
  596. client.Proxy = _proxy;
  597. #endif
  598. if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
  599. var response = client.Request(url);
  600. if (!response.Successed)
  601. {
  602. throw response.ResponseException;
  603. }
  604. location = response.ResponseMessage?.Headers?.Location?.ToString();
  605. string message;
  606. if (!string.IsNullOrEmpty(location) && location.Contains("err.taobao.com/error1.html"))
  607. {
  608. RedisHelper.Set(lock_key, 1, 60);
  609. message = $"【GetRawItemId】{_accountId}:{_accountName}\t{_proxy?.Address}\n" +
  610. $"{mktId}\n{location}";
  611. //NotifyCore.Notify(new NifyMessage
  612. //{
  613. // message = message,
  614. // priority = NifyMessagePriority.high,
  615. // tags = ["red_circle"]
  616. //});
  617. return (0, null);
  618. }
  619. body = response.Body();
  620. var root = body.Convert2JsonElement();
  621. int code = root.PathRead<int>("code");
  622. message = root.PathRead<string>("info.message");
  623. //if ("nologin".Equals(message))
  624. //{
  625. // (bool success, message) = RenewCookie();
  626. // if (!success)
  627. // {
  628. // TkPoolCore.Disabled(_accountId, _accountName, body);
  629. // throw new Exception("nologin");
  630. // }
  631. // return (-1, null);
  632. //}
  633. itemId = root.PathRead<string>("model.item.itemId");
  634. if (!string.IsNullOrEmpty(itemId))
  635. {
  636. RedisHelper.Set(cacheKey, itemId, 86400 * 7);
  637. }
  638. else
  639. {
  640. //RedisHelper.Set(lock_key, 1, 3600);
  641. }
  642. return (1, itemId);
  643. }
  644. catch (Exception ex)
  645. {
  646. string message = $"【GetRawItemId】{_accountId}:{_accountName}\t{_proxy?.Address}\n" +
  647. $"{mktId}\n{location}\n{body}\n{ex.Message}";
  648. NotifyCore.Notify(new NifyMessage
  649. {
  650. message = message,
  651. priority = NifyMessagePriority.high,
  652. tags = ["red_circle"]
  653. });
  654. }
  655. return (0, null);
  656. }
  657. public void GetTkOrders222()
  658. {
  659. try
  660. {
  661. string url = "https://media.alimama.com/violationu2/warning_instance_page_v2.json?r=mx_208&toPage=1&pageSize=40&params=";
  662. var client = new WebClientUtility().SetContentType("application/json;charset=utf-8")
  663. .AddHeaders("X-Requested-With", "XMLHttpRequest")
  664. .AddHeaders("Cookie", _cookies);
  665. client.Proxy = _proxy;
  666. if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
  667. var response = client.Request(url);
  668. var body = response.Body();
  669. var root = body.Convert2JsonElement();
  670. int resultCode = root.Read<int>("resultCode", 0);
  671. int totalCount = root.PathRead<int>("data.totalCount", 0);
  672. bool success = root.Read("success", false);
  673. if (!success)
  674. {
  675. _ = new LoggerLibrary("violationu", "warning_error")
  676. .Info(url, body)
  677. .SaveAsync();
  678. throw new Exception(body);
  679. }
  680. if (totalCount == 0) return;
  681. _ = new LoggerLibrary("violationu", "warning").Info(url, body).SaveAsync();
  682. var list = root.ElementRead("data").ElementRead("result").EnumerateArray();
  683. foreach (var data in list)
  684. {
  685. var violation_commission = data.PathRead<decimal>("mediaInfo.订单虚假交易违规佣金", 0);
  686. new DBContext.Table("alimama_warning")
  687. .Fill(data)
  688. .Loader<int>("filterRuleId", 0)
  689. .Loader<long>("gmtCreate", 0)
  690. .Loader<long>("id", 0, "ali_id")
  691. .Loader<string>("idStr", string.Empty)
  692. .Loader<int>("mediaDimension", 0)
  693. .Loader<long>("mediaId", 0)
  694. .Loader<int>("mediaInfo.abn_cnt", 0, "abn_cnt")
  695. .Add("violation_commission", violation_commission)
  696. .Loader<int>("mediaInfo.warning_cnt", 0, "warning_cnt")
  697. .Loader<string>("mediaName", string.Empty)
  698. .Loader<long>("memberId", 0)
  699. .Loader<string>("noticeCategory", string.Empty)
  700. .Loader<int>("noticeTemplateId", 0)
  701. .Loader<string>("noticeTemplateName", string.Empty)
  702. .Loader<string>("orderFile", string.Empty)
  703. .Loader<string>("pid", string.Empty)
  704. .Loader<int>("punishRuleId", 0)
  705. .Loader<string>("riskType", string.Empty)
  706. .Loader<string>("roleName", string.Empty)
  707. .Loader<string>("ruleLink", string.Empty)
  708. .Loader<bool>("showOrderDetail", false)
  709. .Loader<int>("status", 0, "ali_status")
  710. .Loader<string>("warningText", string.Empty)
  711. .Add("accountName", _accountName)
  712. .Add("status", true)
  713. .Add("create_time", DateTime.Now)
  714. .Add("last_time", DateTime.Now)
  715. .Create(DBContext.InsertType.REPLACE);
  716. }
  717. }
  718. catch (Exception ex) { }
  719. }
  720. }
  721. }