修复火箭工单过盾同步问题
This commit is contained in:
+136
-44
@@ -1,102 +1,194 @@
|
||||
<?php
|
||||
// 火箭工单
|
||||
// 火箭工单 — 测试脚本(短链/长链 + Real Browser + CF + 密码弹窗)
|
||||
|
||||
require_once __DIR__ . '/AbstractScrmSpider.class.php';
|
||||
require_once __DIR__ . '/SplitPageUrlResolver.php';
|
||||
|
||||
class Huojian extends AbstractScrmSpider
|
||||
{
|
||||
const API_LIST = '/prod-api1/biz/counter/link/share/'; // 列表API地址
|
||||
const API_DETAILS = ''; // 详情API地址
|
||||
const API_COUNT = ''; // 总数API地址
|
||||
const DEFAULT_PER_PAGE_COUNT = 20; // List默认每页显示的数量
|
||||
const API_LIST = '/prod-api1/biz/counter/link/share/';
|
||||
|
||||
const API_DETAILS = '';
|
||||
|
||||
const API_COUNT = '';
|
||||
|
||||
const DEFAULT_PER_PAGE_COUNT = 20;
|
||||
|
||||
/** @var string */
|
||||
private $pageUrl;
|
||||
|
||||
/** @var string */
|
||||
private $account;
|
||||
|
||||
/** @var string */
|
||||
private $password;
|
||||
|
||||
/** @var UnifiedScrmData */
|
||||
private $unifiedData;
|
||||
|
||||
// 实例化时动态传入账号和密码
|
||||
|
||||
/** @var string */
|
||||
private $landingUrlHint = '';
|
||||
|
||||
public function __construct($pageUrl, $account, $password, $nodeHost = 'http://127.0.0.1:3001')
|
||||
{
|
||||
parent::__construct($nodeHost);
|
||||
$this->account = $account;
|
||||
$this->password = $password;
|
||||
$this->pageUrl = $pageUrl;
|
||||
|
||||
$this->landingUrlHint = SplitPageUrlResolver::resolveFinalUrl($pageUrl);
|
||||
$this->unifiedData = new UnifiedScrmData();
|
||||
}
|
||||
|
||||
protected function getSpiderConfig()
|
||||
{
|
||||
$antiBot = $this->buildAntiBotConfig();
|
||||
|
||||
$this->logDebug('huojian spider config', [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'landingUrlHint' => $this->landingUrlHint,
|
||||
'sessionKey' => $antiBot['sessionKey'] ?? '',
|
||||
'businessHostHint' => $antiBot['businessHostHint'] ?? '',
|
||||
'cfClearanceRequired' => $antiBot['cfClearanceRequired'] ?? null,
|
||||
]);
|
||||
|
||||
return [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'apiUrls' => [self::API_LIST],
|
||||
|
||||
// 明确指派角色
|
||||
'listApi' => self::API_LIST, // 必须
|
||||
|
||||
'listMethod' => 'POST',
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'listApi' => self::API_LIST,
|
||||
'listMethod' => 'POST',
|
||||
'paginationMode' => self::MODE_UI,
|
||||
|
||||
'authActions' => [
|
||||
// 1. 填入密码:寻找 class 包含 el-message-box__input 下面的任意 input
|
||||
// Node.js 会自动扫描所有匹配项,并只把密码强行注入到那个“肉眼可见”的框里
|
||||
'authActions' => [
|
||||
['type' => 'vue_fill', 'selector' => '.el-message-box__input input', 'value' => $this->password],
|
||||
|
||||
// 2. 停顿 500ms,让 Vue 绑定的 v-model 彻底反应过来
|
||||
['type' => 'wait', 'ms' => 500],
|
||||
|
||||
// 3. 点击确认:寻找 MessageBox 底部的蓝色 primary 确认按钮
|
||||
// 同样利用 vue_click 的可见性过滤,无视隐藏的旧弹窗按钮
|
||||
['type' => 'vue_click', 'selector' => '.el-message-box__btns .el-button--primary'],
|
||||
|
||||
// 4. 等待弹窗淡出,接口开始请求
|
||||
['type' => 'wait', 'ms' => 2000]
|
||||
]
|
||||
['type' => 'wait', 'ms' => 2000],
|
||||
],
|
||||
'antiBot' => $antiBot,
|
||||
];
|
||||
}
|
||||
|
||||
// 只负责解析 List 的总页数
|
||||
/**
|
||||
* 对齐生产 AntiBotConfigBuilder 火箭策略(长链 host 动态解析)
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function buildAntiBotConfig()
|
||||
{
|
||||
$sessionScope = $this->resolveHuojianSessionScope();
|
||||
$businessHostHint = $this->resolveHuojianBusinessHostHint();
|
||||
|
||||
return [
|
||||
'enabled' => true,
|
||||
'profile' => 'real',
|
||||
'turnstile' => true,
|
||||
'solverFallback' => true,
|
||||
'cfClearanceRequired' => true,
|
||||
'sessionKey' => 'huojian:' . $sessionScope,
|
||||
'challengeTimeoutMs' => 60000,
|
||||
'landingUrlHint' => $this->landingUrlHint,
|
||||
'businessHostHint' => $businessHostHint,
|
||||
'postCfReadyUrlContains' => '/gds',
|
||||
'postCfReadySelector' => '.el-message-box__input',
|
||||
'postCfReadyTimeoutMs' => 45000,
|
||||
'postCfSettleMs' => 500,
|
||||
'postCfSpaWaitMs' => 8000,
|
||||
];
|
||||
}
|
||||
|
||||
private function isHuojianLongLinkUrl($pageUrl)
|
||||
{
|
||||
$path = (string) parse_url($pageUrl, PHP_URL_PATH);
|
||||
if ($path === '' || strpos($path, '/gds') === false) {
|
||||
return false;
|
||||
}
|
||||
$query = [];
|
||||
parse_str((string) parse_url($pageUrl, PHP_URL_QUERY), $query);
|
||||
|
||||
return trim((string) ($query['link'] ?? '')) !== '';
|
||||
}
|
||||
|
||||
private function extractHuojianShareToken($pageUrl)
|
||||
{
|
||||
if ($this->isHuojianLongLinkUrl($pageUrl)) {
|
||||
$query = [];
|
||||
parse_str((string) parse_url($pageUrl, PHP_URL_QUERY), $query);
|
||||
|
||||
return trim((string) ($query['link'] ?? ''));
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
private function resolveHuojianSessionScope()
|
||||
{
|
||||
if ($this->isHuojianLongLinkUrl($this->pageUrl)) {
|
||||
return strtolower((string) parse_url($this->pageUrl, PHP_URL_HOST));
|
||||
}
|
||||
$token = $this->extractHuojianShareToken($this->pageUrl);
|
||||
if ($token !== '') {
|
||||
return 'share.' . $token;
|
||||
}
|
||||
if ($this->landingUrlHint !== '' && $this->isHuojianLongLinkUrl($this->landingUrlHint)) {
|
||||
return strtolower((string) parse_url($this->landingUrlHint, PHP_URL_HOST));
|
||||
}
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
private function resolveHuojianBusinessHostHint()
|
||||
{
|
||||
if ($this->isHuojianLongLinkUrl($this->pageUrl)) {
|
||||
return strtolower((string) parse_url($this->pageUrl, PHP_URL_HOST));
|
||||
}
|
||||
if ($this->landingUrlHint !== '' && $this->isHuojianLongLinkUrl($this->landingUrlHint)) {
|
||||
return strtolower((string) parse_url($this->landingUrlHint, PHP_URL_HOST));
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function extractListTotalPages($listFirstPageData, $countData = null)
|
||||
{
|
||||
// 只有一页
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 没有分页返回空数组
|
||||
protected function buildListPageParams($page)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// 提供 List 的下一页按钮信息
|
||||
protected function getUiPaginationConfig()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// 清爽至极的数据清洗:详情是详情,列表是列表
|
||||
protected function parseToUnifiedData($detailData, $allListPagesData)
|
||||
{
|
||||
$unifiedData = $this->unifiedData;
|
||||
|
||||
$unifiedData->todayNewCount = $allListPagesData[0]['data']['counterWorker']['newTodayFriend'];
|
||||
|
||||
// 2. 循环合并了所有页数的 List 数组
|
||||
|
||||
$unifiedData->todayNewCount = (int) ($allListPagesData[0]['data']['counterWorker']['newTodayFriend'] ?? 0);
|
||||
|
||||
$count = 0;
|
||||
foreach ($allListPagesData as $pageRaw) {
|
||||
$records = $pageRaw['data']['counterCsAccountVo'] ?? [];
|
||||
$records = $pageRaw['data']['counterCsAccountVo'] ?? [];
|
||||
foreach ($records as $item) {
|
||||
if(!empty($item['accountLogin'])) {
|
||||
$number = $item['accountLogin'] ?? null;
|
||||
$isOnline = (isset($item['accountStatus']) && $item['accountStatus'] == 1);
|
||||
if (!empty($item['accountLogin'])) {
|
||||
$number = $item['accountLogin'];
|
||||
$isOnline = (isset($item['accountStatus']) && (int) $item['accountStatus'] === 1);
|
||||
$count++;
|
||||
$unifiedData->addNumber($number, $isOnline, $item['newTodayFriend']);
|
||||
$unifiedData->addNumber($number, $isOnline, (int) ($item['newTodayFriend'] ?? 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$unifiedData->total = $count;
|
||||
|
||||
return $unifiedData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -128,10 +128,13 @@ try {
|
||||
|
||||
// try {
|
||||
// echo "🚀 开始执行<火箭工单>抓取任务 (多引擎智能调度)...\n\r";
|
||||
// $pageUrl = 'https://s.url99.me/68vfje8m'; // PageUrl 入口授权页
|
||||
// $username = ""; // 登录账号
|
||||
// $password = "542187"; // 登录密码
|
||||
// $spider = new Huojian($pageUrl, $username, $password);
|
||||
// // 长链(业务域动态,如 v3.url66.me)
|
||||
// // $pageUrl = 'https://v3.url66.me/gds?link=6a387e66e4b09e9d162cd647';
|
||||
// // 短链(与客户后台一致)
|
||||
// $pageUrl = 'https://s.url99.me/50q3622j';
|
||||
// $username = "";
|
||||
// $password = "你的分享密码";
|
||||
// $spider = (new Huojian($pageUrl, $username, $password))->setVerbose(true);
|
||||
// $finalData = $spider->run();
|
||||
|
||||
// echo "✅ 任务完成!统一数据如下:\n\r";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
/**
|
||||
* 短链 HTTP 重定向预解析(与 puppeteer-api/url-resolve.js 行为对齐)
|
||||
*
|
||||
* 用于 antiBot landingUrlHint;CF 拦截时可能失败,浏览器仍会 follow。
|
||||
*/
|
||||
final class SplitPageUrlResolver
|
||||
{
|
||||
private const REDIRECT_CODES = [301, 302, 303, 307, 308];
|
||||
|
||||
/**
|
||||
* 跟随 HTTP 重定向,返回最终 URL;失败时返回原始 URL
|
||||
*/
|
||||
public static function resolveFinalUrl(string $pageUrl, int $maxRedirects = 10, int $timeoutSec = 12): string
|
||||
{
|
||||
$current = trim($pageUrl);
|
||||
if ($current === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $maxRedirects; $i++) {
|
||||
$response = self::fetchHeadOrGet($current, $timeoutSec);
|
||||
if ($response === null) {
|
||||
return $current;
|
||||
}
|
||||
|
||||
$code = $response['code'];
|
||||
$location = $response['location'];
|
||||
if (!in_array($code, self::REDIRECT_CODES, true) || $location === '') {
|
||||
return $current;
|
||||
}
|
||||
|
||||
$current = self::resolveRelativeUrl($current, $location);
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{code: int, location: string}|null
|
||||
*/
|
||||
private static function fetchHeadOrGet(string $url, int $timeoutSec): ?array
|
||||
{
|
||||
$result = self::curlOnce($url, true, $timeoutSec);
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return self::curlOnce($url, false, $timeoutSec);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{code: int, location: string}|null
|
||||
*/
|
||||
private static function curlOnce(string $url, bool $headOnly, int $timeoutSec): ?array
|
||||
{
|
||||
if (!function_exists('curl_init')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ch = curl_init($url);
|
||||
if ($ch === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_NOBODY => $headOnly,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => false,
|
||||
CURLOPT_TIMEOUT => $timeoutSec,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; SplitPageUrlResolver/1.0)',
|
||||
]);
|
||||
|
||||
$body = curl_exec($ch);
|
||||
if ($body === false) {
|
||||
curl_close($ch);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$redirectUrl = (string) curl_getinfo($ch, CURLINFO_REDIRECT_URL);
|
||||
curl_close($ch);
|
||||
|
||||
$location = $redirectUrl;
|
||||
if ($location === '' && is_string($body)) {
|
||||
$location = self::parseLocationHeader($body);
|
||||
}
|
||||
|
||||
return ['code' => $code, 'location' => trim($location)];
|
||||
}
|
||||
|
||||
private static function parseLocationHeader(string $rawHeaders): string
|
||||
{
|
||||
foreach (preg_split('/\r\n|\n|\r/', $rawHeaders) as $line) {
|
||||
if (stripos($line, 'Location:') === 0) {
|
||||
return trim(substr($line, 9));
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private static function resolveRelativeUrl(string $baseUrl, string $location): string
|
||||
{
|
||||
if (preg_match('#^https?://#i', $location)) {
|
||||
return $location;
|
||||
}
|
||||
|
||||
$base = parse_url($baseUrl);
|
||||
if (!is_array($base)) {
|
||||
return $location;
|
||||
}
|
||||
|
||||
$scheme = (string) ($base['scheme'] ?? 'https');
|
||||
$host = (string) ($base['host'] ?? '');
|
||||
if ($host === '') {
|
||||
return $location;
|
||||
}
|
||||
|
||||
if (strpos($location, '/') === 0) {
|
||||
return $scheme . '://' . $host . $location;
|
||||
}
|
||||
|
||||
$path = (string) ($base['path'] ?? '/');
|
||||
$dir = rtrim(str_replace(basename($path), '', $path), '/');
|
||||
|
||||
return $scheme . '://' . $host . ($dir !== '' ? $dir . '/' : '/') . $location;
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ return array (
|
||||
),
|
||||
'split_platform_domain' => 'flowerbells.top',
|
||||
'split_scrm_node_host' => 'http://127.0.0.1:3001',
|
||||
'split_scrm_antibot_types' => 'whatshub,chatknow,a2c',
|
||||
'split_scrm_antibot_types' => 'whatshub,chatknow,a2c,huojian',
|
||||
'split_scrm_session_ttl_minutes' => '120',
|
||||
'split_sync_interval_a2c' => '3',
|
||||
'split_sync_interval_haiwang' => '3',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
/**
|
||||
* 短链 HTTP 重定向预解析(与 puppeteer-api/url-resolve.js 行为对齐)
|
||||
*
|
||||
* 用于 antiBot landingUrlHint;CF 拦截时可能失败,浏览器仍会 follow。
|
||||
*/
|
||||
final class SplitPageUrlResolver
|
||||
{
|
||||
private const REDIRECT_CODES = [301, 302, 303, 307, 308];
|
||||
|
||||
/**
|
||||
* 跟随 HTTP 重定向,返回最终 URL;失败时返回原始 URL
|
||||
*/
|
||||
public static function resolveFinalUrl(string $pageUrl, int $maxRedirects = 10, int $timeoutSec = 12): string
|
||||
{
|
||||
$current = trim($pageUrl);
|
||||
if ($current === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $maxRedirects; $i++) {
|
||||
$response = self::fetchHeadOrGet($current, $timeoutSec);
|
||||
if ($response === null) {
|
||||
return $current;
|
||||
}
|
||||
|
||||
$code = $response['code'];
|
||||
$location = $response['location'];
|
||||
if (!in_array($code, self::REDIRECT_CODES, true) || $location === '') {
|
||||
return $current;
|
||||
}
|
||||
|
||||
$current = self::resolveRelativeUrl($current, $location);
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{code: int, location: string}|null
|
||||
*/
|
||||
private static function fetchHeadOrGet(string $url, int $timeoutSec): ?array
|
||||
{
|
||||
$result = self::curlOnce($url, true, $timeoutSec);
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return self::curlOnce($url, false, $timeoutSec);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{code: int, location: string}|null
|
||||
*/
|
||||
private static function curlOnce(string $url, bool $headOnly, int $timeoutSec): ?array
|
||||
{
|
||||
if (!function_exists('curl_init')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ch = curl_init($url);
|
||||
if ($ch === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_NOBODY => $headOnly,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => false,
|
||||
CURLOPT_TIMEOUT => $timeoutSec,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; SplitPageUrlResolver/1.0)',
|
||||
]);
|
||||
|
||||
$body = curl_exec($ch);
|
||||
if ($body === false) {
|
||||
curl_close($ch);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$redirectUrl = (string) curl_getinfo($ch, CURLINFO_REDIRECT_URL);
|
||||
curl_close($ch);
|
||||
|
||||
$location = $redirectUrl;
|
||||
if ($location === '' && is_string($body)) {
|
||||
$location = self::parseLocationHeader($body);
|
||||
}
|
||||
|
||||
return ['code' => $code, 'location' => trim($location)];
|
||||
}
|
||||
|
||||
private static function parseLocationHeader(string $rawHeaders): string
|
||||
{
|
||||
foreach (preg_split('/\r\n|\n|\r/', $rawHeaders) as $line) {
|
||||
if (stripos($line, 'Location:') === 0) {
|
||||
return trim(substr($line, 9));
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private static function resolveRelativeUrl(string $baseUrl, string $location): string
|
||||
{
|
||||
if (preg_match('#^https?://#i', $location)) {
|
||||
return $location;
|
||||
}
|
||||
|
||||
$base = parse_url($baseUrl);
|
||||
if (!is_array($base)) {
|
||||
return $location;
|
||||
}
|
||||
|
||||
$scheme = (string) ($base['scheme'] ?? 'https');
|
||||
$host = (string) ($base['host'] ?? '');
|
||||
if ($host === '') {
|
||||
return $location;
|
||||
}
|
||||
|
||||
if (strpos($location, '/') === 0) {
|
||||
return $scheme . '://' . $host . $location;
|
||||
}
|
||||
|
||||
$path = (string) ($base['path'] ?? '/');
|
||||
$dir = rtrim(str_replace(basename($path), '', $path), '/');
|
||||
|
||||
return $scheme . '://' . $host . ($dir !== '' ? $dir . '/' : '/') . $location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 火箭云控 URL 解析(与 PHP HuojianUrlHelper 对齐)
|
||||
* 长链域名动态识别,禁止写死 v3.url66.me
|
||||
*/
|
||||
|
||||
const BUSINESS_PATH_NEEDLE = '/gds';
|
||||
const LINK_QUERY_PARAM = 'link';
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
*/
|
||||
function isHuojianLongLinkUrl(url) {
|
||||
if (!url || typeof url !== 'string') {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (!parsed.pathname.includes(BUSINESS_PATH_NEEDLE)) {
|
||||
return false;
|
||||
}
|
||||
const link = (parsed.searchParams.get(LINK_QUERY_PARAM) || '').trim();
|
||||
return link !== '';
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @returns {string}
|
||||
*/
|
||||
function extractHuojianBusinessHost(url) {
|
||||
if (!isHuojianLongLinkUrl(url)) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
return new URL(url).hostname.toLowerCase();
|
||||
} catch (_) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @returns {string}
|
||||
*/
|
||||
function extractHuojianShareToken(url) {
|
||||
if (!url || typeof url !== 'string') {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (isHuojianLongLinkUrl(url)) {
|
||||
return (parsed.searchParams.get(LINK_QUERY_PARAM) || '').trim();
|
||||
}
|
||||
const path = parsed.pathname.replace(/^\/+|\/+$/g, '');
|
||||
if (path === '' || path.includes('/')) {
|
||||
return '';
|
||||
}
|
||||
if (/^[a-zA-Z0-9]+$/.test(path)) {
|
||||
return path;
|
||||
}
|
||||
} catch (_) {
|
||||
/* ignore */
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
*/
|
||||
function isHuojianShortEntryUrl(url) {
|
||||
if (isHuojianLongLinkUrl(url)) {
|
||||
return false;
|
||||
}
|
||||
return extractHuojianShareToken(url) !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 落地后补全 businessHostHint(多长链域名兼容)
|
||||
* @param {object} antiBot
|
||||
* @param {string} finalPageUrl
|
||||
*/
|
||||
function applyHuojianBusinessHostHint(antiBot, finalPageUrl) {
|
||||
if (!antiBot) {
|
||||
return antiBot;
|
||||
}
|
||||
const host = extractHuojianBusinessHost(finalPageUrl);
|
||||
if (host !== '') {
|
||||
antiBot.businessHostHint = host;
|
||||
console.log(`[Huojian] 落地业务域=${host} url=${finalPageUrl}`);
|
||||
}
|
||||
return antiBot;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isHuojianLongLinkUrl,
|
||||
extractHuojianBusinessHost,
|
||||
extractHuojianShareToken,
|
||||
isHuojianShortEntryUrl,
|
||||
applyHuojianBusinessHostHint,
|
||||
BUSINESS_PATH_NEEDLE,
|
||||
};
|
||||
@@ -55,7 +55,11 @@ const {
|
||||
} = require('./lib/session-store');
|
||||
const { resolveSessionContext, touchSessionIfPresent } = require('./lib/session-context');
|
||||
const { getProfileStats, profileExists } = require('./lib/profile-dir');
|
||||
const { runUiPagination } = require('./lib/ui-pagination-runner');
|
||||
const {
|
||||
isHuojianLongLinkUrl,
|
||||
isHuojianShortEntryUrl,
|
||||
applyHuojianBusinessHostHint,
|
||||
} = require('./lib/huojian-url');
|
||||
|
||||
const app = express();
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
@@ -269,10 +273,50 @@ function applyA2cPostCfDefaults(antiBot, pageUrl) {
|
||||
};
|
||||
}
|
||||
|
||||
/** 按 pageUrl 合并 antiBot(含 Whatshub / A2C 默认 postCf) */
|
||||
/**
|
||||
* 火箭短链 → 动态长链域 /gds?link=:PHP 未传 postCfReady* 时 Node 侧自动补全
|
||||
* @param {object} antiBot
|
||||
* @param {string} pageUrl
|
||||
*/
|
||||
function applyHuojianPostCfDefaults(antiBot, pageUrl) {
|
||||
if (!antiBot || !antiBot.enabled) {
|
||||
return antiBot;
|
||||
}
|
||||
if ((antiBot.postCfReadyUrlContains || '').trim()) {
|
||||
return antiBot;
|
||||
}
|
||||
|
||||
let shouldApply = false;
|
||||
const sessionKey = String(antiBot.sessionKey || '').toLowerCase();
|
||||
if (sessionKey.startsWith('huojian:')) {
|
||||
shouldApply = true;
|
||||
}
|
||||
if (isHuojianLongLinkUrl(pageUrl) || isHuojianShortEntryUrl(pageUrl)) {
|
||||
shouldApply = true;
|
||||
}
|
||||
|
||||
if (!shouldApply) {
|
||||
return antiBot;
|
||||
}
|
||||
|
||||
console.log('[CF] 火箭 自动启用 postCfReady 默认配置');
|
||||
return {
|
||||
...antiBot,
|
||||
postCfReadyUrlContains: '/gds',
|
||||
postCfReadySelector: '.el-message-box__input',
|
||||
postCfReadyTimeoutMs: antiBot.postCfReadyTimeoutMs || 45000,
|
||||
postCfSettleMs: antiBot.postCfSettleMs || 500,
|
||||
postCfSpaWaitMs: antiBot.postCfSpaWaitMs || 8000,
|
||||
};
|
||||
}
|
||||
|
||||
/** 按 pageUrl 合并 antiBot(含 Whatshub / A2C / 火箭 默认 postCf) */
|
||||
function resolveAntiBotForPage(rawAntiBot, pageUrl) {
|
||||
return applyA2cPostCfDefaults(
|
||||
applyWhatshubPostCfDefaults(resolveAntiBot(rawAntiBot), pageUrl),
|
||||
return applyHuojianPostCfDefaults(
|
||||
applyA2cPostCfDefaults(
|
||||
applyWhatshubPostCfDefaults(resolveAntiBot(rawAntiBot), pageUrl),
|
||||
pageUrl
|
||||
),
|
||||
pageUrl
|
||||
);
|
||||
}
|
||||
@@ -361,6 +405,9 @@ function isOnShortLinkNotBusiness(page, urlNeedle) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (urlNeedle && urlNeedle.includes('/gds')) {
|
||||
return !url.includes('/gds');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1218,6 +1265,7 @@ app.post('/api/auth-and-intercept', async (req, res) => {
|
||||
await navigateToPage(page, pageUrl);
|
||||
|
||||
let finalPageUrl = await waitForUrlSettled(page);
|
||||
applyHuojianBusinessHostHint(antiBot, finalPageUrl);
|
||||
if (finalPageUrl !== pageUrl) {
|
||||
console.log(`[URL解析] 浏览器落地: ${pageUrl} -> ${finalPageUrl}`);
|
||||
}
|
||||
@@ -1246,6 +1294,7 @@ app.post('/api/auth-and-intercept', async (req, res) => {
|
||||
}
|
||||
|
||||
finalPageUrl = page.url();
|
||||
applyHuojianBusinessHostHint(antiBot, finalPageUrl);
|
||||
touchSessionIfPresent(antiBot.sessionKey);
|
||||
|
||||
await awaitPostCfBusinessReady(page, antiBot, waitForUrlSettled, storedSession, pageUrl);
|
||||
@@ -1599,6 +1648,7 @@ app.post('/api/auth-intercept-and-paginate', async (req, res) => {
|
||||
await prepareWhatshubShortLinkBeforeNav(page, pageUrl, antiBot);
|
||||
await navigateToPage(page, pageUrl);
|
||||
let finalPageUrl = await waitForUrlSettled(page);
|
||||
applyHuojianBusinessHostHint(antiBot, finalPageUrl);
|
||||
|
||||
let interceptor;
|
||||
if (antiBot.enabled) {
|
||||
@@ -1623,6 +1673,7 @@ app.post('/api/auth-intercept-and-paginate', async (req, res) => {
|
||||
return;
|
||||
}
|
||||
finalPageUrl = page.url();
|
||||
applyHuojianBusinessHostHint(antiBot, finalPageUrl);
|
||||
touchSessionIfPresent(antiBot.sessionKey);
|
||||
|
||||
await awaitPostCfBusinessReady(page, antiBot, waitForUrlSettled, storedSession, pageUrl);
|
||||
|
||||
@@ -266,7 +266,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
linkOptions.push('<option value="' + Fast.api.escape(String(id)) + '">' + Fast.api.escape(String(label)) + '</option>');
|
||||
});
|
||||
var html = [
|
||||
'<div class="split-batch-operate-modal" style="padding:26px 22px;">',
|
||||
'<div class="split-batch-operate-modal" style="padding:18px 22px;">',
|
||||
' <div class="form-group">',
|
||||
' <label class="control-label">' + __('Link_url') + '<span class="text-danger">*</span></label>',
|
||||
' <select id="batch-operate-split-link" class="form-control selectpicker" data-live-search="true" data-none-selected-text="' + pleaseSelect + '" title="' + pleaseSelect + '">',
|
||||
@@ -285,7 +285,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
' <option value="delete">' + Fast.api.escape(__('Batch operate delete')) + '</option>',
|
||||
' </select>',
|
||||
' </div>',
|
||||
' <div class="form-group" style="margin-top:10px;margin-bottom:0;text-align:right;">',
|
||||
' <div class="form-group" style="margin-bottom:0;text-align:right;">',
|
||||
' <button type="button" class="btn btn-primary btn-batch-operate-confirm">' + __('OK') + '</button> ',
|
||||
' <button type="button" class="btn btn-default btn-batch-operate-cancel">' + __('Cancel') + '</button>',
|
||||
' </div>',
|
||||
|
||||
Reference in New Issue
Block a user