Files

102 lines
3.2 KiB
PHP
Raw Permalink Normal View History

2026-06-09 03:36:30 +08:00
<?php
declare(strict_types=1);
namespace app\common\library\scrm\spider;
use app\common\library\scrm\AbstractScrmSpider;
2026-07-02 03:13:27 +08:00
use app\common\library\scrm\AntiBotConfigBuilder;
2026-06-09 03:36:30 +08:00
use app\common\library\scrm\UnifiedScrmData;
2026-07-02 03:13:27 +08:00
use app\common\service\SplitPageUrlResolver;
2026-06-09 03:36:30 +08:00
/**
2026-07-02 03:13:27 +08:00
* 火箭云控蜘蛛(Real Browser + CF 过盾 + 密码弹窗 + API 拦截)
*
* 短链 s.url99.me → 长链 *.url66.me/gds?link=(长链域名动态,不写死)
2026-06-09 03:36:30 +08:00
*/
class HuojianSpider extends AbstractScrmSpider
{
private const API_LIST = '/prod-api1/biz/counter/link/share/';
private string $pageUrl;
private string $account;
private string $password;
private UnifiedScrmData $unifiedData;
2026-07-02 03:13:27 +08:00
/** HTTP 预解析落地 URL(短链 CF 时可能失败,仅作 hint) */
private string $landingUrlHint = '';
2026-06-09 03:36:30 +08:00
public function __construct(
string $pageUrl,
string $account = '',
string $password = '',
string $nodeHost = 'http://127.0.0.1:3001'
) {
parent::__construct($nodeHost);
$this->pageUrl = $pageUrl;
$this->account = $account;
$this->password = $password;
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(): array
{
2026-07-02 03:13:27 +08:00
$antiBot = AntiBotConfigBuilder::build('huojian', $this->pageUrl, $this->landingUrlHint);
2026-06-09 03:36:30 +08:00
return [
'pageUrl' => $this->pageUrl,
'listApi' => self::API_LIST,
'listMethod' => 'POST',
'paginationMode' => self::MODE_UI,
'authActions' => [
['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'],
['type' => 'wait', 'ms' => 2000],
],
2026-07-02 03:13:27 +08:00
'antiBot' => $antiBot,
2026-06-09 03:36:30 +08:00
];
}
protected function extractListTotalPages($listFirstPageData, $countData = null)
{
return 1;
}
protected function buildListPageParams(int $page): array
{
return [];
}
protected function getUiPaginationConfig(): array
{
return [];
}
protected function parseToUnifiedData($detailData, array $allListPagesData): UnifiedScrmData
{
$unifiedData = $this->unifiedData;
2026-07-03 20:12:20 +08:00
$unifiedData->todayNewCount = (int) ($allListPagesData[0]['data']['counterWorker']['newTodayFriend'] ?? 0);
2026-06-09 03:36:30 +08:00
$count = 0;
foreach ($allListPagesData as $pageRaw) {
$records = $pageRaw['data']['counterCsAccountVo'] ?? [];
foreach ($records as $item) {
if (empty($item['accountLogin'])) {
continue;
}
$number = (string) $item['accountLogin'];
$isOnline = isset($item['accountStatus']) && (int) $item['accountStatus'] === 1;
$count++;
$unifiedData->addNumber($number, $isOnline, (int) ($item['newTodayFriend'] ?? 0));
}
}
$unifiedData->total = $count;
2026-07-02 03:13:27 +08:00
2026-06-09 03:36:30 +08:00
return $unifiedData;
}
}