goods.cs 8.5 KB

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