goods.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. var _promotion_data = root.jd_union_open_promotion_common_get_responce.getResult;
  50. var promotion_data = _promotion_data.Convert2Object<JdData>();
  51. string code = root.jd_union_open_promotion_common_get_responce.code;
  52. if ("0".Equals(code))
  53. {
  54. if (promotion_data.code == 200)
  55. {
  56. var url = promotion_data.data.clickURL;
  57. result.success = true;
  58. result.message = "OK";
  59. result.shortLinkurl = url;
  60. result.content = result.shortLinkurl;
  61. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  62. return result;
  63. }
  64. }
  65. result.success = false;
  66. result.message = "转链失败";
  67. result.reason = root.jd_union_open_promotion_common_get_responce.message;
  68. if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message;
  69. result.shortLinkurl = shortLinkurl;
  70. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  71. _ = new LoggerLibrary("JdUnion", "promotion_get_error").Info(body).SaveAsync();
  72. return result;
  73. }
  74. public async Task<JdDataDTO> GetPromotionByAffAsync(JdDataDTO result, string shortLinkurl, CancellationToken cancellationToken = default)
  75. {
  76. string method = "jd.union.open.promotion.bysubunionid.get";
  77. string version = "1.0";
  78. var data = new
  79. {
  80. promotionCodeReq = new
  81. {
  82. materialId = shortLinkurl,
  83. command = 1,
  84. chainType = 2,
  85. }
  86. };
  87. var body = await RequestAsync(method, version, data.Convert2Json(), cancellationToken);
  88. var root = body.Convert2Object<JdUnionResponse>();
  89. //{"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\"}"}}
  90. string code = root.jd_union_open_promotion_bysubunionid_get_responce.code;
  91. var _promotion_data = root.jd_union_open_promotion_bysubunionid_get_responce.getResult;
  92. var promotion_data = _promotion_data.Convert2Object<JdData>();
  93. if ("0".Equals(code))
  94. {
  95. if (promotion_data.code == 200)
  96. {
  97. var url = promotion_data.data.shortURL;
  98. result.success = true;
  99. result.message = "OK";
  100. result.shortLinkurl = url;
  101. result.content = result.shortLinkurl;
  102. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  103. return result;
  104. }
  105. }
  106. result.success = false;
  107. result.message = "转链失败";
  108. result.reason = root.jd_union_open_promotion_bysubunionid_get_responce.message;
  109. if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message;
  110. result.shortLinkurl = shortLinkurl;
  111. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  112. _ = new LoggerLibrary("JdUnion", "bysubunionid_get_error").Info(body).SaveAsync();
  113. return result;
  114. }
  115. public async Task<JdDataDTO> GetPromotionByCrawlerAsync(JdDataDTO result, string wareUrl, CancellationToken cancellationToken = default)
  116. {
  117. string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None);
  118. if (parts.Length > 1)
  119. {
  120. wareUrl = parts[0] + ".html";
  121. }
  122. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  123. string cookies = _account.cookies;
  124. string uuid = cookies.GetContentPart("__jdu=", ";");
  125. string __jda = cookies.GetContentPart("__jda=", ";");
  126. if (__jda.Split('.').Length > 1)
  127. {
  128. uuid = __jda.Split('.')[1];
  129. }
  130. string useragent = _account.user_agent;
  131. if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
  132. string url = $"https://api.m.jd.com/api?functionId=unionPromoteLinkService&" +
  133. $"appid=unionpc&_={ts}&loginType=3&uuid={uuid}";
  134. var args = new
  135. {
  136. funName = "getCode",
  137. param = new
  138. {
  139. couponLink = "",
  140. isPinGou = 0,
  141. materialId = result.itemId,
  142. materialType = 1,
  143. planId = 3479956501,
  144. promotionType = 15,
  145. receiveType = "cps",
  146. wareUrl = wareUrl,
  147. isSmartGraphics = 0,
  148. command = 1,
  149. ext1 = "618|pc|".UrlEncode()
  150. },
  151. lientPageId = "jingfen_pc"
  152. };
  153. string data = args.Convert2Json().UrlEncode();
  154. WebClientUtility client = new WebClientUtility();
  155. client.Proxy = _proxy;
  156. #if DEBUG
  157. client.Proxy = null;
  158. #endif
  159. client.SetContentType("application/x-www-form-urlencoded");
  160. client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
  161. client.AddHeaders("X-Rp-Client", "h5_1.0.0");
  162. client.AddHeaders("Referer", "https://union.jd.com/");
  163. client.AddHeaders("Origin", "https://union.jd.com");
  164. client.UserAgent = useragent;
  165. client.AddHeaders("Cookie", cookies);
  166. client.Post($"body={data}");
  167. var response = await client.RequestAsync(url, "POST", cancellationToken);
  168. string body = response.Body();
  169. var root = body.Convert2JsonElement();
  170. int code = root.Read<int>("code");
  171. string message = root.Read<string>("message");
  172. string shortCode = root.PathRead<string>("data.shortCode");
  173. if (code == 200)
  174. {
  175. result.success = true;
  176. result.message = "OK";
  177. result.shortLinkurl = shortCode;
  178. result.content = result.shortLinkurl;
  179. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  180. }
  181. else
  182. {
  183. if (string.IsNullOrEmpty(body)) message = "网络异常";
  184. result.success = false;
  185. result.message = "转链失败";
  186. result.reason = message;
  187. result.shortLinkurl = wareUrl;
  188. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  189. _ = new LoggerLibrary("JdUnion", "GetPromotionByCrawlerAsync").Info(body).SaveAsync();
  190. }
  191. return result;
  192. }
  193. }
  194. public class JdData
  195. {
  196. public int code { get; set; }
  197. public string message { get; set; }
  198. public string requestId { get; set; }
  199. public JdClickData data { get; set; }
  200. }
  201. public class JdClickData
  202. {
  203. public string shortURL { get; set; }
  204. public string clickURL { get; set; }
  205. public string jCommand { get; set; }
  206. }
  207. public class JdUnionResponse
  208. {
  209. public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_common_get_responce { get; set; }
  210. public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_bysubunionid_get_responce { get; set; }
  211. }
  212. public class JdUnionOpenPromotionCommonGetResponce
  213. {
  214. public string code { get; set; }
  215. public string getResult { get; set; }
  216. public string message { get; set; }
  217. public string requestId { get; set; }
  218. }
  219. }