2026-06-09 03:36:30 +08:00
|
|
|
<?php
|
2026-07-02 03:13:27 +08:00
|
|
|
// 火箭工单 — 测试脚本(短链/长链 + Real Browser + CF + 密码弹窗)
|
2026-06-09 03:36:30 +08:00
|
|
|
|
|
|
|
|
require_once __DIR__ . '/AbstractScrmSpider.class.php';
|
2026-07-02 03:13:27 +08:00
|
|
|
require_once __DIR__ . '/SplitPageUrlResolver.php';
|
2026-06-09 03:36:30 +08:00
|
|
|
|
|
|
|
|
class Huojian extends AbstractScrmSpider
|
|
|
|
|
{
|
2026-07-02 03:13:27 +08:00
|
|
|
const API_LIST = '/prod-api1/biz/counter/link/share/';
|
|
|
|
|
|
|
|
|
|
const API_DETAILS = '';
|
|
|
|
|
|
|
|
|
|
const API_COUNT = '';
|
|
|
|
|
|
|
|
|
|
const DEFAULT_PER_PAGE_COUNT = 20;
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
2026-06-09 03:36:30 +08:00
|
|
|
private $pageUrl;
|
2026-07-02 03:13:27 +08:00
|
|
|
|
|
|
|
|
/** @var string */
|
2026-06-09 03:36:30 +08:00
|
|
|
private $account;
|
2026-07-02 03:13:27 +08:00
|
|
|
|
|
|
|
|
/** @var string */
|
2026-06-09 03:36:30 +08:00
|
|
|
private $password;
|
2026-07-02 03:13:27 +08:00
|
|
|
|
|
|
|
|
/** @var UnifiedScrmData */
|
2026-06-09 03:36:30 +08:00
|
|
|
private $unifiedData;
|
2026-07-02 03:13:27 +08:00
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $landingUrlHint = '';
|
|
|
|
|
|
2026-06-09 03:36:30 +08:00
|
|
|
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;
|
2026-07-02 03:13:27 +08:00
|
|
|
$this->landingUrlHint = SplitPageUrlResolver::resolveFinalUrl($pageUrl);
|
2026-06-09 03:36:30 +08:00
|
|
|
$this->unifiedData = new UnifiedScrmData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getSpiderConfig()
|
|
|
|
|
{
|
2026-07-02 03:13:27 +08:00
|
|
|
$antiBot = $this->buildAntiBotConfig();
|
|
|
|
|
|
|
|
|
|
$this->logDebug('huojian spider config', [
|
|
|
|
|
'pageUrl' => $this->pageUrl,
|
|
|
|
|
'landingUrlHint' => $this->landingUrlHint,
|
|
|
|
|
'sessionKey' => $antiBot['sessionKey'] ?? '',
|
|
|
|
|
'businessHostHint' => $antiBot['businessHostHint'] ?? '',
|
|
|
|
|
'cfClearanceRequired' => $antiBot['cfClearanceRequired'] ?? null,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-06-09 03:36:30 +08:00
|
|
|
return [
|
2026-07-02 03:13:27 +08:00
|
|
|
'pageUrl' => $this->pageUrl,
|
|
|
|
|
'listApi' => self::API_LIST,
|
|
|
|
|
'listMethod' => 'POST',
|
2026-06-09 03:36:30 +08:00
|
|
|
'paginationMode' => self::MODE_UI,
|
2026-07-02 03:13:27 +08:00
|
|
|
'authActions' => [
|
2026-06-09 03:36:30 +08:00
|
|
|
['type' => 'vue_fill', 'selector' => '.el-message-box__input input', 'value' => $this->password],
|
|
|
|
|
['type' => 'wait', 'ms' => 500],
|
|
|
|
|
['type' => 'vue_click', 'selector' => '.el-message-box__btns .el-button--primary'],
|
2026-07-02 03:13:27 +08:00
|
|
|
['type' => 'wait', 'ms' => 2000],
|
|
|
|
|
],
|
|
|
|
|
'antiBot' => $antiBot,
|
2026-06-09 03:36:30 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-02 03:13:27 +08:00
|
|
|
/**
|
|
|
|
|
* 对齐生产 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 '';
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 03:36:30 +08:00
|
|
|
protected function extractListTotalPages($listFirstPageData, $countData = null)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function buildListPageParams($page)
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getUiPaginationConfig()
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function parseToUnifiedData($detailData, $allListPagesData)
|
|
|
|
|
{
|
|
|
|
|
$unifiedData = $this->unifiedData;
|
2026-07-02 03:13:27 +08:00
|
|
|
|
2026-07-02 19:03:06 +08:00
|
|
|
$unifiedData->todayNewCount = (int) ($allListPagesData[0]['data']['counterWorker']['newTodayFriend'] ?? 0) + (int) ($allListPagesData[0]['data']['counterWorker']['newRemovedTodayFriend'] ?? 0);
|
|
|
|
|
|
2026-06-09 03:36:30 +08:00
|
|
|
$count = 0;
|
|
|
|
|
foreach ($allListPagesData as $pageRaw) {
|
2026-07-02 03:13:27 +08:00
|
|
|
$records = $pageRaw['data']['counterCsAccountVo'] ?? [];
|
2026-06-09 03:36:30 +08:00
|
|
|
foreach ($records as $item) {
|
2026-07-02 03:13:27 +08:00
|
|
|
if (!empty($item['accountLogin'])) {
|
|
|
|
|
$number = $item['accountLogin'];
|
|
|
|
|
$isOnline = (isset($item['accountStatus']) && (int) $item['accountStatus'] === 1);
|
2026-06-09 03:36:30 +08:00
|
|
|
$count++;
|
2026-07-02 03:13:27 +08:00
|
|
|
$unifiedData->addNumber($number, $isOnline, (int) ($item['newTodayFriend'] ?? 0));
|
2026-06-09 03:36:30 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-02 03:13:27 +08:00
|
|
|
|
2026-06-09 03:36:30 +08:00
|
|
|
$unifiedData->total = $count;
|
|
|
|
|
|
|
|
|
|
return $unifiedData;
|
|
|
|
|
}
|
2026-07-02 03:13:27 +08:00
|
|
|
}
|