using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Collections.Generic; using System.Linq; using System.Text; using dodohold.core; using Dataoke; using System.Text.RegularExpressions; using Org.BouncyCastle.Ocsp; using System.Diagnostics; using TencentCloud.Fmu.V20191213.Models; using Microsoft.VisualBasic; using System.Text.Json; using static System.Runtime.InteropServices.JavaScript.JSType; using System.Security.Cryptography; using System.Security.Policy; using Google.Protobuf.WellKnownTypes; using Microsoft.AspNetCore.Components; using Org.BouncyCastle.Pqc.Crypto.Ntru; using Newtonsoft.Json; using Sayaka.Common; using System.Net; namespace molilian.core { public partial class JdUnionPlus { public async Task GetPromotionBySiteAsync(JdDataDTO result, string shortLinkurl, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(_account.site_id)) { return await GetPromotionByAffAsync(result, shortLinkurl, cancellationToken); } string method = "jd.union.open.promotion.common.get"; string version = "1.0"; var data = new { promotionCodeReq = new { siteId = _account.site_id, materialId = shortLinkurl, command = 1, chainType = 2, } }; var body = await RequestAsync(method, version, data.Convert2Json(), cancellationToken); var root = body.Convert2Object(); var _promotion_data = root.jd_union_open_promotion_common_get_responce.getResult; var promotion_data = _promotion_data.Convert2Object(); string code = root.jd_union_open_promotion_common_get_responce.code; if ("0".Equals(code)) { if (promotion_data.code == 200) { var url = promotion_data.data.clickURL; result.success = true; result.message = "OK"; result.shortLinkurl = url; result.content = result.shortLinkurl; result.deeplink_url = GetDeeplink(result.shortLinkurl); return result; } } result.success = false; result.message = "转链失败"; result.reason = root.jd_union_open_promotion_common_get_responce.message; if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message; result.shortLinkurl = shortLinkurl; result.deeplink_url = GetDeeplink(result.shortLinkurl); _ = new LoggerLibrary("JdUnion", "promotion_get_error").Info(body).SaveAsync(); return result; } public async Task GetPromotionByAffAsync(JdDataDTO result, string shortLinkurl, CancellationToken cancellationToken = default) { string method = "jd.union.open.promotion.bysubunionid.get"; string version = "1.0"; var data = new { promotionCodeReq = new { materialId = shortLinkurl, command = 1, chainType = 2, } }; var body = await RequestAsync(method, version, data.Convert2Json(), cancellationToken); var root = body.Convert2Object(); //{"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\"}"}} string code = root.jd_union_open_promotion_bysubunionid_get_responce.code; var _promotion_data = root.jd_union_open_promotion_bysubunionid_get_responce.getResult; var promotion_data = _promotion_data.Convert2Object(); if ("0".Equals(code)) { if (promotion_data.code == 200) { var url = promotion_data.data.shortURL; result.success = true; result.message = "OK"; result.shortLinkurl = url; result.content = result.shortLinkurl; result.deeplink_url = GetDeeplink(result.shortLinkurl); return result; } } result.success = false; result.message = "转链失败"; result.reason = root.jd_union_open_promotion_bysubunionid_get_responce.message; if (string.IsNullOrEmpty(result.reason)) result.reason = promotion_data.message; result.shortLinkurl = shortLinkurl; result.deeplink_url = GetDeeplink(result.shortLinkurl); _ = new LoggerLibrary("JdUnion", "bysubunionid_get_error").Info(body).SaveAsync(); return result; } public async Task GetPromotionByCrawlerAsync(JdDataDTO result, string wareUrl, CancellationToken cancellationToken = default) { string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None); if (parts.Length > 1) { wareUrl = parts[0] + ".html"; } var ts = DateTime.Now.Convert2UnixTimestamp(true); string cookies = _account.cookies; string uuid = cookies.GetContentPart("__jdu=", ";"); string __jda = cookies.GetContentPart("__jda=", ";"); if (__jda.Split('.').Length > 1) { uuid = __jda.Split('.')[1]; } string useragent = _account.user_agent; if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer; string url = $"https://api.m.jd.com/api?functionId=unionPromoteLinkService&" + $"appid=unionpc&_={ts}&loginType=3&uuid={uuid}"; var args = new { funName = "getCode", param = new { couponLink = "", isPinGou = 0, materialId = result.itemId, materialType = 1, planId = 3479956501, promotionType = 15, receiveType = "cps", wareUrl = wareUrl, isSmartGraphics = 0, command = 1, ext1 = "618|pc|".UrlEncode() }, lientPageId = "jingfen_pc" }; string data = args.Convert2Json().UrlEncode(); WebClientUtility client = new WebClientUtility(); client.Proxy = _proxy; #if DEBUG client.Proxy = null; #endif client.SetContentType("application/x-www-form-urlencoded"); client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index"); client.AddHeaders("X-Rp-Client", "h5_1.0.0"); client.AddHeaders("Referer", "https://union.jd.com/"); client.AddHeaders("Origin", "https://union.jd.com"); client.UserAgent = useragent; client.AddHeaders("Cookie", cookies); client.Post($"body={data}"); var response = await client.RequestAsync(url, "POST", cancellationToken); string body = response.Body(); var root = body.Convert2JsonElement(); int code = root.Read("code"); string message = root.Read("message"); string shortCode = root.PathRead("data.shortCode"); if (code == 200) { result.success = true; result.message = "OK"; result.shortLinkurl = shortCode; result.content = result.shortLinkurl; result.deeplink_url = GetDeeplink(result.shortLinkurl); } else { if (string.IsNullOrEmpty(body)) message = "网络异常"; result.success = false; result.message = "转链失败"; result.reason = message; result.shortLinkurl = wareUrl; result.deeplink_url = GetDeeplink(result.shortLinkurl); _ = new LoggerLibrary("JdUnion", "GetPromotionByCrawlerAsync").Info(body).SaveAsync(); } return result; } } public class JdData { public int code { get; set; } public string message { get; set; } public string requestId { get; set; } public JdClickData data { get; set; } } public class JdClickData { public string shortURL { get; set; } public string clickURL { get; set; } public string jCommand { get; set; } } public class JdUnionResponse { public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_common_get_responce { get; set; } public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_bysubunionid_get_responce { get; set; } } public class JdUnionOpenPromotionCommonGetResponce { public string code { get; set; } public string getResult { get; set; } public string message { get; set; } public string requestId { get; set; } } }