account = $account; $this->password = $password; $this->pageUrl = $pageUrl; $this->unifiedData = new UnifiedScrmData(); } protected function getSpiderConfig() { $host = (string) parse_url($this->pageUrl, PHP_URL_HOST); return [ 'pageUrl' => $this->pageUrl, 'apiUrls' => [self::API_LIST], 'listApi' => self::API_LIST, // 必须,第一页的列表数据 // 'detailApi' => self::API_DETAILS, // 选填 // 'countApi' => self::API_COUNT, 'listMethod' => 'GET', 'paginationMode' => self::MODE_UI, 'authActions' => [ // ['type' => 'vue_select', 'selector' => 'input[type="password"]', 'value' => $this->password], // ['type' => 'type', 'selector' => '#username_input', 'value' => $this->account], // ['type' => 'vue_click', 'selector' => '.layui-btn', 'text' => '搜索'], ['type' => 'wait', 'ms' => 4000] ], // ChatKnow 专用:Real Browser + Turnstile + Captcha API 兜底 + 会话复用 'antiBot' => [ 'enabled' => true, 'profile' => 'real', 'turnstile' => true, 'solverFallback' => true, 'sessionKey' => 'chatknow:' . $host, 'challengeTimeoutMs' => 60000, ], ]; } // 只负责解析 List 的总页数 protected function extractListTotalPages($listFirstPageData, $countData = null) { $default_per_page_count = self::DEFAULT_PER_PAGE_COUNT; $this->unifiedData->total = $listFirstPageData['total']; $this->unifiedData->todayNewCount = $listFirstPageData['data']['today_num']; if($listFirstPageData['total'] <= $default_per_page_count) { return 1; } return ceil($listFirstPageData['total']/$default_per_page_count); } // 只负责组装 List 的翻页参数 protected function buildListPageParams($page) { return ['page' => $page, 'limit' => self::DEFAULT_PER_PAGE_COUNT]; } // 提供 List 的下一页按钮信息 protected function getUiPaginationConfig() { return [ 'nextBtnSelector' => '.tabs-content .arco-pagination-item-next', 'waitMs' => 2000 ]; } // 清爽至极的数据清洗:详情是详情,列表是列表 protected function parseToUnifiedData($detailData, $allListPagesData) { $unifiedData = $this->unifiedData; // 循环合并了所有页数的 List 数组 foreach ($allListPagesData as $pageRaw) { $records = $pageRaw['rows'] ?? []; foreach ($records as $item) { if(!empty($item['username'])) { $number = $item['username'] ?? null; $isOnline = (isset($item['state']) && $item['state'] == 1); $unifiedData->addNumber($number, $isOnline, $item['today_num']); } } } return $unifiedData; } }