完整版V1 加入爬虫功能

This commit is contained in:
root
2026-06-09 03:36:30 +08:00
parent 34d76cce74
commit a68b83fcbd
69 changed files with 5058 additions and 56 deletions
+105
View File
@@ -0,0 +1,105 @@
<?php
// A2c云控
require_once __DIR__ . '/AbstractScrmSpider.class.php';
class A2c extends AbstractScrmSpider
{
const API_LIST = '/api/talk/counter/share/record/list'; // 列表API地址
const API_DETAILS = '/api/talk/counter/share/detail'; // 详情API地址
const API_COUNT = ''; // 总数API地址
const DEFAULT_PER_PAGE_COUNT = 20; // List默认每页显示的数量
private $pageUrl;
private $account;
private $password;
private $unifiedData;
// 实例化时动态传入账号和密码
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->unifiedData = new UnifiedScrmData();
}
protected function getSpiderConfig()
{
return [
'pageUrl' => $this->pageUrl,
'apiUrls' => [self::API_LIST, self::API_DETAILS],
// 明确指派角色
'listApi' => self::API_LIST, // 必须
'detailApi' => self::API_DETAILS, // 选填
'listMethod' => 'POST',
'paginationMode' => self::MODE_UI,
'authActions' => [
// ['type' => 'type', 'selector' => 'input[type="password"]', 'value' => $this->password],
// ['type' => 'type', 'selector' => '#username_input', 'value' => $this->account],
// ['type' => 'press', 'key' => 'Enter'],
['type' => 'wait', 'ms' => 2000]
]
];
}
// 只负责解析 List 的总页数
protected function extractListTotalPages($listFirstPageData, $countData = null)
{
$default_per_page_count = self::DEFAULT_PER_PAGE_COUNT;
$this->unifiedData->total = $listFirstPageData['data']['total'];
if($listFirstPageData['data']['total'] <= $default_per_page_count) {
return 1;
}
return ceil($listFirstPageData['data']['total']/$default_per_page_count);
}
// 只负责组装 List 的翻页参数
protected function buildListPageParams($page)
{
return ['page' => $page, 'pageSize' => self::DEFAULT_PER_PAGE_COUNT];
}
// 提供 List 的下一页按钮信息
protected function getUiPaginationConfig()
{
return [
'nextBtnSelector' => '.btn-next',
'waitMs' => 2000
];
}
// 清爽至极的数据清洗:详情是详情,列表是列表
protected function parseToUnifiedData($detailData, $allListPagesData)
{
$unifiedData = $this->unifiedData;
// 1. 如果捕获到了详情数据,提取今日新增
if ($detailData) {
$unifiedData->todayNewCount = (int)($detailData['data']['newFollowersToday'] ?? 0);
}
// 2. 循环合并了所有页数的 List 数组
foreach ($allListPagesData as $pageRaw) {
$records = $pageRaw['data']['rows'] ?? [];
foreach ($records as $item) {
if(!empty($item['account'])) {
$number = $item['account'] ?? null;
$isOnline = (isset($item['numberStatus']) && $item['numberStatus'] == 1);
$unifiedData->addNumber($number, $isOnline, $item['newFollowersToday']);
}
}
}
return $unifiedData;
}
}