PddUnionPlus.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using dodohold.core;
  2. using System.Text.RegularExpressions;
  3. namespace molilian.core
  4. {
  5. public partial class PddUnionPlus
  6. {
  7. public static string _url_pattern = @"https?://(?:[\w-]+\.)*(?:yangkeduo\.com|pinduoduo\.com)(?:/[^\s]*)?";
  8. public static string GetLink(string content)
  9. {
  10. if (string.IsNullOrEmpty(content)) return content;
  11. string result = content;
  12. //
  13. Regex regex = new(_url_pattern);
  14. MatchCollection matches = regex.Matches(content);
  15. foreach (Match m in matches.Cast<Match>())
  16. {
  17. string url = m.Value;
  18. return url;
  19. }
  20. return string.Empty;
  21. }
  22. public static string GetDeeplink(string url)
  23. {
  24. string result = $"pinduoduo://com.xunmeng.pinduoduo/{url}";
  25. return result;
  26. }
  27. public static PddDataDTO GetFormattedObject(string content, string ip = "", string oaid = "")
  28. {
  29. string shortLinkurl = GetLink(content);
  30. string deeplink_url = GetDeeplink(shortLinkurl);
  31. return new PddDataDTO()
  32. {
  33. message = string.Empty,
  34. link_type = LinkTypeEnum.unknown,
  35. channel = TkChannelEnum.pdd,
  36. accountName = string.Empty,
  37. success = false,
  38. content = content,
  39. ip = ip,
  40. oaid = oaid,
  41. elapsedTime = 0,
  42. itemName = "点击打开拼多多APP",
  43. shortLinkurl = string.Empty,
  44. deeplink_url = string.Empty,
  45. create_time = DateTime.Now,
  46. end_point = _end_point,
  47. };
  48. }
  49. public async Task<PddDataDTO> PddParseAsync(string content, PddDataDTO result, CancellationToken cancellationToken = default)
  50. {
  51. string message = "OK";
  52. string url = GetLink(content);
  53. if (string.IsNullOrEmpty(url))
  54. {
  55. result.success = false;
  56. result.link_type = LinkTypeEnum.unknown;
  57. result.channel_type = ChannelTypeEnum.pdd;
  58. result.message = "放弃转链";
  59. result.reason = "无效链接";
  60. result.accountId = 0;
  61. result.accountName = string.Empty;
  62. result.content = content;
  63. return result;
  64. }
  65. string shortLinkurl = url;
  66. if (result.link_type == LinkTypeEnum.other_aff)
  67. {
  68. result.success = false;
  69. result.link_type = LinkTypeEnum.unknown;
  70. result.channel_type = ChannelTypeEnum.pdd;
  71. result.message = "放弃转链";
  72. result.reason = "其他推广链接";
  73. result.accountId = 0;
  74. result.accountName = string.Empty;
  75. result.content = content;
  76. return result;
  77. }
  78. if (!result.ip.StartsWith("127.0.0") && FlowControlIgnoreRequest(_config, out string reason))
  79. {
  80. result.success = false;
  81. result.link_type = LinkTypeEnum.unknown;
  82. result.channel_type = ChannelTypeEnum.pdd;
  83. result.message = "放弃转链";
  84. result.reason = reason;
  85. result.accountId = 0;
  86. result.accountName = string.Empty;
  87. result.content = content;
  88. return result;
  89. }
  90. switch (_account.work_mode)
  91. {
  92. case PddUnionWorkMode.SiteApi:
  93. result = await UnionGeneratelink(result, url, cancellationToken);
  94. break;
  95. //case PddUnionWorkMode.AffApi:
  96. // result = await GetPromotionByAffAsync(result, url, cancellationToken);
  97. // break;
  98. case PddUnionWorkMode.Crawler:
  99. default:
  100. result = await transferUrl(result, url, cancellationToken);
  101. break;
  102. }
  103. return result;
  104. }
  105. }
  106. }