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-06-26 21:24:31 +08:00
|
|
|
|
use app\common\library\scrm\AntiBotConfigBuilder;
|
2026-06-09 03:36:30 +08:00
|
|
|
|
use app\common\library\scrm\UnifiedScrmData;
|
2026-07-03 20:12:20 +08:00
|
|
|
|
use app\common\service\SplitPageUrlResolver;
|
2026-06-09 03:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2026-07-01 01:26:27 +08:00
|
|
|
|
* A2C 云控蜘蛛(Real Browser 打开分享页 + 拦截加密 API + UI 翻页)
|
|
|
|
|
|
*
|
2026-07-03 20:12:20 +08:00
|
|
|
|
* 业务域 user.a2c.chat 在 CF 挑战页启用 CapSolver 兜底;短链 yyk.ink 预解析为长链后直达业务页。
|
2026-06-09 03:36:30 +08:00
|
|
|
|
*/
|
|
|
|
|
|
class A2cSpider extends AbstractScrmSpider
|
|
|
|
|
|
{
|
|
|
|
|
|
private const API_LIST = '/api/talk/counter/share/record/list';
|
|
|
|
|
|
|
|
|
|
|
|
private const API_DETAILS = '/api/talk/counter/share/detail';
|
|
|
|
|
|
|
|
|
|
|
|
private const DEFAULT_PER_PAGE_COUNT = 20;
|
|
|
|
|
|
|
|
|
|
|
|
private string $pageUrl;
|
|
|
|
|
|
|
|
|
|
|
|
private string $account;
|
|
|
|
|
|
|
|
|
|
|
|
private string $password;
|
|
|
|
|
|
|
2026-07-03 20:12:20 +08:00
|
|
|
|
/** @var string HTTP 预解析落地 URL(供 antiBot landingUrlHint) */
|
|
|
|
|
|
private string $landingUrlHint = '';
|
|
|
|
|
|
|
2026-06-09 03:36:30 +08:00
|
|
|
|
private UnifiedScrmData $unifiedData;
|
|
|
|
|
|
|
|
|
|
|
|
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-03 20:12:20 +08:00
|
|
|
|
$this->landingUrlHint = SplitPageUrlResolver::resolveFinalUrl($pageUrl);
|
2026-06-09 03:36:30 +08:00
|
|
|
|
$this->unifiedData = new UnifiedScrmData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getSpiderConfig(): array
|
|
|
|
|
|
{
|
|
|
|
|
|
return [
|
|
|
|
|
|
'pageUrl' => $this->pageUrl,
|
|
|
|
|
|
'listApi' => self::API_LIST,
|
|
|
|
|
|
'detailApi' => self::API_DETAILS,
|
|
|
|
|
|
'listMethod' => 'POST',
|
|
|
|
|
|
'paginationMode' => self::MODE_UI,
|
|
|
|
|
|
'authActions' => [
|
|
|
|
|
|
['type' => 'wait', 'ms' => 2000],
|
|
|
|
|
|
],
|
2026-07-03 20:12:20 +08:00
|
|
|
|
'antiBot' => AntiBotConfigBuilder::build('a2c', $this->pageUrl, $this->landingUrlHint),
|
2026-06-09 03:36:30 +08:00
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function extractListTotalPages($listFirstPageData, $countData = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
$total = (int) ($listFirstPageData['data']['total'] ?? 0);
|
|
|
|
|
|
$this->unifiedData->total = $total;
|
|
|
|
|
|
if ($total <= self::DEFAULT_PER_PAGE_COUNT) {
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return (int) ceil($total / self::DEFAULT_PER_PAGE_COUNT);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function buildListPageParams(int $page): array
|
|
|
|
|
|
{
|
|
|
|
|
|
return ['page' => $page, 'pageSize' => self::DEFAULT_PER_PAGE_COUNT];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getUiPaginationConfig(): array
|
|
|
|
|
|
{
|
|
|
|
|
|
return [
|
|
|
|
|
|
'nextBtnSelector' => '.btn-next',
|
|
|
|
|
|
'waitMs' => 2000,
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function parseToUnifiedData($detailData, array $allListPagesData): UnifiedScrmData
|
|
|
|
|
|
{
|
|
|
|
|
|
$unifiedData = $this->unifiedData;
|
|
|
|
|
|
if ($detailData) {
|
|
|
|
|
|
$unifiedData->todayNewCount = (int) ($detailData['data']['newFollowersToday'] ?? 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach ($allListPagesData as $pageRaw) {
|
|
|
|
|
|
$records = $pageRaw['data']['rows'] ?? [];
|
|
|
|
|
|
foreach ($records as $item) {
|
|
|
|
|
|
if (empty($item['account'])) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
$number = (string) $item['account'];
|
|
|
|
|
|
$isOnline = isset($item['numberStatus']) && (int) $item['numberStatus'] === 1;
|
|
|
|
|
|
$unifiedData->addNumber($number, $isOnline, (int) ($item['newFollowersToday'] ?? 0));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $unifiedData;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|