PddUnionPlus.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. var link_type = LinkTypeEnum.unknown;
  32. if (!string.IsNullOrEmpty(shortLinkurl) && shortLinkurl.StartsWith("https://p.pinduoduo.com/"))
  33. {
  34. link_type = LinkTypeEnum.other_aff;
  35. }
  36. return new PddDataDTO()
  37. {
  38. message = string.Empty,
  39. link_type = link_type,
  40. channel = TkChannelEnum.pdd,
  41. accountName = string.Empty,
  42. success = false,
  43. content = content,
  44. ip = ip,
  45. oaid = oaid,
  46. elapsedTime = 0,
  47. itemName = "点击打开拼多多APP",
  48. shortLinkurl = string.Empty,
  49. deeplink_url = string.Empty,
  50. create_time = DateTime.Now,
  51. end_point = _end_point,
  52. };
  53. }
  54. public async Task<PddDataDTO> PddParseAsync(string content, PddDataDTO result, CancellationToken cancellationToken = default)
  55. {
  56. string message = "OK";
  57. string url = GetLink(content);
  58. if (string.IsNullOrEmpty(url))
  59. {
  60. result.success = false;
  61. result.link_type = LinkTypeEnum.unknown;
  62. result.channel_type = ChannelTypeEnum.pdd;
  63. result.message = "放弃转链";
  64. result.reason = "无效链接";
  65. result.accountId = 0;
  66. result.accountName = string.Empty;
  67. result.content = content;
  68. return result;
  69. }
  70. string shortLinkurl = url;
  71. if (result.link_type == LinkTypeEnum.other_aff)
  72. {
  73. result.success = false;
  74. result.link_type = LinkTypeEnum.unknown;
  75. result.channel_type = ChannelTypeEnum.pdd;
  76. result.message = "放弃转链";
  77. result.reason = "其他推广链接";
  78. result.accountId = 0;
  79. result.accountName = string.Empty;
  80. result.content = content;
  81. return result;
  82. }
  83. if (!result.ip.StartsWith("127.0.0") && FlowControlIgnoreRequest(_config, out string reason))
  84. {
  85. result.success = false;
  86. result.link_type = LinkTypeEnum.unknown;
  87. result.channel_type = ChannelTypeEnum.pdd;
  88. result.message = "放弃转链";
  89. result.reason = reason;
  90. result.accountId = 0;
  91. result.accountName = string.Empty;
  92. result.content = content;
  93. return result;
  94. }
  95. switch (_account.work_mode)
  96. {
  97. case PddUnionWorkMode.SiteApi:
  98. result = await UnionGeneratelink(result, url, cancellationToken);
  99. break;
  100. //case PddUnionWorkMode.AffApi:
  101. // result = await GetPromotionByAffAsync(result, url, cancellationToken);
  102. // break;
  103. case PddUnionWorkMode.Crawler:
  104. default:
  105. result = await transferUrl(result, url, cancellationToken);
  106. break;
  107. }
  108. return result;
  109. }
  110. }
  111. }