TkPoolCore.GeneralLinkParse.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. namespace molilian.core
  2. {
  3. public partial class TkPoolCore
  4. {
  5. /// <summary>
  6. /// 选择万能解析账号。解析池独立于转链节点及 enable_parse 配置。
  7. /// </summary>
  8. public static async Task<TkPoolDTO?> GetGeneralLinkParseAccountAsync()
  9. {
  10. var accounts = await ListAsync().ConfigureAwait(false);
  11. if (accounts == null) return null;
  12. foreach (var account in accounts.OrderBy(_ => Random.Shared.Next()))
  13. {
  14. if (!account.status || account.is_banned || !account.enable_general_link_parse_pool ||
  15. !HasGeneralLinkParseCredentials(account) || !PassesFastAccountChecks(account, TkAction.all))
  16. continue;
  17. DateTime now = DateTime.Now;
  18. if (account.daily_calls_limit > 0 &&
  19. RiskControlCore.GetCalls(TkChannelEnum.tb, account.id, now.ToString("yyyyMMdd")) >= account.daily_calls_limit)
  20. continue;
  21. if (account.hourly_calls_limit > 0 &&
  22. RiskControlCore.GetCalls(TkChannelEnum.tb, account.id, now.ToString("yyyyMMddHH")) >= account.hourly_calls_limit)
  23. continue;
  24. if (TryAcquireQps(account)) return account;
  25. }
  26. return null;
  27. }
  28. private static bool HasGeneralLinkParseCredentials(TkPoolDTO account)
  29. {
  30. if (string.IsNullOrWhiteSpace(account.appkey) || string.IsNullOrWhiteSpace(account.appSecret) ||
  31. string.IsNullOrWhiteSpace(account.open_pid))
  32. return false;
  33. string[] pidParts = account.open_pid.Split('_');
  34. return pidParts.Length == 4 && pidParts[0] == "mm" &&
  35. !string.IsNullOrWhiteSpace(pidParts[1]) && !string.IsNullOrWhiteSpace(pidParts[2]) &&
  36. long.TryParse(pidParts[3], out long adzoneId) && adzoneId > 0;
  37. }
  38. }
  39. }