修复火箭工单过盾同步问题
This commit is contained in:
+136
-44
@@ -1,102 +1,194 @@
|
||||
<?php
|
||||
// 火箭工单
|
||||
// 火箭工单 — 测试脚本(短链/长链 + Real Browser + CF + 密码弹窗)
|
||||
|
||||
require_once __DIR__ . '/AbstractScrmSpider.class.php';
|
||||
require_once __DIR__ . '/SplitPageUrlResolver.php';
|
||||
|
||||
class Huojian extends AbstractScrmSpider
|
||||
{
|
||||
const API_LIST = '/prod-api1/biz/counter/link/share/'; // 列表API地址
|
||||
const API_DETAILS = ''; // 详情API地址
|
||||
const API_COUNT = ''; // 总数API地址
|
||||
const DEFAULT_PER_PAGE_COUNT = 20; // List默认每页显示的数量
|
||||
const API_LIST = '/prod-api1/biz/counter/link/share/';
|
||||
|
||||
const API_DETAILS = '';
|
||||
|
||||
const API_COUNT = '';
|
||||
|
||||
const DEFAULT_PER_PAGE_COUNT = 20;
|
||||
|
||||
/** @var string */
|
||||
private $pageUrl;
|
||||
|
||||
/** @var string */
|
||||
private $account;
|
||||
|
||||
/** @var string */
|
||||
private $password;
|
||||
|
||||
/** @var UnifiedScrmData */
|
||||
private $unifiedData;
|
||||
|
||||
// 实例化时动态传入账号和密码
|
||||
|
||||
/** @var string */
|
||||
private $landingUrlHint = '';
|
||||
|
||||
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->landingUrlHint = SplitPageUrlResolver::resolveFinalUrl($pageUrl);
|
||||
$this->unifiedData = new UnifiedScrmData();
|
||||
}
|
||||
|
||||
protected function getSpiderConfig()
|
||||
{
|
||||
$antiBot = $this->buildAntiBotConfig();
|
||||
|
||||
$this->logDebug('huojian spider config', [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'landingUrlHint' => $this->landingUrlHint,
|
||||
'sessionKey' => $antiBot['sessionKey'] ?? '',
|
||||
'businessHostHint' => $antiBot['businessHostHint'] ?? '',
|
||||
'cfClearanceRequired' => $antiBot['cfClearanceRequired'] ?? null,
|
||||
]);
|
||||
|
||||
return [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'apiUrls' => [self::API_LIST],
|
||||
|
||||
// 明确指派角色
|
||||
'listApi' => self::API_LIST, // 必须
|
||||
|
||||
'listMethod' => 'POST',
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'listApi' => self::API_LIST,
|
||||
'listMethod' => 'POST',
|
||||
'paginationMode' => self::MODE_UI,
|
||||
|
||||
'authActions' => [
|
||||
// 1. 填入密码:寻找 class 包含 el-message-box__input 下面的任意 input
|
||||
// Node.js 会自动扫描所有匹配项,并只把密码强行注入到那个“肉眼可见”的框里
|
||||
'authActions' => [
|
||||
['type' => 'vue_fill', 'selector' => '.el-message-box__input input', 'value' => $this->password],
|
||||
|
||||
// 2. 停顿 500ms,让 Vue 绑定的 v-model 彻底反应过来
|
||||
['type' => 'wait', 'ms' => 500],
|
||||
|
||||
// 3. 点击确认:寻找 MessageBox 底部的蓝色 primary 确认按钮
|
||||
// 同样利用 vue_click 的可见性过滤,无视隐藏的旧弹窗按钮
|
||||
['type' => 'vue_click', 'selector' => '.el-message-box__btns .el-button--primary'],
|
||||
|
||||
// 4. 等待弹窗淡出,接口开始请求
|
||||
['type' => 'wait', 'ms' => 2000]
|
||||
]
|
||||
['type' => 'wait', 'ms' => 2000],
|
||||
],
|
||||
'antiBot' => $antiBot,
|
||||
];
|
||||
}
|
||||
|
||||
// 只负责解析 List 的总页数
|
||||
/**
|
||||
* 对齐生产 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 '';
|
||||
}
|
||||
|
||||
protected function extractListTotalPages($listFirstPageData, $countData = null)
|
||||
{
|
||||
// 只有一页
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 没有分页返回空数组
|
||||
protected function buildListPageParams($page)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// 提供 List 的下一页按钮信息
|
||||
protected function getUiPaginationConfig()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// 清爽至极的数据清洗:详情是详情,列表是列表
|
||||
protected function parseToUnifiedData($detailData, $allListPagesData)
|
||||
{
|
||||
$unifiedData = $this->unifiedData;
|
||||
|
||||
$unifiedData->todayNewCount = $allListPagesData[0]['data']['counterWorker']['newTodayFriend'];
|
||||
|
||||
// 2. 循环合并了所有页数的 List 数组
|
||||
|
||||
$unifiedData->todayNewCount = (int) ($allListPagesData[0]['data']['counterWorker']['newTodayFriend'] ?? 0);
|
||||
|
||||
$count = 0;
|
||||
foreach ($allListPagesData as $pageRaw) {
|
||||
$records = $pageRaw['data']['counterCsAccountVo'] ?? [];
|
||||
$records = $pageRaw['data']['counterCsAccountVo'] ?? [];
|
||||
foreach ($records as $item) {
|
||||
if(!empty($item['accountLogin'])) {
|
||||
$number = $item['accountLogin'] ?? null;
|
||||
$isOnline = (isset($item['accountStatus']) && $item['accountStatus'] == 1);
|
||||
if (!empty($item['accountLogin'])) {
|
||||
$number = $item['accountLogin'];
|
||||
$isOnline = (isset($item['accountStatus']) && (int) $item['accountStatus'] === 1);
|
||||
$count++;
|
||||
$unifiedData->addNumber($number, $isOnline, $item['newTodayFriend']);
|
||||
$unifiedData->addNumber($number, $isOnline, (int) ($item['newTodayFriend'] ?? 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$unifiedData->total = $count;
|
||||
|
||||
return $unifiedData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user