EstimateComm.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.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. string body = response.Body();
  52. var root = body.Convert2JsonElement();
  53. int code = root.Read<int>("code");
  54. string message = root.Read<string>("message");
  55. hasNext = root.Read<bool>("hasNext", false);
  56. pageNo++;
  57. if (code == 200 && "success".Equals(message))
  58. {
  59. var list = root.ElementRead("result");
  60. string filter = "report_date=@report_date AND accountId=@accountId" +
  61. " AND unionType=@unionType AND feeType=@feeType AND platform=@platform";
  62. foreach (var item in list.EnumerateArray())
  63. {
  64. var report = item.GetRawText().Convert2Object<JdEstimateCommDTO>();
  65. if (DateTime.TryParseExact(report.payMonth, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime report_date))
  66. {
  67. changed_dates.Add(report_date.Date);
  68. var exist = new DBContext.Table("jd_estimate_comm")
  69. .Fields("id")
  70. .Get<dynamic>(filter,
  71. new
  72. {
  73. report_date = report_date.Date,
  74. accountId = _account.id,
  75. report.unionType,
  76. report.feeType,
  77. report.platform,
  78. report.status
  79. }
  80. );
  81. var update = new DBContext.Table("jd_estimate_comm")
  82. .Add("accountId", _account.id)
  83. .Add("accountName", _account.name)
  84. .Add("cosFee", report.cosFee)
  85. .Add("feeType", report.feeType)
  86. .Add("feeTypeStr", report.feeTypeStr)
  87. .Add("platform", report.platform)
  88. .Add("platformStr", report.platformStr)
  89. .Add("status", report.status)
  90. .Add("unionType", report.unionType)
  91. .Add("unionTypeStr", report.unionTypeStr)
  92. .Add("last_time", DateTime.Now);
  93. if (exist == null)
  94. {
  95. update.Add("report_date", report_date.Date)
  96. .Add("create_time", DateTime.Now)
  97. .Create(DBContext.InsertType.REPLACE);
  98. }
  99. else
  100. {
  101. update.Where("id=@id", new { exist.id }).Update();
  102. }
  103. }
  104. }
  105. }
  106. else
  107. {
  108. throw new APIException(body);
  109. }
  110. }
  111. return changed_dates;
  112. }
  113. }
  114. }