goods.cs 20 KB

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