|
|
@@ -136,28 +136,8 @@ class ThirdPartyPusher:
|
|
|
logger.error(f"[第三方平台] 处理上报错误: {e}")
|
|
|
|
|
|
def _get_auth_headers(self) -> Dict[str, str]:
|
|
|
- """获取认证请求头"""
|
|
|
- headers = {
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- 'Accept': 'application/json',
|
|
|
- }
|
|
|
-
|
|
|
- if self.auth_type == 'api_key':
|
|
|
- headers['X-API-Key'] = self.api_key
|
|
|
- if self.api_secret:
|
|
|
- headers['X-API-Secret'] = self.api_secret
|
|
|
-
|
|
|
- elif self.auth_type == 'oauth2':
|
|
|
- token = self._get_oauth2_token()
|
|
|
- if token:
|
|
|
- headers['Authorization'] = f'Bearer {token}'
|
|
|
-
|
|
|
- elif self.auth_type == 'basic':
|
|
|
- import base64
|
|
|
- credentials = base64.b64encode(f"{self.api_key}:{self.api_secret}".encode()).decode()
|
|
|
- headers['Authorization'] = f'Basic {credentials}'
|
|
|
-
|
|
|
- return headers
|
|
|
+ """获取认证请求头(当前第三方接口不需要自定义 header,返回空避免 422)"""
|
|
|
+ return {}
|
|
|
|
|
|
def _get_oauth2_token(self) -> Optional[str]:
|
|
|
"""获取 OAuth2 Token"""
|
|
|
@@ -300,29 +280,15 @@ class ThirdPartyPusher:
|
|
|
def _build_payload(self, report: BatchReport) -> Dict[str, Any]:
|
|
|
"""
|
|
|
构建上报请求体
|
|
|
-
|
|
|
+
|
|
|
Args:
|
|
|
report: 批次上报数据
|
|
|
-
|
|
|
+
|
|
|
Returns:
|
|
|
Dict: 请求体字典
|
|
|
"""
|
|
|
batch_info = report.batch_info
|
|
|
-
|
|
|
- # 标准上报格式
|
|
|
- payload = {
|
|
|
- 'deviceId': report.device_id,
|
|
|
- 'projectId': report.project_id,
|
|
|
- 'batchId': report.batch_id,
|
|
|
- 'timestamp': report.timestamp,
|
|
|
- 'datetime': datetime.fromtimestamp(report.timestamp).isoformat(),
|
|
|
- 'totalPersons': batch_info.get('total_persons', 0),
|
|
|
- 'ptzImagesCount': batch_info.get('ptz_images_count', 0),
|
|
|
- 'panorama': batch_info.get('panorama', {}),
|
|
|
- 'persons': batch_info.get('persons', []),
|
|
|
- 'uploadStatus': batch_info.get('upload_status', {}),
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
# 根据平台类型调整格式
|
|
|
if self.platform_type == 'jtjai':
|
|
|
# jtjai 平台特定格式
|
|
|
@@ -339,7 +305,10 @@ class ThirdPartyPusher:
|
|
|
'persons': batch_info.get('persons', []),
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
+ else:
|
|
|
+ # custom / 其他平台:原样发送 batch_info(snake_case)
|
|
|
+ payload = dict(batch_info)
|
|
|
+
|
|
|
return payload
|
|
|
|
|
|
def report_batch(self, batch_info: Dict[str, Any], local_path: Optional[str] = None):
|