goods.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Controllers;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using dodohold.core;
  9. using Dataoke;
  10. using System.Text.RegularExpressions;
  11. using Org.BouncyCastle.Ocsp;
  12. using System.Diagnostics;
  13. using TencentCloud.Fmu.V20191213.Models;
  14. using Microsoft.VisualBasic;
  15. using System.Text.Json;
  16. using static System.Runtime.InteropServices.JavaScript.JSType;
  17. using System.Security.Cryptography;
  18. using System.Security.Policy;
  19. using Google.Protobuf.WellKnownTypes;
  20. using Microsoft.AspNetCore.Components;
  21. using Org.BouncyCastle.Pqc.Crypto.Ntru;
  22. using Newtonsoft.Json;
  23. using Sayaka.Common;
  24. using System.Net;
  25. namespace molilian.core
  26. {
  27. public partial class JdUnionPlus
  28. {
  29. public async Task<JdDataDTO> GetPromotionBySiteAsync(JdDataDTO result, string shortLinkurl, CancellationToken cancellationToken = default)
  30. {
  31. if (string.IsNullOrEmpty(_account.site_id))
  32. {
  33. return await GetPromotionByAffAsync(result, shortLinkurl, cancellationToken);
  34. }
  35. string method = "jd.union.open.promotion.common.get";
  36. string version = "1.0";
  37. var data = new
  38. {
  39. promotionCodeReq = new
  40. {
  41. siteId = _account.site_id,
  42. materialId = shortLinkurl,
  43. command = 1,
  44. chainType = 2,
  45. }
  46. };
  47. var body = await RequestAsync(method, version, data.Convert2Json(), cancellationToken);
  48. var root = body.Convert2Object<JdUnionResponse>();
  49. if (root != null && root.jd_union_open_promotion_common_get_responce != null)
  50. {
  51. var _promotion_data = root.jd_union_open_promotion_common_get_responce.getResult;
  52. var promotion_data = _promotion_data.Convert2Object<JdData>();
  53. string code = root.jd_union_open_promotion_common_get_responce.code;
  54. if ("0".Equals(code))
  55. {
  56. if (promotion_data.code == 200)
  57. {
  58. var url = promotion_data.data.clickURL;
  59. result.success = true;
  60. result.message = "OK";
  61. result.shortLinkurl = url;
  62. result.content = result.shortLinkurl;
  63. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  64. return result;
  65. }
  66. }
  67. result.reason = root.jd_union_open_promotion_common_get_responce.message;
  68. if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message;
  69. }
  70. else
  71. {
  72. result.reason = "网络错误";
  73. }
  74. result.success = false;
  75. result.message = "转链失败";
  76. result.shortLinkurl = shortLinkurl;
  77. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  78. _ = new LoggerLibrary("JdUnion", "promotion_get_error").Info(body).SaveAsync();
  79. return result;
  80. }
  81. public async Task<JdDataDTO> GetPromotionByAffAsync(JdDataDTO result, string shortLinkurl, CancellationToken cancellationToken = default)
  82. {
  83. string method = "jd.union.open.promotion.bysubunionid.get";
  84. string version = "1.0";
  85. var data = new
  86. {
  87. promotionCodeReq = new
  88. {
  89. materialId = shortLinkurl,
  90. command = 1,
  91. chainType = 2,
  92. }
  93. };
  94. var body = await RequestAsync(method, version, data.Convert2Json(), cancellationToken);
  95. var root = body.Convert2Object<JdUnionResponse>();
  96. //{"jd_union_open_promotion_bysubunionid_get_responce":{"code":"0","getResult":"{\"code\":200,\"data\":{\"shortURL\":\"https://u.jd.com/esCrWn4\"},\"message\":\"success\",\"requestId\":\"o_0b64a07b_lyiusnpg_74220789\"}"}}
  97. if (root != null && root.jd_union_open_promotion_bysubunionid_get_responce != null)
  98. {
  99. string code = root.jd_union_open_promotion_bysubunionid_get_responce.code;
  100. var _promotion_data = root.jd_union_open_promotion_bysubunionid_get_responce.getResult;
  101. var promotion_data = _promotion_data.Convert2Object<JdData>();
  102. if ("0".Equals(code))
  103. {
  104. if (promotion_data.code == 200)
  105. {
  106. var url = promotion_data.data.shortURL;
  107. result.success = true;
  108. result.message = "OK";
  109. result.shortLinkurl = url;
  110. result.content = result.shortLinkurl;
  111. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  112. return result;
  113. }
  114. }
  115. result.reason = root.jd_union_open_promotion_bysubunionid_get_responce.message;
  116. if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message;
  117. }
  118. else
  119. {
  120. result.reason = "网络错误";
  121. }
  122. result.success = false;
  123. result.message = "转链失败";
  124. result.shortLinkurl = shortLinkurl;
  125. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  126. _ = new LoggerLibrary("JdUnion", "bysubunionid_get_error").Info(body).SaveAsync();
  127. return result;
  128. }
  129. public async Task<JdDataDTO> GetPromotionByCrawlerAsync(JdDataDTO result, string wareUrl, CancellationToken cancellationToken = default)
  130. {
  131. string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None);
  132. if (parts.Length > 1)
  133. {
  134. wareUrl = parts[0] + ".html";
  135. }
  136. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  137. string cookies = _account.cookies;
  138. //cookies = "pinId=lDSKR4P756s; __jdu=797222838; unpl=JF8EAM1nNSttXxtVVxtSSEFASw9QWwpbTh4KP28NAwlaTAvEt16MoRnbUfHBdCarU9683KT3AsB67n92UtFSEXtdVV9fD0oeBm5vNWRdXU8ABh5VSUAXJV06KgF6SUxXbxN6CCU2S1UEGgYfExlOX11bEAl7FANfZjVSVV5IVwYSABIiEXtdXFptCEoWAmtjBF1YWkJRNSsHGxMRTltWX1oBexYzbWYEUV1fQ10AGjJZfMnF8oHV_d_CidTxw9Df9oz_3EgdCh0RE0hUVldtCXsU; shshshfpa=02d19590-d1e4-c91f-76d9-50b5b48caeae-1696955111; shshshfpx=02d19590-d1e4-c91f-76d9-50b5b48caeae-1696955111; TrackID=1P1YIoOSuMvq9KVQS8e4qaKAWslU3bHIlXwpUNeXUOPY_dPOhYcH5fl6XgaIzKppd5zTuGg52Ql9Ht7h1LNA62ZkhO1G3xwkTKekmP3nhjjmnOr5rzvlohhH3EkChqHLB; thor=D3FCA70DCE7542F87C212B790D3JDaxNfPy83okP3kLScwCkGiuMcyC4Pcyn8202E9E708F27CB58F480D2CC3FE67C9253747FE21007250E37AE528C577139FEEC81E6EE68034351A54BE200FF3JDaxNfPy83okP3kLScwCkGiuMcyC4Pcyn7n92UtFE03B1646F11A6B796AEE7DE71C760EDFF210BD03D24599A6CFF007C0D40BA49D; pin=23117; unick=jd2311kga; _tp=D8kjVbHzTJzgqxcxaN3m1w%3D%3D; _pst=23117; ipLoc-djd=24-2144-3909-58335; 3AB9D23F7A4B3C9B=IPF6PUOISQRNPNXNQVLJJVKQVBTAvEt16MoRnbUfHBdCarU9683JDaxNfPy83okP3kLScwCkGiuMcyC4PcynYGLMEE; flash=2_YNg0msef1iArLpGWQBwhJos62BkQWLuFuDD-HGOLK2KKuPtQ08qYx9js2jlEHwoRT7AVTOjRo8iR1-PT6ZsT8ZDnqdgMfbeoSNMJvJa8qphobenATQ0WXPYP62_XgiF1J7II6jY1qovmiIDadA7rd5tHyAVpTzEsqpI6xVJ9b6D*; __jda=209449046.797222838.1720272224.1720293360.1721239059.3; __jdc=209449046; __jdv=209449046|baidu|-|organic|notset|1721239059356; 3AB9D23F7A4B3CSS=jdd03IPF6PUOISQRNPNXNQVLJJVKQVBTAvEt16MoRnbUfHBdCarU9683JDaxNfPy83okP3kLScwCkGiuMcyC4PcynvEt16MoRnbUfHBdCarU9683KT3AsB67n92UtFUX; _gia_d=1; shshshfpb=BApXcdm_fwvVAJzuAI6Mnq8QQOcIPSh90B9TUVj599xJ1MlKCa4O2; __jdb=209449046.5.797222838|3.1721239059; RT=\"z=1&dm=jd.com&si=zpw2ttxi9&ss=lyq5alej&sl=6&tt=3x4&ld=z4s&nu=3d2f85352c70c73af100bf1449967844&cl=x78\"\r\n\r\n;";
  139. string uuid = cookies.GetContentPart("__jdu=", ";");
  140. string __jda = cookies.GetContentPart("__jda=", ";");
  141. if (__jda.Split('.').Length > 1)
  142. {
  143. uuid = __jda.Split('.')[1];
  144. }
  145. string useragent = _account.user_agent;
  146. if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
  147. string url = $"https://api.m.jd.com/api?functionId=unionPromoteLinkService&" +
  148. $"appid=unionpc&_={ts}&loginType=3&uuid={uuid}";
  149. var args = new
  150. {
  151. funName = "getCode",
  152. param = new
  153. {
  154. couponLink = "",
  155. isPinGou = 0,
  156. materialId = result.itemId,
  157. materialType = 1,
  158. planId = 3479956501,
  159. promotionType = 15,
  160. receiveType = "cps",
  161. wareUrl = wareUrl,
  162. isSmartGraphics = 0,
  163. command = 1,
  164. ext1 = "618|pc|".UrlEncode()
  165. },
  166. lientPageId = "jingfen_pc"
  167. };
  168. string data = args.Convert2Json().UrlEncode();
  169. WebClientUtility client = new WebClientUtility();
  170. client.Proxy = _proxy;
  171. #if DEBUG
  172. client.Proxy = null;
  173. #endif
  174. client.SetContentType("application/x-www-form-urlencoded");
  175. client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
  176. client.AddHeaders("X-Rp-Client", "h5_1.0.0");
  177. client.AddHeaders("Referer", "https://union.jd.com/");
  178. client.AddHeaders("Origin", "https://union.jd.com");
  179. client.UserAgent = useragent;
  180. client.AddHeaders("Cookie", cookies);
  181. client.Post($"body={data}");
  182. var response = await client.RequestAsync(url, "POST", cancellationToken);
  183. string body = response.Body();
  184. var root = body.Convert2JsonElement();
  185. int code = root.Read<int>("code");
  186. string message = root.Read<string>("message");
  187. string shortCode = root.PathRead<string>("data.shortCode");
  188. if (code == 200)
  189. {
  190. result.success = true;
  191. result.message = "OK";
  192. result.shortLinkurl = shortCode;
  193. result.content = result.shortLinkurl;
  194. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  195. }
  196. else
  197. {
  198. if (string.IsNullOrEmpty(body)) message = "网络异常";
  199. result.success = false;
  200. result.message = "转链失败";
  201. result.reason = message;
  202. result.shortLinkurl = wareUrl;
  203. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  204. _ = new LoggerLibrary("JdUnion", "GetPromotionByCrawlerAsync").Info(body).SaveAsync();
  205. }
  206. return result;
  207. }
  208. }
  209. public class JdData
  210. {
  211. public int code { get; set; }
  212. public string message { get; set; }
  213. public string requestId { get; set; }
  214. public JdClickData data { get; set; }
  215. }
  216. public class JdClickData
  217. {
  218. public string shortURL { get; set; }
  219. public string clickURL { get; set; }
  220. public string jCommand { get; set; }
  221. }
  222. public class JdUnionResponse
  223. {
  224. public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_common_get_responce { get; set; }
  225. public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_bysubunionid_get_responce { get; set; }
  226. }
  227. public class JdUnionOpenPromotionCommonGetResponce
  228. {
  229. public string code { get; set; }
  230. public string getResult { get; set; }
  231. public string message { get; set; }
  232. public string requestId { get; set; }
  233. }
  234. }