goods.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using dodohold.core;
  2. using Sayaka.Common;
  3. using System.Text.RegularExpressions;
  4. namespace molilian.core
  5. {
  6. public class PddTransferUrlResult
  7. {
  8. public string multiGroupShortUrl { get; set; } = string.Empty;
  9. public string multiGroupUrl { get; set; } = string.Empty;
  10. public string shortUrl { get; set; } = string.Empty;
  11. public string url { get; set; } = string.Empty;
  12. }
  13. public class PddTransferUrlResponse
  14. {
  15. public int errorCode { get; set; }
  16. public string errorMsg { get; set; } = string.Empty;
  17. public bool success { get; set; } = false;
  18. public PddTransferUrlResult result { get; set; } = new();
  19. }
  20. public class PddCreatePromotionUrlResult
  21. {
  22. public string multiGroupShortUrl { get; set; } = string.Empty;
  23. public string multiGroupUrl { get; set; } = string.Empty;
  24. public string shortUrl { get; set; } = string.Empty;
  25. public string url { get; set; } = string.Empty;
  26. }
  27. public class PddCreatePromotionUrlResponse
  28. {
  29. public int errorCode { get; set; }
  30. public string errorMsg { get; set; } = string.Empty;
  31. public bool success { get; set; } = false;
  32. public PddCreatePromotionUrlResult result { get; set; } = new();
  33. }
  34. public partial class PddUnionPlus
  35. {
  36. public async Task<PddDataDTO> transferUrl(PddDataDTO result, string sourceUrl, CancellationToken cancellationToken = default)
  37. {
  38. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  39. string cookies = _account.cookies.Trim();
  40. string useragent = ProviderFakeUserAgent.RandomComputer;
  41. string url = "https://jinbao.pinduoduo.com/network/api/promotion/transferUrl";
  42. //{"pid":"13848803_189356569","sourceUrl":"https://p.pinduoduo.com/1OAsct0r"}
  43. var args = new
  44. {
  45. _account.pid,
  46. sourceUrl = sourceUrl.UrlDecode(),
  47. };
  48. string data = args.Convert2Json();
  49. WebClientUtility client = new WebClientUtility();
  50. client.Proxy = _proxy;
  51. #if DEBUG
  52. client.Proxy = null;
  53. #endif
  54. client.SetContentType("application/json");
  55. client.AddHeaders("Referer", "https://jinbao.pinduoduo.com/promotion/url-promotion");
  56. client.AddHeaders("Origin", "https://jinbao.pinduoduo.com");
  57. client.UserAgent = useragent;
  58. client.AddHeaders("Cookie", cookies);
  59. client.Post(data);
  60. var response = await client.RequestAsync(url, "POST", cancellationToken);
  61. string body = response.Body();
  62. var root = body.Convert2Object<PddTransferUrlResponse>();
  63. string message = string.Empty;
  64. if (!root.success)
  65. {
  66. message = $"{root.errorCode}:{root.errorMsg}";
  67. result.success = false;
  68. result.message = "转链失败";
  69. result.reason = message;
  70. _ = new LoggerLibrary("PddUnion", "transferUrl").Info(body).SaveAsync();
  71. return result;
  72. }
  73. if (string.IsNullOrEmpty(root.result?.multiGroupShortUrl))
  74. {
  75. result.success = false;
  76. result.message = "转链失败";
  77. result.reason = "无法转链";
  78. //_ = new LoggerLibrary("PddUnion", "transferUrl").Info(body).SaveAsync();
  79. return result;
  80. }
  81. if (!string.IsNullOrEmpty(root.result?.url))
  82. {
  83. result.itemId = root.result?.url.GetContentPart("goods_id=", "&");
  84. }
  85. result.success = true;
  86. result.message = "OK";
  87. result.link_type = LinkTypeEnum.goods;
  88. result.shortLinkurl = root.result?.multiGroupShortUrl;
  89. result.content = result.shortLinkurl;
  90. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  91. return result;
  92. }
  93. public async Task<PddDataDTO> createPromotionUrl(PddDataDTO result, string sourceUrl, CancellationToken cancellationToken = default)
  94. {
  95. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  96. string cookies = _account.cookies.Trim();
  97. string useragent = ProviderFakeUserAgent.RandomComputer;
  98. string url = "https://jinbao.pinduoduo.com/network/api/promotion/createPromotionUrl";
  99. //{"pid":"13848803_189356569","sourceUrl":"https://p.pinduoduo.com/1OAsct0r"}
  100. string goodsId = sourceUrl;
  101. var args = new
  102. {
  103. _account.pid,
  104. goodsId,
  105. generateOpenCoupon = true
  106. };
  107. /*
  108. {
  109. "mediaId": "9092702778",
  110. "pid": "13848803_189356569",
  111. "goodsId": "123",
  112. "generateOpenCoupon": true
  113. }
  114. */
  115. string data = args.Convert2Json();
  116. WebClientUtility client = new WebClientUtility();
  117. client.Proxy = _proxy;
  118. #if DEBUG
  119. client.Proxy = null;
  120. #endif
  121. client.SetContentType("application/json");
  122. client.AddHeaders("Referer", "https://jinbao.pinduoduo.com/promotion/url-promotion");
  123. client.AddHeaders("Origin", "https://jinbao.pinduoduo.com");
  124. client.UserAgent = useragent;
  125. client.AddHeaders("Cookie", cookies);
  126. client.Post(data);
  127. var response = await client.RequestAsync(url, "POST", cancellationToken);
  128. string body = response.Body();
  129. var root = body.Convert2Object<PddCreatePromotionUrlResponse>();
  130. string message = string.Empty;
  131. if (!root.success)
  132. {
  133. message = $"{root.errorCode}:{root.errorMsg}";
  134. result.success = false;
  135. result.message = "转链失败";
  136. result.reason = message;
  137. _ = new LoggerLibrary("PddUnion", "transferUrl").Info(body).SaveAsync();
  138. return result;
  139. }
  140. if (string.IsNullOrEmpty(root.result?.multiGroupShortUrl))
  141. {
  142. result.success = false;
  143. result.message = "转链失败";
  144. result.reason = "无法转链";
  145. //_ = new LoggerLibrary("PddUnion", "transferUrl").Info(body).SaveAsync();
  146. return result;
  147. }
  148. //goods_id=636365867069&pid=13848803_189356569&goods_sign=E9z2NkASdqlKuWDVwvfdqnADgCEqTQSt_JuMe2WC0G&zs_duo_id=25194414&cpsSign=CC_240807_13848803_189356569_fdbbdfa499058644becc9f8b3b7acaaf&_x_ddjb_act=
  149. if (!string.IsNullOrEmpty(root.result?.url))
  150. {
  151. result.itemId = root.result?.url.GetContentPart("goods_id=", "&");
  152. }
  153. result.success = true;
  154. result.message = "OK";
  155. result.link_type = LinkTypeEnum.goods;
  156. result.shortLinkurl = root.result?.multiGroupShortUrl;
  157. result.content = result.shortLinkurl;
  158. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  159. return result;
  160. }
  161. }
  162. }