| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- 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<JdDataDTO> 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<JdUnionResponse>();
- string code = root.jd_union_open_promotion_common_get_responce.code;
- if ("0".Equals(code))
- {
- var _promotion_data = root.jd_union_open_promotion_common_get_responce.getResult;
- var promotion_data = _promotion_data.Convert2Object<JdData>();
- 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;
- result.shortLinkurl = shortLinkurl;
- result.deeplink_url = GetDeeplink(result.shortLinkurl);
- _ = new LoggerLibrary("JdUnion", "promotion_get_error").Info(body).SaveAsync();
- return result;
- }
- public async Task<JdDataDTO> 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<JdUnionResponse>();
- string code = root.jd_union_open_promotion_common_get_responce.code;
- if ("0".Equals(code))
- {
- var _promotion_data = root.jd_union_open_promotion_common_get_responce.getResult;
- var promotion_data = _promotion_data.Convert2Object<JdData>();
- 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;
- result.shortLinkurl = shortLinkurl;
- result.deeplink_url = GetDeeplink(result.shortLinkurl);
- _ = new LoggerLibrary("JdUnion", "bysubunionid_get_error").Info(body).SaveAsync();
- return result;
- }
- public async Task<JdDataDTO> GetPromotionByCrawlerAsync(JdDataDTO result, string wareUrl, CancellationToken cancellationToken = default)
- {
- 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<int>("code");
- string message = root.Read<string>("message");
- string shortCode = root.PathRead<string>("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 JdClickData data { get; set; }
- }
- public class JdClickData
- {
- public string clickURL { get; set; }
- }
- public class JdUnionResponse
- {
- public JdUnionOpenPromotionCommonGetResponce jd_union_open_promotion_common_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; }
- }
- }
|