EstimateComm.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using dodohold.core;
  2. using Sayaka.Common;
  3. namespace molilian.core
  4. {
  5. public partial class JdUnionPlus
  6. {
  7. public async Task<List<DateTime>> queryEstimateCommList(CancellationToken cancellationToken = default)
  8. {
  9. List<DateTime> changed_dates = new List<DateTime>();
  10. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  11. string cookies = _account.union_cookies;
  12. string useragent = _account.user_agent;
  13. if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
  14. bool hasNext = true;
  15. int pageNo = 1;
  16. while (hasNext)
  17. {
  18. var args = new
  19. {
  20. funName = "queryEstimateCommList",
  21. param = new
  22. {
  23. startTime = "",
  24. endTime = "",
  25. unionType = "",
  26. status = "",
  27. pageNo,
  28. pageSize = 20
  29. },
  30. //,"param":{"endTime":"","startTime":"","unionType":"","status":null,"pageNo":1,"pageSize":20}}
  31. };
  32. string data = args.Convert2Json().UrlEncode();
  33. string url = $"https://api.m.jd.com/api?functionId=union_balance_service&appid=unionpc&loginType=3&body={data}";
  34. WebClientUtility client = new WebClientUtility();
  35. client.Proxy = _proxy;
  36. #if DEBUG
  37. client.Proxy = null;
  38. #endif
  39. client.SetContentType("application/x-www-form-urlencoded");
  40. client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
  41. client.AddHeaders("X-Rp-Client", "h5_1.0.0");
  42. client.AddHeaders("Referer", "https://union.jd.com/");
  43. client.AddHeaders("Origin", "https://union.jd.com");
  44. client.UserAgent = useragent;
  45. client.AddHeaders("Cookie", cookies);
  46. client.Post($"body={data}");
  47. DateTime stime = DateTime.Now;
  48. var response = await client.RequestAsync(url, "POST", cancellationToken);
  49. TimeSpan ts2 = DateTime.Now - stime;
  50. string xx = ts2.TotalSeconds.ToString();
  51. if (!client.Successed) throw client.ResponseException;
  52. string body = response.Body();
  53. var root = body.Convert2JsonElement();
  54. int code = root.Read<int>("code");
  55. string message = root.Read<string>("message");
  56. hasNext = root.Read<bool>("hasNext", false);
  57. pageNo++;
  58. if (code == 200 && "success".Equals(message))
  59. {
  60. var list = root.ElementRead("result");
  61. string filter = "report_date=@report_date AND accountId=@accountId" +
  62. " AND unionType=@unionType AND feeType=@feeType AND platform=@platform";
  63. foreach (var item in list.EnumerateArray())
  64. {
  65. var report = item.GetRawText().Convert2Object<JdEstimateCommDTO>();
  66. if (DateTime.TryParseExact(report.payMonth, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime report_date))
  67. {
  68. changed_dates.Add(report_date.Date);
  69. var exist = new DBContext.Table("jd_estimate_comm")
  70. .Fields("id")
  71. .Get<dynamic>(filter,
  72. new
  73. {
  74. report_date = report_date.Date,
  75. accountId = _account.id,
  76. report.unionType,
  77. report.feeType,
  78. report.platform,
  79. report.status
  80. }
  81. );
  82. var update = new DBContext.Table("jd_estimate_comm")
  83. .Add("accountId", _account.id)
  84. .Add("accountName", _account.name)
  85. .Add("cosFee", report.cosFee)
  86. .Add("feeType", report.feeType)
  87. .Add("feeTypeStr", report.feeTypeStr)
  88. .Add("platform", report.platform)
  89. .Add("platformStr", report.platformStr)
  90. .Add("status", report.status)
  91. .Add("unionType", report.unionType)
  92. .Add("unionTypeStr", report.unionTypeStr)
  93. .Add("last_time", DateTime.Now);
  94. if (exist == null)
  95. {
  96. update.Add("report_date", report_date.Date)
  97. .Add("create_time", DateTime.Now)
  98. .Create(DBContext.InsertType.REPLACE);
  99. }
  100. else
  101. {
  102. update.Where("id=@id", new { exist.id }).Update();
  103. }
  104. }
  105. }
  106. }
  107. else
  108. {
  109. throw new APIException(body);
  110. }
  111. }
  112. return changed_dates;
  113. }
  114. }
  115. }