修复火箭工单过盾同步问题
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 '';
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\library\scrm;
|
||||
|
||||
/**
|
||||
* 火箭云控 URL 解析:短链(s.url99.me/code)与长链(*.url66.me/gds?link=)动态识别
|
||||
*
|
||||
* 长链域名可能为 v3.url66.me、v4.url66.me 等,禁止写死单一 host。
|
||||
*/
|
||||
final class HuojianUrlHelper
|
||||
{
|
||||
/** 火箭业务页路径特征 */
|
||||
public const BUSINESS_PATH_NEEDLE = '/gds';
|
||||
|
||||
/** 长链 query 中的分享 token 参数名 */
|
||||
public const LINK_QUERY_PARAM = 'link';
|
||||
|
||||
/**
|
||||
* 是否为火箭长链业务页(含 /gds 且带 link=)
|
||||
*/
|
||||
public static function isLongLinkUrl(string $pageUrl): bool
|
||||
{
|
||||
$path = (string) parse_url($pageUrl, PHP_URL_PATH);
|
||||
if ($path === '' || strpos($path, self::BUSINESS_PATH_NEEDLE) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = [];
|
||||
parse_str((string) parse_url($pageUrl, PHP_URL_QUERY), $query);
|
||||
|
||||
return trim((string) ($query[self::LINK_QUERY_PARAM] ?? '')) !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 从长链 URL 动态解析业务域(如 v3.url66.me)
|
||||
*/
|
||||
public static function extractBusinessHost(string $pageUrl): string
|
||||
{
|
||||
if (!self::isLongLinkUrl($pageUrl)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$host = strtolower(trim((string) parse_url($pageUrl, PHP_URL_HOST)));
|
||||
|
||||
return $host !== '' ? $host : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取分享稳定标识:长链 link= 或短链 path 段(如 50q3622j)
|
||||
*/
|
||||
public static function extractShareToken(string $pageUrl): string
|
||||
{
|
||||
if (self::isLongLinkUrl($pageUrl)) {
|
||||
$query = [];
|
||||
parse_str((string) parse_url($pageUrl, PHP_URL_QUERY), $query);
|
||||
|
||||
return trim((string) ($query[self::LINK_QUERY_PARAM] ?? ''));
|
||||
}
|
||||
|
||||
$path = trim((string) parse_url($pageUrl, PHP_URL_PATH), '/');
|
||||
if ($path === '' || strpos($path, '/') !== false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (preg_match('/^[a-zA-Z0-9]+$/', $path) !== 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为火箭短链入口(单段 path,非 /gds 长链)
|
||||
*/
|
||||
public static function isShortEntryUrl(string $pageUrl): bool
|
||||
{
|
||||
if (self::isLongLinkUrl($pageUrl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::extractShareToken($pageUrl) !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话 scope:长链用动态业务域;短链用 share.{token}(跨长链域名复用 cookie jar)
|
||||
*/
|
||||
public static function resolveSessionScope(string $pageUrl): string
|
||||
{
|
||||
$businessHost = self::extractBusinessHost($pageUrl);
|
||||
if ($businessHost !== '') {
|
||||
return $businessHost;
|
||||
}
|
||||
|
||||
$token = self::extractShareToken($pageUrl);
|
||||
if ($token !== '') {
|
||||
return 'share.' . $token;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,14 @@ declare(strict_types=1);
|
||||
namespace app\common\library\scrm\spider;
|
||||
|
||||
use app\common\library\scrm\AbstractScrmSpider;
|
||||
use app\common\library\scrm\AntiBotConfigBuilder;
|
||||
use app\common\library\scrm\UnifiedScrmData;
|
||||
use app\common\service\SplitPageUrlResolver;
|
||||
|
||||
/**
|
||||
* 火箭云控蜘蛛
|
||||
* 火箭云控蜘蛛(Real Browser + CF 过盾 + 密码弹窗 + API 拦截)
|
||||
*
|
||||
* 短链 s.url99.me → 长链 *.url66.me/gds?link=(长链域名动态,不写死)
|
||||
*/
|
||||
class HuojianSpider extends AbstractScrmSpider
|
||||
{
|
||||
@@ -22,6 +26,9 @@ class HuojianSpider extends AbstractScrmSpider
|
||||
|
||||
private UnifiedScrmData $unifiedData;
|
||||
|
||||
/** HTTP 预解析落地 URL(短链 CF 时可能失败,仅作 hint) */
|
||||
private string $landingUrlHint = '';
|
||||
|
||||
public function __construct(
|
||||
string $pageUrl,
|
||||
string $account = '',
|
||||
@@ -32,11 +39,14 @@ class HuojianSpider extends AbstractScrmSpider
|
||||
$this->pageUrl = $pageUrl;
|
||||
$this->account = $account;
|
||||
$this->password = $password;
|
||||
$this->landingUrlHint = SplitPageUrlResolver::resolveFinalUrl($pageUrl);
|
||||
$this->unifiedData = new UnifiedScrmData();
|
||||
}
|
||||
|
||||
protected function getSpiderConfig(): array
|
||||
{
|
||||
$antiBot = AntiBotConfigBuilder::build('huojian', $this->pageUrl, $this->landingUrlHint);
|
||||
|
||||
return [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'listApi' => self::API_LIST,
|
||||
@@ -48,6 +58,7 @@ class HuojianSpider extends AbstractScrmSpider
|
||||
['type' => 'vue_click', 'selector' => '.el-message-box__btns .el-button--primary'],
|
||||
['type' => 'wait', 'ms' => 2000],
|
||||
],
|
||||
'antiBot' => $antiBot,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -84,6 +95,7 @@ class HuojianSpider extends AbstractScrmSpider
|
||||
}
|
||||
}
|
||||
$unifiedData->total = $count;
|
||||
|
||||
return $unifiedData;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user