order.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using dodohold.core;
  2. using Sayaka.Common;
  3. namespace molilian.core
  4. {
  5. public partial class JdUnionPlus
  6. {
  7. public async Task<JdDataDTO> listOrderSku(JdDataDTO result, string wareUrl, CancellationToken cancellationToken = default)
  8. {
  9. string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None);
  10. if (parts.Length > 1)
  11. {
  12. wareUrl = parts[0] + ".html";
  13. }
  14. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  15. string cookies = _account.cookies;
  16. string uuid = cookies.GetContentPart("__jdu=", ";");
  17. string __jda = cookies.GetContentPart("__jda=", ";");
  18. if (__jda.Split('.').Length > 1)
  19. {
  20. uuid = __jda.Split('.')[1];
  21. }
  22. string useragent = _account.user_agent;
  23. if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
  24. string url = $"https://api.m.jd.com/api?functionId=unionPromoteLinkService&" +
  25. $"appid=unionpc&_={ts}&loginType=3&uuid={uuid}";
  26. var args = new
  27. {
  28. funName = "getCode",
  29. param = new
  30. {
  31. couponLink = "",
  32. isPinGou = 0,
  33. materialId = result.itemId,
  34. materialType = 1,
  35. planId = 3479956501,
  36. promotionType = 15,
  37. receiveType = "cps",
  38. wareUrl = wareUrl,
  39. isSmartGraphics = 0,
  40. command = 1,
  41. ext1 = "618|pc|".UrlEncode()
  42. },
  43. lientPageId = "jingfen_pc"
  44. };
  45. string data = args.Convert2Json().UrlEncode();
  46. WebClientUtility client = new WebClientUtility();
  47. client.Proxy = _proxy;
  48. #if DEBUG
  49. client.Proxy = null;
  50. #endif
  51. client.SetContentType("application/x-www-form-urlencoded");
  52. client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
  53. client.AddHeaders("X-Rp-Client", "h5_1.0.0");
  54. client.AddHeaders("Referer", "https://union.jd.com/");
  55. client.AddHeaders("Origin", "https://union.jd.com");
  56. client.UserAgent = useragent;
  57. client.AddHeaders("Cookie", cookies);
  58. client.Post($"body={data}");
  59. var response = await client.RequestAsync(url, "POST", cancellationToken);
  60. string body = response.Body();
  61. var root = body.Convert2JsonElement();
  62. int code = root.Read<int>("code");
  63. string message = root.Read<string>("message");
  64. string shortCode = root.PathRead<string>("data.shortCode");
  65. if (code == 200)
  66. {
  67. result.success = true;
  68. result.message = "OK";
  69. result.shortLinkurl = shortCode;
  70. result.content = result.shortLinkurl;
  71. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  72. }
  73. else
  74. {
  75. if (string.IsNullOrEmpty(body)) message = "网络异常";
  76. result.success = false;
  77. result.message = "转链失败";
  78. result.reason = message;
  79. result.shortLinkurl = wareUrl;
  80. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  81. _ = new LoggerLibrary("JdUnion", "GetPromotionByCrawlerAsync").Info(body).SaveAsync();
  82. }
  83. return result;
  84. }
  85. }
  86. }