parse.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. using System.Text;
  2. using dodohold.core;
  3. using System.Text.RegularExpressions;
  4. using System.Net;
  5. using System.Linq;
  6. using System.Security.Cryptography;
  7. using TencentCloud.Ecm.V20190719.Models;
  8. using System.Diagnostics;
  9. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  10. using System.Text.Json;
  11. using TencentCloud.Tcm.V20210413.Models;
  12. using TencentCloud.Tione.V20211111.Models;
  13. using System.Runtime.InteropServices.Marshalling;
  14. namespace molilian.core
  15. {
  16. public partial class AlimamaPlus
  17. {
  18. private string _accountName;
  19. private int _accountId;
  20. private string _company;
  21. private string _tb_token;
  22. private string _floorId;
  23. private string _refpid;
  24. private string _user_agent;
  25. private string _cookies;
  26. public string _proxyName;
  27. public WebProxy? _proxy = null;
  28. private string _api;
  29. private int _api_id = 0;
  30. public TkConfigDTO _config;
  31. private static string _end_point;
  32. private TkPoolDTO _account;
  33. static Random _random = new Random();
  34. public static string _url_pattern = @"https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";
  35. static AlimamaPlus()
  36. {
  37. _end_point = Environment.GetEnvironmentVariable("EndPoint");
  38. }
  39. public AlimamaPlus(TkPoolDTO account)
  40. {
  41. // string accountName, string tb_token, string floorId, string refpid,
  42. // string cookies, string user_agent, string nodeName
  43. _config = TkConfigCore.Get();
  44. _account = account;
  45. _accountId = account.id;
  46. _accountName = account.name;
  47. _company = account.company;
  48. _tb_token = account.tb_token;
  49. _floorId = account.floorId;
  50. _refpid = account.refpid;
  51. _cookies = account.cookies;
  52. _user_agent = account.user_agent?.Trim();
  53. if (!string.IsNullOrEmpty(account.nodeName))
  54. {
  55. _proxyName = ProxyNodesCore.GetSelectOne(account.nodeName);
  56. _proxy = ProxyNodesCore.GetOne(_proxyName);
  57. }
  58. _api = account.api;
  59. _api_id = account.api_id;
  60. }
  61. public bool ShouldIgnoreOtherAff(string content)
  62. {
  63. TkDataDTO result = new();
  64. //(_, _, var link_type, _) = InternalTextProcessing(content, ref result);
  65. InternalTextProcessing(content, ref result);
  66. return result.link_type == LinkTypeEnum.other_aff;
  67. }
  68. public async Task<TkDataDTO> UnionParseAsync(UnionParseRequest request, string content, TkDataDTO result, bool isTaobaoUrl, CancellationToken cancellationToken = default,
  69. Dictionary<string, long> swData = null)
  70. {
  71. result.itemName = "点击打开淘宝APP";
  72. result = await InternalTextProcessingAsync(content, result, cancellationToken, swData);
  73. bool ShouldStopAfterTextProcessing()
  74. {
  75. if (result.link_type == LinkTypeEnum.other_aff)
  76. {
  77. result.channel = TkChannelEnum.tb;
  78. result.channel_type = ChannelTypeEnum.tb;
  79. result.success = false;
  80. result.message = "放弃转链";
  81. result.reason = "其他推广链接";
  82. result.subCode = TkSubCodeEnum.OtherPromo;
  83. result.accountName = string.Empty;
  84. result.content = content;
  85. return true;
  86. }
  87. if (!result.success)
  88. {
  89. switch (result.link_type)
  90. {
  91. case LinkTypeEnum.profile:
  92. case LinkTypeEnum.live:
  93. case LinkTypeEnum.video:
  94. case LinkTypeEnum.note:
  95. case LinkTypeEnum.goods:
  96. case LinkTypeEnum.baseDomain:
  97. result.reason = string.Empty;
  98. break;
  99. default:
  100. if (string.IsNullOrWhiteSpace(result.reason)) result.reason = "非标准链接";
  101. if (result.subCode == TkSubCodeEnum.Other) result.subCode = TkSubCodeEnum.NonStdLink;
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. if (ShouldStopAfterTextProcessing()) return result;
  108. //============================== 放弃转链-地区过滤 ==============================
  109. bool is_ignore2 = FlowControlIgnoreRequest(request, out string reason);
  110. string message = "放弃转链";
  111. if (is_ignore2)
  112. {
  113. if ("7".Equals(_account.parseEndpoint))
  114. {
  115. message = "转链失败";
  116. result.reason = "fail2";
  117. }
  118. result.success = false;
  119. result.message = message;
  120. result.reason = reason;
  121. result.subCode = TkSubCodeEnum.TrafficCtrl;
  122. return result;
  123. }
  124. switch (request.CommerceType)
  125. {
  126. case 1:
  127. case 2:
  128. result.success = false;
  129. result.message = "放弃转链";
  130. result.reason = $"厂商放弃{request.CommerceType}";
  131. result.subCode = TkSubCodeEnum.PartnersDrop;
  132. return result;
  133. }
  134. //2025-02-06 增加重试机制
  135. int try_count = 0;
  136. while (try_count == 0 || try_count <= _config.tk_parse_retry_count)
  137. {
  138. if (try_count >= 3) break;
  139. (int ep_id, string tkEndpoint) = await TkEndpointManager.GetConvertApiAsync(_accountId, isTaobaoUrl, _account.parseEndpoint);
  140. result.tkEndpoint = ep_id;
  141. switch (tkEndpoint)
  142. {
  143. case "moose_share":
  144. result.endpoint_called = true;
  145. result = await endpoint_moose_share(result.content, result, cancellationToken);
  146. break;
  147. case "promo_goods":
  148. result.endpoint_called = true;
  149. result = await endpoint_promo_goods(result.content, result, cancellationToken);
  150. break;
  151. case "tool_links":
  152. result.endpoint_called = true;
  153. result = await endpoint_tool_links(result.content, result, cancellationToken);
  154. break;
  155. case "aliyun":
  156. result.endpoint_called = true;
  157. result = await endpoint_aliyun(result.content, result, cancellationToken);
  158. break;
  159. case "tbk_dg":
  160. result.endpoint_called = true;
  161. result = await endpoint_tbk_dg(result.content, result, cancellationToken);
  162. break;
  163. case "aiopen":
  164. result.endpoint_called = true;
  165. result = await endpoint_aiopen(result.content, result, cancellationToken);
  166. break;
  167. case "veapi":
  168. case "ddx":
  169. case "other_api":
  170. if (!string.IsNullOrEmpty(_api) && _api_id > 0)
  171. {
  172. var account = OtherApiPoolCore.Get(_api_id);
  173. if (account != null)
  174. {
  175. var core = new OtherApiPlus(account.name, account.key, account.sessionKey, tkEndpoint, account.api_url);
  176. string refpid = string.IsNullOrEmpty(account.refpid) ? _refpid : account.refpid;
  177. result.endpoint_called = true;
  178. result = await core.UnionParseAsync(result.content, refpid, result, cancellationToken);
  179. return result;
  180. }
  181. }
  182. else
  183. {
  184. result.link_type = LinkTypeEnum.unknown;
  185. result.subCode = TkSubCodeEnum.Other;
  186. result.success = false;
  187. result.message = "放弃转链";
  188. result.reason = "接口配置失败";
  189. return result;
  190. }
  191. break;
  192. //case "ALL":
  193. // //没有可以用的接口了
  194. // result.link_type = LinkTypeEnum.unknown;
  195. // result.subCode = TkSubCodeEnum.ParseDeny;
  196. // result.success = false;
  197. // result.message = "放弃转链";
  198. // result.reason = "接口风控ALL";
  199. // return result;
  200. default:
  201. result.link_type = LinkTypeEnum.unknown;
  202. result.subCode = TkSubCodeEnum.ParseDeny;
  203. result.success = false;
  204. result.message = "放弃转链";
  205. result.reason = $"接口风控{tkEndpoint}";
  206. break;
  207. }
  208. if (!"该链接不支持转化,请更换链接尝试".Equals(result.message)) break;
  209. try_count++;
  210. }
  211. result.retry_count = try_count;
  212. result.commercial = result.success;
  213. if (result.success && "brwsimilar".Equals(request.RiskStrategy))
  214. {
  215. // 需要搜同款才进入这个逻辑
  216. result.PromotionImg = await InternalCallPromotionQuery(result.pic, request.Oaid, request.Ip, _account.useCouponLinkFirst);
  217. // "pic": "https://img.alicdn.com/i4/6000000004750/O1CN01w4wgqa1kxYS1BadZp_!!6000000004750-0-sm.jpg",
  218. //result.pic
  219. //result.PromotionImg[*].pic
  220. int i = 0;
  221. foreach (var item in result.PromotionImg)
  222. {
  223. i++;
  224. item.clickTracks = TracksCore.BuildBrwSimilarPath(TrackType.Click, result, item, i);
  225. item.exposeTracks = TracksCore.BuildBrwSimilarPath(TrackType.Expose, result, item, i);
  226. item.pic = NormalizeAlicdnImageUrl(item.pic);
  227. }
  228. DateTime now = DateTime.Now;
  229. if (now < new DateTime(2026, 8, 22))
  230. {
  231. _ = new LoggerLibrary("AlimamaPlus", "PromotionImageCount")
  232. .Info(now.ToString("yyyy-MM-dd HH:mm:ss.fff"), i.ToString())
  233. .SaveAsync();
  234. }
  235. }
  236. result.pic = NormalizeAlicdnImageUrl(result.pic);
  237. if (!result.success)
  238. {
  239. result.itemName = "点击打开淘宝APP";
  240. }
  241. if (string.IsNullOrEmpty(result.itemName) || result.link_type == LinkTypeEnum.profile)
  242. {
  243. result.itemName = "点击打开淘宝APP";
  244. }
  245. return result;
  246. }
  247. private async Task<List<PromotionQueryItemDTO>> InternalCallPromotionQuery(string pic, string oaid, string ip, bool useCouponLinkFirst)
  248. {
  249. if (string.IsNullOrWhiteSpace(pic))
  250. {
  251. return [];
  252. }
  253. static bool TryParseItems(JsonElement element, out List<PromotionQueryItemDTO> items)
  254. {
  255. items = [];
  256. if (element.ValueKind == JsonValueKind.Array)
  257. {
  258. items = JsonSerializer.Deserialize<List<PromotionQueryItemDTO>>(element.GetRawText()) ?? [];
  259. return true;
  260. }
  261. if (element.ValueKind != JsonValueKind.Object)
  262. {
  263. return false;
  264. }
  265. if (element.TryGetProperty("promotionImg", out var promotionImg) && promotionImg.ValueKind == JsonValueKind.Array)
  266. {
  267. items = JsonSerializer.Deserialize<List<PromotionQueryItemDTO>>(promotionImg.GetRawText()) ?? [];
  268. return true;
  269. }
  270. if (element.TryGetProperty("PromotionImg", out promotionImg) && promotionImg.ValueKind == JsonValueKind.Array)
  271. {
  272. items = JsonSerializer.Deserialize<List<PromotionQueryItemDTO>>(promotionImg.GetRawText()) ?? [];
  273. return true;
  274. }
  275. return false;
  276. }
  277. static List<PromotionQueryItemDTO> RemoveFirstItem(List<PromotionQueryItemDTO> items)
  278. {
  279. return items.Count > 0 ? items.Skip(1).ToList() : [];
  280. }
  281. string requestUrl = "https://similar.molilian.com/api/unsafePromotionQuery";
  282. string targetPic = NormalizeAlicdnImageUrl(pic.StartsWith("//") ? $"https:{pic}" : pic, 1200);
  283. object postData = new
  284. {
  285. url = targetPic,
  286. oaid,
  287. ip,
  288. recommand = false,
  289. useCouponLinkFirst
  290. };
  291. string post = postData.Convert2Json();
  292. try
  293. {
  294. var client = new WebClientUtility().SetContentType("application/json")
  295. .Post(post);
  296. var response = await client.RequestAsync(requestUrl, "POST");
  297. var body = response.Body();
  298. if (string.IsNullOrWhiteSpace(body))
  299. {
  300. return [];
  301. }
  302. var root = body.Convert2JsonElement();
  303. if (TryParseItems(root, out var result))
  304. {
  305. return RemoveFirstItem(result);
  306. }
  307. if (root.ValueKind == JsonValueKind.Object)
  308. {
  309. if (root.TryGetProperty("data", out var data) && TryParseItems(data, out result))
  310. {
  311. return RemoveFirstItem(result);
  312. }
  313. if (root.TryGetProperty("result", out var resultNode) && TryParseItems(resultNode, out result))
  314. {
  315. return RemoveFirstItem(result);
  316. }
  317. }
  318. _ = new LoggerLibrary("AlimamaPlus", "InternalCallPromotionQuery")
  319. .Info(post, body)
  320. .SaveAsync();
  321. }
  322. catch (Exception ex)
  323. {
  324. _ = new LoggerLibrary("AlimamaPlus", "InternalCallPromotionQuery")
  325. .Info(requestUrl, post)
  326. .Info(ex.Message, ex.StackTrace)
  327. .SaveAsync();
  328. }
  329. return [];
  330. }
  331. private static string NormalizeAlicdnImageUrl(string pic, int size = 400)
  332. {
  333. string formatSuffix = size switch
  334. {
  335. 1200 => "_1200x1200q90.jpg_.webp",
  336. _ => "_400x400q90.jpg_.webp"
  337. };
  338. if (string.IsNullOrWhiteSpace(pic))
  339. {
  340. return pic;
  341. }
  342. if (!pic.Contains("img.alicdn.com", StringComparison.OrdinalIgnoreCase))
  343. {
  344. return pic;
  345. }
  346. if (Regex.IsMatch(pic, @"_\d+x\d+q\d+\.jpg_\.webp(?:[?#].*)?$", RegexOptions.IgnoreCase))
  347. {
  348. return pic;
  349. }
  350. return $"{pic}{formatSuffix}";
  351. }
  352. public static bool ContainsTaobaoId(string content, string rawContent)
  353. {
  354. var match = Regex.Match(content, @"(?<=[?&]id=)\d+(?=&|$)");
  355. if (!match.Success) return false;
  356. string id = match.Value;
  357. return Regex.IsMatch(rawContent, $@"(^|\D){id}($|\D)");
  358. }
  359. public static string ReplaceUrls(string content, string shortLink)
  360. {
  361. if (string.IsNullOrEmpty(content) || string.IsNullOrEmpty(shortLink)) return content;
  362. string result = content;
  363. Regex regex = new(_url_pattern);
  364. MatchCollection matches = regex.Matches(content);
  365. foreach (Match m in matches.Cast<Match>())
  366. {
  367. string url = m.Value;
  368. if (url.Contains("https://s.tb.cn/") ||
  369. url.Contains("http://s.tb.cn/") ||
  370. url.Contains("http://m.tb.cn/") ||
  371. url.Contains("http://m.tb.cn/") ||
  372. url.Contains("http://e.tb.cn/") ||
  373. url.Contains("https://e.tb.cn/"))
  374. {
  375. result = result.Replace(url, shortLink);
  376. }
  377. }
  378. return result;
  379. }
  380. public static string RemoveUrls(string content)
  381. {
  382. if (string.IsNullOrEmpty(content)) return content;
  383. string result = content;
  384. Regex regex = new(_url_pattern);
  385. MatchCollection matches = regex.Matches(content);
  386. foreach (Match m in matches.Cast<Match>())
  387. {
  388. string url = m.Value;
  389. result = result.Replace(url, string.Empty);
  390. }
  391. return result;
  392. }
  393. public static string GetLink(string content)
  394. {
  395. if (string.IsNullOrEmpty(content)) return content;
  396. //string pattern = @"https?:\/\/?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?(\?[\S]+)?";
  397. Regex regex = new(_url_pattern);
  398. MatchCollection matches = regex.Matches(content);
  399. string result = string.Empty;
  400. if (matches.Count > 0)
  401. {
  402. result = Regex.Replace(matches[^1].Value, @"\++$", "");
  403. }
  404. result = result.Replace("&nbsp;", "");
  405. if (result.StartsWith("http://e.tb.cn/")) result = result.Replace("http://", "https://");
  406. return result;
  407. }
  408. public static string GetTaobaoLink(string content)
  409. {
  410. if (string.IsNullOrEmpty(content)) return content;
  411. string pattern = @"(https?://(?:[\w-]+\.)*(?:tb\.cn|taobao\.com|juhuasuan\.com|tmall\.com|tmall\.hk)(?:/[a-zA-Z0-9\-\._~:/?#[\]@!$&'()*+,;=%]*)?)";
  412. Regex regex = new(pattern, RegexOptions.IgnoreCase);
  413. MatchCollection matches = regex.Matches(content);
  414. if (matches.Count > 0)
  415. {
  416. string result = Regex.Replace(matches[^1].Value, @"\++$", "");
  417. return result;
  418. }
  419. return string.Empty;
  420. }
  421. public static string GetDeeplink(string url)
  422. {
  423. if (string.IsNullOrEmpty(url)) return "tbopen://m.taobao.com/tbopen/index.html";
  424. string result = $"tbopen://m.taobao.com/tbopen/index.html?action=ali.open.nav&module=h5&h5Url={url.UrlEncode()}";
  425. //string result = $"tbopen://m.taobao.com/tbopen/index.html?action=ali.open.nav&module=h5&bootImage=0&afcPromotionOpen=false&bc_fl_src=h5_huanduan&source=slk_dp&h5Url={url.UrlEncode()}";
  426. return result;
  427. }
  428. public static string GetTitle(string content)
  429. {
  430. if (string.IsNullOrEmpty(content)) return string.Empty;
  431. string url = GetLink(content);
  432. if (!string.IsNullOrEmpty(url)) content = content.Replace(url, string.Empty);
  433. content = content.Replace("点击链接直接打开 或者 淘宝搜索直接打开", string.Empty).Trim();
  434. string[] words = Regex.Split(content, @"\s+");
  435. string word = words[^1];
  436. word = word.TrimStart('「').TrimEnd('」');
  437. return word;
  438. }
  439. public static bool IgnoreRegionIncluded(string _ignoreRegions, string? ipInfo, out string regionInfo)
  440. {
  441. regionInfo = string.Empty;
  442. if (string.IsNullOrEmpty(_ignoreRegions) || string.IsNullOrEmpty(ipInfo)) return false;
  443. string[] parts = ipInfo.Split('|');
  444. string countryInfo = null;
  445. if (parts.Length >= 4)
  446. {
  447. countryInfo = parts[0];
  448. regionInfo = parts[3];
  449. }
  450. if (string.IsNullOrEmpty(regionInfo)) return false;
  451. if (string.IsNullOrEmpty(countryInfo)) return false;
  452. string[] ignoreRegions = _ignoreRegions.Split('|');
  453. if (ignoreRegions.Contains(regionInfo)) return true;
  454. if (ignoreRegions.Contains(countryInfo))
  455. {
  456. regionInfo = countryInfo;
  457. return true;
  458. }
  459. foreach (var region in ignoreRegions)
  460. {
  461. if ("海外".Equals(region) && !"中国".Equals(countryInfo) && !"0".Equals(countryInfo))
  462. {
  463. regionInfo = "海外";
  464. return true;
  465. }
  466. }
  467. return false;
  468. }
  469. public static async Task<bool> OtherPlatformAsync(string content)
  470. {
  471. try
  472. {
  473. //腾讯会议
  474. string wemeetId = await ToolParsePlus.GetWemeetIdAsync(content);
  475. if (!string.IsNullOrEmpty(wemeetId)) return true;
  476. //百度网盘
  477. string surl = string.Empty, pwd = string.Empty;
  478. _ = ToolParsePlus.GetPanLink(content, ref surl, ref pwd);
  479. if (!string.IsNullOrEmpty(surl)) return true;
  480. //JD
  481. string url = JdUnionPlus.GetLink(content);
  482. var urlType = JdUnionPlus.GetLinkType(url, out _, out _);
  483. if (urlType != LinkTypeEnum.unknown) return true;
  484. //DY
  485. url = DyUnionPlus.GetLink(content);
  486. urlType = DyUnionPlus.GetLinkType(content, url);
  487. if (urlType != LinkTypeEnum.unknown) return true;
  488. }
  489. catch { }
  490. return false;
  491. }
  492. public static bool MatchRegexes(string text, List<string> extended)
  493. {
  494. text = RemoveUrls(text);
  495. string special_symbols = $"\\$\\(\\)\\/\\#\\&\\<\\>฿¢¥¥$🗝₰₵₲¤₪₴€₤£₳《¢💰🔑🎵✔💲🔐📲";
  496. string[] base_patterns =
  497. [
  498. $@"(.*?\d{{2}}\s[a-zA-Z]{{2}}\d{{4}}\s.*?[{special_symbols}]+[a-zA-Z0-9\s]+[{special_symbols}]).*",
  499. $@"[{special_symbols}]+\s*([a-zA-Z]{{1,2}}\d{{2,4}}\s[a-zA-Z0-9]{{11}}|[a-zA-Z0-9]{{11}}[a-zA-Z]{{1,2}}\d{{2,4}}\s|[a-zA-Z0-9]{{11}})\s*[{special_symbols}]+",
  500. @"🍑♭ɑ◑下单|Tao宝"
  501. ];
  502. List<string> mergedArray = extended.Union(base_patterns).ToList();
  503. /*
  504. (.*?\\d{2}\\s[a-zA-Z]{2}\\d{4}\\s.*?[\\$\\(\\)\\/\\#\\&\\<\\>฿¢¥¥$🗝₰₵₲¤₪₴€₤£₳《¢💰🔑🎵✔💲🔐📲]+[a-zA-Z0-9\\s]+[\\$\\(\\)\\/\\#\\&\\<\\>฿¢¥¥$🗝₰₵₲¤₪₴€₤£₳《¢💰🔑🎵✔💲🔐📲])).*\n[\\$\\(\\)\\/\\#\\&\\<\\>฿¢¥¥$🗝₰₵₲¤₪₴€₤£₳《¢💰🔑🎵✔💲🔐📲]+\\s*([a-zA-Z]{1,2}\\d{2,4}\\s[a-zA-Z0-9]{11}|[a-zA-Z0-9]{11}[a-zA-Z]{1,2}\\d{2,4}\\s|[a-zA-Z0-9]{11})\\s*[\\$\\(\\)\\/\\#\\&\\<\\>฿¢¥¥$🗝₰₵₲¤₪₴€₤£₳《¢💰🔑🎵✔💲🔐📲]+\n🍑♭ɑ◑下单|Tao宝
  505. 【3瓶】恩威万蓝莓叶黄素酯软糖儿童成人上班族如酸涩肿胀可服用,<z5TYWAblvTw >:// HU7709,打開/
  506. 置顶小助手,方便下次查询\r\n1★【劵】无\r\n2★【返.佣】 0.29圆 \r\n3★【付款.价】24.9 圆\r\n \r\n 1 ¢HZv5WAboi0D¢(/:/ HU8866\r\
  507. n长按覆制本内容,打开TaoBao/\r\n-\r\n返佣是指商家的推广佣.金\r\n通过我回复的口令下単收货后,我
  508. 会微信红.苞返给你!!\r\n\r\n有疑问可回复“人工”咨询客服*/
  509. //🍑🔗上 水和肌精华水& CZ0 VWdCWC2gj97&,
  510. //6฿04ZDWzrwxjN)/ CA97
  511. //1😘 腹制这条(CZ00 iHvtWzrXa7O(:/
  512. //¥EC8DG4Zj0dhd8DOw¥MF6563 oIo0WzOF1Cp##X-PyVpHiPlyj1OP##
  513. //6.6₵vU2jWzIW3Qx₲/ CZ5224
  514. //$F56nWzIDSFZ$
  515. //0復製这条口令( CZ00 D0M4WzI0jFJ¢,📱咑開[Tao宝]就可下单:/
  516. //8fuzhi本条消息:¤ CZ3458 JSR1WzrPCBU¤,打开🍑♭ɑ◑下单/
  517. //5€Lz6SWzrkLDw¥:// CZ13
  518. //3₲Igq3Wzkc5np₳:// CZ15
  519. //9.9🎈【康师傅易拉罐6罐】口伶:6₰TnxKWzr0wff₪:// CZ69
  520. //4₲99Y0WzJdK6S₳:// CZ46
  521. //4fuzhi本条消息:¤ CZ0002 WVCSWzrk6Ix¤,打开🍑♭ɑ◑下单/
  522. bool anyMatch = false;
  523. foreach (string pattern in mergedArray)
  524. {
  525. if (Regex.IsMatch(text, pattern, RegexOptions.IgnoreCase))
  526. {
  527. anyMatch = true;
  528. }
  529. }
  530. return anyMatch;
  531. }
  532. public static bool MatchOtherInfo(string text, List<string> extended)
  533. {
  534. string[] base_patterns =
  535. [
  536. "[ďȌƯƔɪƝɖƟɏƖԂȎȗϓɫɧơȲǏđǫƲƳɨǹƊȮǚƴɬɲƿȖȳɳɗʮϔӢǙɦɒɎƥʘưΊƞǪȈʠΌǓϒίȠƠƱƗǸþŌŬÿĩŅÞÓũŸÎŎûįŇĎÖÙŷÏňÜÝÍñĎÒüŶľńĎ0ųŷÏŇdǒǔyí℡抖yí℡ÞŐûŷÌñ]{6}",
  537. @"(?:.+)极速版(?:口令|搜索)",
  538. @"##[a-zA-Z0-9]+##\[抖音(?:极速版)?(?:口令|搜索)\]",
  539. @"岽|亰|菄|京东|婛",
  540. "打开【剪映】",
  541. "weishi://|baiduhaokan://",
  542. "复制打开「UC浏览器」|UC瀏覽器",
  543. "番茄免费小说",
  544. @"\?chanTag=[^&\s]*口令",
  545. @"(https?://pan\.baidu\.com/s/[A-Za-z0-9?\-_=]+)",
  546. @"https?:\/\/meeting\.tencent\.com[^\s]*",
  547. @"#腾讯会议:(\d{3}-\d{3}-\d{3})"
  548. ];
  549. List<string> mergedArray = extended.Union(base_patterns).ToList();
  550. bool anyMatch = false;
  551. foreach (string pattern in mergedArray)
  552. {
  553. if (Regex.IsMatch(text, pattern, RegexOptions.IgnoreCase))
  554. {
  555. anyMatch = true;
  556. }
  557. }
  558. return anyMatch;
  559. }
  560. public static bool MatchMultiToken(string text, List<string> extended)
  561. {
  562. text = RemoveUrls(text);
  563. string special_symbols = $"\\$\\(\\)\\/\\#\\&\\<\\>฿¢¥¥$🗝₰₵₲¤₪₴€₤£₳《¢💰🔑🎵✔💲🔐📲";
  564. string[] base_patterns =
  565. [
  566. @"[!$¥%]+([a-zA-Z0-9]{16})[!$¥%]+",
  567. @"\^v(\d+#[a-zA-Z0-9]+)(?:\?.*)?\^",
  568. "##([a-zA-Z0-9\\-]+)##",
  569. $@"(.*?\d{{2}}\s[a-zA-Z]{{2}}\d{{4}}\s.*?[{special_symbols}]+[a-zA-Z0-9\s]+[{special_symbols}]).*",
  570. $@"[{special_symbols}]+\s*([a-zA-Z]{{1,2}}\d{{2,4}}\s[a-zA-Z0-9]{{11}}|[a-zA-Z0-9]{{11}}[a-zA-Z]{{1,2}}\d{{2,4}}\s|[a-zA-Z0-9]{{11}})\s*[{special_symbols}]+",
  571. ];
  572. // PAGE6:/^v130091#P2J6EDxN8p8?chanTag=d9dc522bdea27437514052ea50f6a787^
  573. List<string> mergedArray = extended.Union(base_patterns).ToList();
  574. int matchCount = 0;
  575. foreach (string pattern in mergedArray)
  576. {
  577. Match match = Regex.Match(text, pattern, RegexOptions.IgnoreCase);
  578. if (match.Success)
  579. {
  580. matchCount++;
  581. text = text.Replace(match.Groups[^1].Value, ""); // 移除匹配的部分文本
  582. }
  583. }
  584. return matchCount >= 2;
  585. }
  586. public static bool FilterRiskLink(string ip, string oaid, string content, out string reason)
  587. {
  588. reason = string.Empty;
  589. string itemId = ExtractItemId(content);
  590. if (string.IsNullOrEmpty(itemId)) return false;
  591. string cacheKey = $":cache:parse:{ip}_{oaid}_{itemId}";
  592. int flag = RedisHelper.Get<int>(cacheKey);
  593. if (flag > 0)
  594. {
  595. reason = $"口令用户";
  596. return true;
  597. }
  598. return false;
  599. }
  600. public static bool ShouldIgnoreRequest(UnionParseRequest request, out string reason)
  601. {
  602. reason = string.Empty;
  603. ////2025-05-11 brw不做风控
  604. //if (!string.IsNullOrEmpty(riskStrategy) && !"os".Equals(riskStrategy) && launchScene != -1) return false;
  605. switch (request.RiskStrategy)
  606. {
  607. case "tbpush":
  608. case "brwsimilar":
  609. case "icon":
  610. return false;
  611. }
  612. try
  613. {
  614. // IP和流量控制
  615. var config = TkConfigCore.Get();
  616. string ignorePercentageCity = config.ignorePercentageCity;
  617. string? ipInfo = IP2RegionPlus.Search(request.Ip);
  618. if (!TestParseCore.InWhitelist(request.Ip, request.Oaid) && IgnoreRegionIncluded(ignorePercentageCity, ipInfo, out string regionInfo))
  619. {
  620. reason = $"地区控制:{regionInfo}";
  621. return true;
  622. }
  623. if (TkLogCore.InBlacklist(config.blacklist_oaid, request.Oaid))
  624. {
  625. reason = "OAID黑名单";
  626. return true;
  627. }
  628. int limit_num = config.tk_limit_per_ip_24h;
  629. if (!TestParseCore.InWhitelist(request.Ip, request.Oaid) && limit_num > 0)
  630. {
  631. int num = TkLogCore.getClientRequestTotalByIp(TkChannelEnum.tb, request.Ip);
  632. if (num >= limit_num)
  633. {
  634. reason = "IP控制";
  635. return true;
  636. }
  637. }
  638. limit_num = config.tk_limit_per_oaid_24h;
  639. if (!TestParseCore.InWhitelist(request.Ip, request.Oaid) && limit_num > 0)
  640. {
  641. int num = TkLogCore.getClientRequestTotalByOAID(TkChannelEnum.tb, request.Oaid);
  642. if (num >= limit_num)
  643. {
  644. reason = "OAID控制";
  645. return true;
  646. }
  647. }
  648. }
  649. catch (Exception ex)
  650. {
  651. reason = "配置异常";
  652. }
  653. return false;
  654. }
  655. public static bool FlowControlIgnoreRequest(UnionParseRequest request, out string reason)
  656. {
  657. reason = string.Empty;
  658. ////2025-05-11 brw不做风控
  659. //if (!string.IsNullOrEmpty(riskStrategy) && !"os".Equals(riskStrategy) && launchScene != -1) return false;
  660. switch (request.RiskStrategy)
  661. {
  662. case "tbpush":
  663. case "brwsimilar":
  664. case "icon":
  665. return false;
  666. }
  667. if (TestParseCore.InWhitelist(request.Ip, request.Oaid)) return false;
  668. try
  669. {
  670. // IP和流量控制
  671. var config = TkConfigCore.Get();
  672. int ignorePercentage = config.ignorePercentage;
  673. if (ignorePercentage == 0) return false;
  674. var randomValue = (decimal)_random.Next(0, 100);
  675. bool result = randomValue <= ignorePercentage; // 如果生成的随机数小于忽略百分比,则返回 true,表示需要忽略请求
  676. if (result)
  677. {
  678. reason = "流量控制";
  679. return true;
  680. }
  681. }
  682. catch (Exception ex)
  683. {
  684. reason = $"配置异常";
  685. }
  686. return false;
  687. }
  688. public static bool IsDigitsOnly(string? s)
  689. {
  690. return !string.IsNullOrEmpty(s)
  691. && s.AsSpan().IndexOfAnyExceptInRange('0', '9') < 0;
  692. }
  693. public static TkDataDTO GetFormattedObject(UnionParseRequest request)
  694. {
  695. string content = request.Content;
  696. switch (request.RiskStrategy)
  697. {
  698. case "tbpush":
  699. case "brwsimilar":
  700. case "icon":
  701. case "req":
  702. if (IsDigitsOnly(content))
  703. {
  704. content = $"https://item.taobao.com/item.htm?id={content}";
  705. }
  706. break;
  707. }
  708. string shortLinkurl = GetTaobaoLink(content);
  709. string deeplink_url = GetDeeplink(shortLinkurl);
  710. return new TkDataDTO()
  711. {
  712. message = string.Empty,
  713. subCode = TkSubCodeEnum.Other,
  714. channel = TkChannelEnum.tb,
  715. accountName = string.Empty,
  716. success = false,
  717. content = content,
  718. rawContent = request.Content,
  719. link_type = LinkTypeEnum.unknown,
  720. ip = request.Ip,
  721. oaid = request.Oaid,
  722. couponAmount = 0,
  723. taoToken = string.Empty,
  724. elapsedTime = 0,
  725. itemName = "点击打开淘宝APP",
  726. shortLinkurl = shortLinkurl,
  727. deeplink_url = deeplink_url,
  728. create_time = DateTime.Now,
  729. end_point = _end_point,
  730. parse_type = request.Type,
  731. riskStrategy = request.RiskStrategy,
  732. launchScene = request.LaunchScene,
  733. };
  734. }
  735. public static string OppoDecode(string content)
  736. {
  737. try
  738. {
  739. string secretKey = "BwFeIvOEDZy9MFGi0JLZBO4yEhR44DGV";
  740. byte[] keyBytes = Encoding.UTF8.GetBytes(secretKey);
  741. if (!content.Contains("%IV%")) return content;
  742. string cipherText = content.GetContentPart("", "%IV%");
  743. string ivText = content.GetContentPart("%IV%", "");
  744. byte[] cipherBytes = Convert.FromBase64String(cipherText);
  745. byte[] ivBytes = Convert.FromBase64String(ivText);
  746. using RijndaelManaged aes = new();
  747. aes.Key = keyBytes;
  748. aes.IV = ivBytes;
  749. aes.Mode = CipherMode.CFB;
  750. aes.Padding = PaddingMode.PKCS7;
  751. ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
  752. var outBytes = decryptor.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
  753. content = outBytes.ConvertToString();
  754. }
  755. catch (Exception e) { }
  756. return content;
  757. }
  758. }
  759. }