修复whatshub工单数据同步
This commit is contained in:
@@ -147,12 +147,16 @@ class AntiBotConfigBuilder
|
||||
{
|
||||
if ($ticketType === 'whatshub') {
|
||||
return [
|
||||
'postCfReadyUrlContains' => 'work-order-sharing',
|
||||
'postCfReadySelector' => '.el-input__inner',
|
||||
'postCfReadyApiUrl' => '/api/whatshub-counter/workShare/open/statistics',
|
||||
'postCfReadyTimeoutMs' => 60000,
|
||||
'postCfSettleMs' => 500,
|
||||
'postCfSpaWaitMs' => 4000,
|
||||
'postCfReadyUrlContains' => 'work-order-sharing',
|
||||
// 业务页表格就绪即可;密码框为 vxe-form,勿用泛化 .el-input__inner
|
||||
'postCfReadySelector' => '.vxe-table, .vxe-grid',
|
||||
'postCfReadySelectorOptional' => true,
|
||||
// statistics 仅在密码验证后触发,禁止 pre-auth 等待(见 Node skipPostCfReadyApi)
|
||||
'postCfReadyTimeoutMs' => 60000,
|
||||
'postCfSettleMs' => 500,
|
||||
'postCfSpaWaitMs' => 4000,
|
||||
'skipShortLinkCfPurgeOnReuse' => true,
|
||||
'authSkipIfNoPasswordDialog' => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,13 @@ class WhatshubSpider extends AbstractScrmSpider
|
||||
}
|
||||
|
||||
/**
|
||||
* 混合同步:cURL 拉号码 + Node 监听 statistics 算完成量;任一失败则完整 Node fallback
|
||||
* 混合同步:cURL 拉号码 + Node 监听 statistics 算完成量
|
||||
* statistics 失败时清 session 重试;仍失败则 fallback 完整 Node 仅取完成量
|
||||
*/
|
||||
public function run(): UnifiedScrmData
|
||||
{
|
||||
$apiResult = $this->tryFetchViaShareCodeApi();
|
||||
$statsCount = $this->tryFetchStatisticsViaNode();
|
||||
$statsCount = $this->tryFetchStatisticsViaNode(false);
|
||||
|
||||
if ($apiResult instanceof UnifiedScrmData && $statsCount !== null) {
|
||||
$apiResult->todayNewCount = $statsCount;
|
||||
@@ -68,26 +69,82 @@ class WhatshubSpider extends AbstractScrmSpider
|
||||
return $apiResult;
|
||||
}
|
||||
|
||||
// cURL 已成功:清 session 再试 statistics;仍失败则完整 Node 只取完成量
|
||||
if ($apiResult instanceof UnifiedScrmData) {
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub stats retry after purge session', [
|
||||
'numberCount' => count($apiResult->numbers),
|
||||
]);
|
||||
$statsCount = $this->tryFetchStatisticsViaNode(true);
|
||||
if ($statsCount !== null) {
|
||||
$apiResult->todayNewCount = $statsCount;
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub hybrid path ok (retry)', [
|
||||
'numberCount' => count($apiResult->numbers),
|
||||
'todayNewCount' => $statsCount,
|
||||
]);
|
||||
return $apiResult;
|
||||
}
|
||||
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub stats fallback full node for complete count', [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'numberCount' => count($apiResult->numbers),
|
||||
]);
|
||||
try {
|
||||
$fullResult = parent::run();
|
||||
$apiResult->todayNewCount = $fullResult->todayNewCount;
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub hybrid path ok (full node stats)', [
|
||||
'numberCount' => count($apiResult->numbers),
|
||||
'todayNewCount' => $apiResult->todayNewCount,
|
||||
]);
|
||||
return $apiResult;
|
||||
} catch (\Throwable $e) {
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub stats fallback full node failed', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Whatshub statistics 同步失败(号码已通过 API 获取,无法更新完成量)');
|
||||
}
|
||||
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub hybrid incomplete, fallback full node', [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'apiOk' => $apiResult instanceof UnifiedScrmData,
|
||||
'apiOk' => false,
|
||||
'statisticsOk' => $statsCount !== null,
|
||||
]);
|
||||
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
/** Whatshub vxe 密码表单:placeholder 含「密码」+ 确认按钮,与业务页搜索框区分 */
|
||||
private const AUTH_PASSWORD_INPUT = '.vxe-form .el-input__inner[placeholder*="密码"]';
|
||||
|
||||
private const AUTH_CONFIRM_BUTTON = '.vxe-form .vxe-button-group button.theme--primary[type="submit"]';
|
||||
|
||||
/**
|
||||
* Node 监听 statistics API,返回 dayNewFans + reDayNewFans 总和;失败返回 null
|
||||
*
|
||||
* @param bool $isRetry 是否为清 session 后的二次尝试
|
||||
*/
|
||||
private function tryFetchStatisticsViaNode(): ?int
|
||||
private function tryFetchStatisticsViaNode(bool $isRetry = false): ?int
|
||||
{
|
||||
$config = $this->getSpiderConfig();
|
||||
$antiBot = $config['antiBot'] ?? null;
|
||||
if (is_array($antiBot)) {
|
||||
// statistics-only:早挂拦截器、识别 vxe 密码框、session 有效时 skip auth
|
||||
$antiBot = array_merge($antiBot, [
|
||||
'skipPostCfReadyApi' => true,
|
||||
'authSkipIfNoPasswordDialog' => true,
|
||||
'authSelectorTimeoutMs' => 30000,
|
||||
'earlyApiIntercept' => true,
|
||||
]);
|
||||
if ($isRetry) {
|
||||
$antiBot['purgeSession'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub stats node request', [
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'api' => self::API_DETAILS,
|
||||
'pageUrl' => $this->pageUrl,
|
||||
'api' => self::API_DETAILS,
|
||||
'isRetry' => $isRetry,
|
||||
]);
|
||||
|
||||
$result = $this->requestNode('/api/auth-and-intercept', [
|
||||
@@ -101,6 +158,7 @@ class WhatshubSpider extends AbstractScrmSpider
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub stats node failed', [
|
||||
'error' => $result['error'] ?? '未知',
|
||||
'code' => $result['code'] ?? null,
|
||||
'page' => $result['page'] ?? null,
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
@@ -109,6 +167,7 @@ class WhatshubSpider extends AbstractScrmSpider
|
||||
if (!isset($intercepted[self::API_DETAILS]['data']) || !is_array($intercepted[self::API_DETAILS]['data'])) {
|
||||
SplitTicketSyncLogger::log('spider', 'whatshub stats node missing payload', [
|
||||
'intercepted' => array_keys(is_array($intercepted) ? $intercepted : []),
|
||||
'page' => $result['page'] ?? null,
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
@@ -287,10 +346,10 @@ class WhatshubSpider extends AbstractScrmSpider
|
||||
'listMethod' => 'POST',
|
||||
'paginationMode' => self::MODE_UI,
|
||||
'authActions' => [
|
||||
// Element Plus 密码弹窗:仅注入可见 input
|
||||
['type' => 'vue_fill', 'selector' => '.el-input__inner', 'value' => $this->password],
|
||||
// Whatshub 密码 UI 为 vxe-form + Element input,限定在表单内避免误填搜索框
|
||||
['type' => 'vue_fill', 'selector' => self::AUTH_PASSWORD_INPUT, 'value' => $this->password],
|
||||
['type' => 'wait', 'ms' => 500],
|
||||
['type' => 'vue_click', 'selector' => '.vxe-button-group .theme--primary'],
|
||||
['type' => 'vue_click', 'selector' => self::AUTH_CONFIRM_BUTTON],
|
||||
['type' => 'wait', 'ms' => 2200],
|
||||
],
|
||||
'antiBot' => AntiBotConfigBuilder::build('whatshub', $this->pageUrl),
|
||||
|
||||
Reference in New Issue
Block a user