| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- namespace molilian.core
- {
- public partial class TkPoolCore
- {
- /// <summary>
- /// 选择万能解析账号。解析池独立于转链节点及 enable_parse 配置。
- /// </summary>
- public static async Task<TkPoolDTO?> GetGeneralLinkParseAccountAsync()
- {
- var accounts = await ListAsync().ConfigureAwait(false);
- if (accounts == null) return null;
- foreach (var account in accounts.OrderBy(_ => Random.Shared.Next()))
- {
- if (!account.status || account.is_banned || !account.enable_general_link_parse_pool ||
- !HasGeneralLinkParseCredentials(account) || !PassesFastAccountChecks(account, TkAction.all))
- continue;
- DateTime now = DateTime.Now;
- if (account.daily_calls_limit > 0 &&
- RiskControlCore.GetCalls(TkChannelEnum.tb, account.id, now.ToString("yyyyMMdd")) >= account.daily_calls_limit)
- continue;
- if (account.hourly_calls_limit > 0 &&
- RiskControlCore.GetCalls(TkChannelEnum.tb, account.id, now.ToString("yyyyMMddHH")) >= account.hourly_calls_limit)
- continue;
- if (TryAcquireQps(account)) return account;
- }
- return null;
- }
- private static bool HasGeneralLinkParseCredentials(TkPoolDTO account)
- {
- if (string.IsNullOrWhiteSpace(account.appkey) || string.IsNullOrWhiteSpace(account.appSecret) ||
- string.IsNullOrWhiteSpace(account.open_pid))
- return false;
- string[] pidParts = account.open_pid.Split('_');
- return pidParts.Length == 4 && pidParts[0] == "mm" &&
- !string.IsNullOrWhiteSpace(pidParts[1]) && !string.IsNullOrWhiteSpace(pidParts[2]) &&
- long.TryParse(pidParts[3], out long adzoneId) && adzoneId > 0;
- }
- }
- }
|