goods.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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, string clickId, CancellationToken cancellationToken = default)
  30. {
  31. if (string.IsNullOrEmpty(_account.site_id))
  32. {
  33. return await GetPromotionByAffAsync(result, shortLinkurl, clickId, 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.commercial = true;
  61. result.message = "OK";
  62. result.shortLinkurl = url;
  63. result.content = result.shortLinkurl;
  64. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  65. return result;
  66. }
  67. }
  68. result.reason = root.jd_union_open_promotion_common_get_responce.message;
  69. if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message;
  70. }
  71. else
  72. {
  73. result.reason = "网络错误";
  74. }
  75. result.success = false;
  76. result.message = "转链失败";
  77. result.shortLinkurl = shortLinkurl;
  78. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  79. _ = new LoggerLibrary("JdUnion", "promotion_get_error").Info(body).SaveAsync();
  80. return result;
  81. }
  82. public async Task<JdDataDTO> GetPromotionByAffAsync(JdDataDTO result, string shortLinkurl, string clickId, CancellationToken cancellationToken = default)
  83. {
  84. string method = "jd.union.open.promotion.bysubunionid.get";
  85. string version = "1.0";
  86. var data = new
  87. {
  88. promotionCodeReq = new
  89. {
  90. materialId = shortLinkurl,
  91. command = 1,
  92. chainType = 2,
  93. }
  94. };
  95. var body = await RequestAsync(method, version, data.Convert2Json(), cancellationToken);
  96. var root = body.Convert2Object<JdUnionResponse>();
  97. //{"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\"}"}}
  98. if (root != null && root.jd_union_open_promotion_bysubunionid_get_responce != null)
  99. {
  100. string code = root.jd_union_open_promotion_bysubunionid_get_responce.code;
  101. var _promotion_data = root.jd_union_open_promotion_bysubunionid_get_responce.getResult;
  102. var promotion_data = _promotion_data.Convert2Object<JdData>();
  103. if ("0".Equals(code))
  104. {
  105. if (promotion_data.code == 200)
  106. {
  107. var url = promotion_data.data.shortURL;
  108. result.success = true;
  109. result.message = "OK";
  110. result.commercial = true;
  111. result.shortLinkurl = url;
  112. result.content = result.shortLinkurl;
  113. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  114. return result;
  115. }
  116. }
  117. result.reason = root.jd_union_open_promotion_bysubunionid_get_responce.message;
  118. if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message;
  119. }
  120. else
  121. {
  122. result.reason = "网络错误";
  123. }
  124. result.success = false;
  125. result.message = "转链失败";
  126. result.shortLinkurl = shortLinkurl;
  127. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  128. _ = new LoggerLibrary("JdUnion", "bysubunionid_get_error").Info(body).SaveAsync();
  129. return result;
  130. }
  131. public async Task<JdDataDTO> GetPromotionByDdxAsync(JdDataDTO result, string wareUrl, string clickId, CancellationToken cancellationToken = default)
  132. {
  133. string url = $"http://api.tbk.dingdanxia.com/jd/url_privilege?apikey={_account.app_key}&unionId={_account.unionid}&materialId={result.shortLinkurl.UrlDecode()}";
  134. WebClientUtility client = new WebClientUtility();
  135. var response = await client.RequestAsync(url, "GET", cancellationToken);
  136. string body = response.Body();
  137. var root = body.Convert2JsonElement();
  138. int code = root.Read<int>("code");
  139. string message = root.Read<string>("msg");
  140. string shortURL = root.PathRead<string>("data.shortURL");
  141. if (code == 200)
  142. {
  143. result.success = true;
  144. result.message = "OK";
  145. result.commercial = true;
  146. result.shortLinkurl = shortURL;
  147. result.content = result.shortLinkurl;
  148. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  149. }
  150. else
  151. {
  152. if (string.IsNullOrEmpty(body)) message = "网络异常";
  153. if (body.Contains("数据返回失败【(sceneId未入参)或(sceneId和商品格式不匹配)"))
  154. {
  155. message = "不支持数字ID";
  156. }
  157. result.success = false;
  158. result.message = "转链失败";
  159. result.reason = message;
  160. result.shortLinkurl = wareUrl;
  161. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  162. _ = new LoggerLibrary("JdUnion", "GetPromotionByDdxAsync").Info(body).SaveAsync();
  163. }
  164. return result;
  165. }
  166. public async Task<JdDataDTO> GetPromotionByCrawlerAsync(JdDataDTO result, string wareUrl, string clickId, CancellationToken cancellationToken = default)
  167. {
  168. string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None);
  169. if (parts.Length > 1)
  170. {
  171. wareUrl = parts[0] + ".html";
  172. }
  173. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  174. string cookies = _account.cookies;
  175. //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;";
  176. string uuid = cookies.GetContentPart("__jdu=", ";");
  177. string __jda = cookies.GetContentPart("__jda=", ";");
  178. if (__jda.Split('.').Length > 1)
  179. {
  180. uuid = __jda.Split('.')[1];
  181. }
  182. string useragent = _account.user_agent;
  183. if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
  184. var args = new
  185. {
  186. funName = "getCode",
  187. param = new
  188. {
  189. couponLink = "",
  190. isPinGou = 0,
  191. materialId = result.itemId,
  192. materialType = 1,
  193. planId = 3479956501,
  194. promotionType = 15,
  195. receiveType = "cps",
  196. wareUrl = wareUrl,
  197. isSmartGraphics = 0,
  198. command = 1,
  199. ext1 = "618|pc|".UrlEncode()
  200. },
  201. lientPageId = "jingfen_pc"
  202. };
  203. string data = args.Convert2Json().UrlEncode();
  204. string qs = await H5stHack(new
  205. {
  206. functionId = "unionPromoteLinkService",
  207. appid = "unionpc",
  208. _ = $"{ts}",
  209. loginType = "3",
  210. uuid = uuid,
  211. body = data,
  212. }, cancellationToken);
  213. string url = $"https://api.m.jd.com/api?{qs}";
  214. if (string.IsNullOrEmpty(qs))
  215. {
  216. result.success = false;
  217. result.message = "转链失败";
  218. result.reason = "签名失败";
  219. result.shortLinkurl = wareUrl;
  220. result.deeplink_url = (result.shortLinkurl);
  221. return result;
  222. }
  223. WebClientUtility client = new WebClientUtility();
  224. client.Proxy = _proxy;
  225. #if DEBUG
  226. client.Proxy = null;
  227. #endif
  228. client.SetContentType("application/x-www-form-urlencoded");
  229. client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
  230. client.AddHeaders("X-Rp-Client", "h5_1.0.0");
  231. client.AddHeaders("Referer", "https://union.jd.com/");
  232. client.AddHeaders("Origin", "https://union.jd.com");
  233. client.UserAgent = useragent;
  234. client.AddHeaders("Cookie", cookies);
  235. client.Post($"body={data}");
  236. var response = await client.RequestAsync(url, "GET", cancellationToken);
  237. string body = response.Body();
  238. var root = body.Convert2JsonElement();
  239. int code = root.Read<int>("code");
  240. string message = root.Read<string>("message");
  241. string shortCode = root.PathRead<string>("data.shortCode");
  242. if (code == 200)
  243. {
  244. result.success = true;
  245. result.message = "OK";
  246. result.commercial = true;
  247. result.shortLinkurl = shortCode;
  248. result.content = result.shortLinkurl;
  249. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  250. }
  251. else
  252. {
  253. if (string.IsNullOrEmpty(body)) message = "网络异常";
  254. result.success = false;
  255. result.message = "转链失败";
  256. result.reason = message;
  257. result.shortLinkurl = wareUrl;
  258. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  259. _ = new LoggerLibrary("JdUnion", "GetPromotionByCrawlerAsync").Info(body).SaveAsync();
  260. }
  261. return result;
  262. }
  263. public async Task<JdDataDTO> GetPromotionByCrawlerAsync2(JdDataDTO result, string wareUrl, string clickId, CancellationToken cancellationToken = default)
  264. {
  265. string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None);
  266. if (parts.Length > 1)
  267. {
  268. wareUrl = parts[0] + ".html";
  269. }
  270. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  271. string cookies = _account.cookies;
  272. //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;";
  273. string uuid = cookies.GetContentPart("__jdu=", ";");
  274. string __jda = cookies.GetContentPart("__jda=", ";");
  275. if (__jda.Split('.').Length > 1)
  276. {
  277. uuid = __jda.Split('.')[1];
  278. }
  279. string useragent = _account.user_agent;
  280. if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
  281. string url = $"https://api.m.jd.com/api?functionId=unionPromoteLinkService&" +
  282. $"appid=unionpc&_={ts}&loginType=3&uuid={uuid}";
  283. var args = new
  284. {
  285. funName = "getCode",
  286. param = new
  287. {
  288. couponLink = "",
  289. isPinGou = 0,
  290. materialId = result.itemId,
  291. materialType = 1,
  292. planId = 3479956501,
  293. promotionType = 15,
  294. receiveType = "cps",
  295. wareUrl = wareUrl,
  296. isSmartGraphics = 0,
  297. command = 1,
  298. ext1 = "618|pc|".UrlEncode()
  299. },
  300. lientPageId = "jingfen_pc"
  301. };
  302. string data = args.Convert2Json().UrlEncode();
  303. WebClientUtility client = new WebClientUtility();
  304. client.Proxy = _proxy;
  305. #if DEBUG
  306. client.Proxy = new WebProxy
  307. {
  308. Address = new Uri("http://bjapi.molilian.com:20063"),
  309. //Credentials = new NetworkCredential("t12881967077999", "6a1eh304")
  310. };
  311. client.Proxy = null;
  312. #endif
  313. client.SetContentType("application/x-www-form-urlencoded");
  314. client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
  315. client.AddHeaders("X-Rp-Client", "h5_1.0.0");
  316. client.AddHeaders("Referer", "https://union.jd.com/");
  317. client.AddHeaders("Origin", "https://union.jd.com");
  318. client.UserAgent = useragent;
  319. client.AddHeaders("Cookie", cookies);
  320. client.Post($"body={data}");
  321. var response = await client.RequestAsync(url, "POST", cancellationToken);
  322. //if (response.ResponseMessage.StatusCode == HttpStatusCode.Forbidden)
  323. //{
  324. // result.success = false;
  325. // result.message = "转链失败";
  326. // result.reason = "nologin";
  327. // result.shortLinkurl = wareUrl;
  328. // result.deeplink_url = GetDeeplink(result.shortLinkurl);
  329. // return result;
  330. //}
  331. string body = response.Body();
  332. var root = body.Convert2JsonElement();
  333. int code = root.Read<int>("code");
  334. string message = root.Read<string>("message");
  335. string shortCode = root.PathRead<string>("data.shortCode");
  336. if (code == 200)
  337. {
  338. result.success = true;
  339. result.message = "OK";
  340. result.commercial = true;
  341. result.shortLinkurl = shortCode;
  342. result.content = result.shortLinkurl;
  343. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  344. }
  345. else
  346. {
  347. if (string.IsNullOrEmpty(body)) message = "网络异常";
  348. result.success = false;
  349. result.message = "转链失败";
  350. result.reason = message;
  351. result.shortLinkurl = wareUrl;
  352. result.deeplink_url = GetDefaultStyleDeeplink(result.shortLinkurl);
  353. _ = new LoggerLibrary("JdUnion", "GetPromotionByCrawlerAsync").Info(body).SaveAsync();
  354. }
  355. return result;
  356. }
  357. }
  358. public class JdData
  359. {
  360. public int code { get; set; }
  361. public string message { get; set; }
  362. public string requestId { get; set; }
  363. public JdClickData data { get; set; }
  364. }
  365. public class JdClickData
  366. {
  367. public string shortURL { get; set; }
  368. public string clickURL { get; set; }
  369. public string jCommand { get; set; }
  370. }
  371. public class JdUnionResponse
  372. {
  373. public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_common_get_responce { get; set; }
  374. public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_bysubunionid_get_responce { get; set; }
  375. }
  376. public class JdUnionOpenPromotionCommonGetResponce
  377. {
  378. public string code { get; set; }
  379. public string getResult { get; set; }
  380. public string message { get; set; }
  381. public string requestId { get; set; }
  382. }
  383. }