修复火箭工单过盾同步问题
This commit is contained in:
@@ -16,65 +16,74 @@ class AntiBotConfigBuilder
|
||||
/**
|
||||
* 为指定工单类型与落地页 URL 构建 Node antiBot 配置;未启用类型返回 null
|
||||
*
|
||||
* @param string $landingUrlHint HTTP 预解析或历史上次落地的长链(可选)
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public static function build(string $ticketType, string $pageUrl): ?array
|
||||
public static function build(string $ticketType, string $pageUrl, string $landingUrlHint = ''): ?array
|
||||
{
|
||||
$enabledTypes = self::getEnabledTypes();
|
||||
if (!in_array($ticketType, $enabledTypes, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sessionHost = self::resolveSessionHost($ticketType, $pageUrl);
|
||||
if ($sessionHost === '') {
|
||||
$sessionScope = self::resolveSessionScope($ticketType, $pageUrl, $landingUrlHint);
|
||||
if ($sessionScope === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sessionKey = $ticketType . ':' . $sessionHost;
|
||||
$sessionKey = $ticketType . ':' . $sessionScope;
|
||||
$ttlMinutes = self::getSessionTtlMinutes();
|
||||
|
||||
$businessHostHint = self::resolveBusinessHostHint($ticketType, $pageUrl, $landingUrlHint);
|
||||
|
||||
return [
|
||||
'enabled' => true,
|
||||
'profile' => 'real',
|
||||
'turnstile' => self::defaultTurnstile($ticketType),
|
||||
'solverFallback' => self::defaultSolverFallback($ticketType),
|
||||
'cfClearanceRequired'=> self::defaultCfClearanceRequired($ticketType),
|
||||
'sessionKey' => $sessionKey,
|
||||
'challengeTimeoutMs' => 60000,
|
||||
'sessionTtlMinutes' => $ttlMinutes,
|
||||
'businessHostHint' => self::defaultBusinessHostHint($ticketType, $sessionHost),
|
||||
'enabled' => true,
|
||||
'profile' => 'real',
|
||||
'turnstile' => self::defaultTurnstile($ticketType),
|
||||
'solverFallback' => self::defaultSolverFallback($ticketType),
|
||||
'cfClearanceRequired' => self::defaultCfClearanceRequired($ticketType),
|
||||
'sessionKey' => $sessionKey,
|
||||
'challengeTimeoutMs' => 60000,
|
||||
'sessionTtlMinutes' => $ttlMinutes,
|
||||
'businessHostHint' => $businessHostHint,
|
||||
'landingUrlHint' => $landingUrlHint !== '' ? $landingUrlHint : '',
|
||||
] + self::postCfReadyExtras($ticketType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话域:A2C 短链(yyk.ink)仍用业务域 user.a2c.chat 复用 Real Browser 会话
|
||||
* 会话 scope:A2C 短链固定业务域;火箭长链用动态 host、短链用 share.{token}
|
||||
*/
|
||||
public static function resolveSessionScope(string $ticketType, string $pageUrl, string $landingUrlHint = ''): string
|
||||
{
|
||||
if ($ticketType === 'a2c') {
|
||||
return self::resolveA2cSessionHost($pageUrl, $landingUrlHint);
|
||||
}
|
||||
|
||||
if ($ticketType === 'huojian') {
|
||||
return self::resolveHuojianSessionScope($pageUrl, $landingUrlHint);
|
||||
}
|
||||
|
||||
$host = strtolower(trim((string) parse_url($pageUrl, PHP_URL_HOST)));
|
||||
|
||||
return $host !== '' ? $host : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 兼容旧调用,等价 resolveSessionScope
|
||||
*/
|
||||
public static function resolveSessionHost(string $ticketType, string $pageUrl): string
|
||||
{
|
||||
$host = strtolower(trim((string) parse_url($pageUrl, PHP_URL_HOST)));
|
||||
if ($host === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($ticketType === 'a2c') {
|
||||
if (strpos($host, 'a2c.chat') !== false) {
|
||||
return $host;
|
||||
}
|
||||
|
||||
return 'user.a2c.chat';
|
||||
}
|
||||
|
||||
return $host;
|
||||
return self::resolveSessionScope($ticketType, $pageUrl, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 sessionKey(供 cron 分组调度使用)
|
||||
*/
|
||||
public static function resolveSessionKey(string $ticketType, string $pageUrl): string
|
||||
public static function resolveSessionKey(string $ticketType, string $pageUrl, string $landingUrlHint = ''): string
|
||||
{
|
||||
$host = self::resolveSessionHost($ticketType, $pageUrl);
|
||||
$scope = self::resolveSessionScope($ticketType, $pageUrl, $landingUrlHint);
|
||||
|
||||
return $ticketType . ':' . ($host !== '' ? $host : 'unknown');
|
||||
return $ticketType . ':' . ($scope !== '' ? $scope : 'unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,6 +142,16 @@ class AntiBotConfigBuilder
|
||||
];
|
||||
}
|
||||
|
||||
if ($ticketType === 'huojian') {
|
||||
return [
|
||||
'postCfReadyUrlContains' => HuojianUrlHelper::BUSINESS_PATH_NEEDLE,
|
||||
'postCfReadySelector' => '.el-message-box__input',
|
||||
'postCfReadyTimeoutMs' => 45000,
|
||||
'postCfSettleMs' => 500,
|
||||
'postCfSpaWaitMs' => 8000,
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -159,10 +178,63 @@ class AntiBotConfigBuilder
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function defaultBusinessHostHint(string $ticketType, string $sessionHost): string
|
||||
/**
|
||||
* 火箭/A2C 业务域 hint:优先长链动态 host,其次 landing 预解析
|
||||
*/
|
||||
private static function resolveBusinessHostHint(string $ticketType, string $pageUrl, string $landingUrlHint): string
|
||||
{
|
||||
if ($ticketType === 'a2c') {
|
||||
return $sessionHost;
|
||||
return self::resolveA2cSessionHost($pageUrl, $landingUrlHint);
|
||||
}
|
||||
|
||||
if ($ticketType === 'huojian') {
|
||||
$host = HuojianUrlHelper::extractBusinessHost($pageUrl);
|
||||
if ($host !== '') {
|
||||
return $host;
|
||||
}
|
||||
if ($landingUrlHint !== '') {
|
||||
$hintHost = HuojianUrlHelper::extractBusinessHost($landingUrlHint);
|
||||
if ($hintHost !== '') {
|
||||
return $hintHost;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private static function resolveA2cSessionHost(string $pageUrl, string $landingUrlHint = ''): string
|
||||
{
|
||||
$candidates = [];
|
||||
if ($landingUrlHint !== '') {
|
||||
$candidates[] = (string) parse_url($landingUrlHint, PHP_URL_HOST);
|
||||
}
|
||||
$candidates[] = (string) parse_url($pageUrl, PHP_URL_HOST);
|
||||
|
||||
foreach ($candidates as $host) {
|
||||
$host = strtolower(trim($host));
|
||||
if ($host !== '' && strpos($host, 'a2c.chat') !== false) {
|
||||
return $host;
|
||||
}
|
||||
}
|
||||
|
||||
return 'user.a2c.chat';
|
||||
}
|
||||
|
||||
private static function resolveHuojianSessionScope(string $pageUrl, string $landingUrlHint = ''): string
|
||||
{
|
||||
$scope = HuojianUrlHelper::resolveSessionScope($pageUrl);
|
||||
if ($scope !== '') {
|
||||
return $scope;
|
||||
}
|
||||
|
||||
if ($landingUrlHint !== '') {
|
||||
$fromLanding = HuojianUrlHelper::resolveSessionScope($landingUrlHint);
|
||||
if ($fromLanding !== '') {
|
||||
return $fromLanding;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user