检查 Sentinel 拦截 Args: did: Device ID proxies: 代理配置 Returns: Sentinel token 或 None
(self, did: str, proxies: Optional[Dict] = None)
| 351 | raise HTTPClientError(f"OpenAI 请求失败: {endpoint} - {e}") |
| 352 | |
| 353 | def check_sentinel(self, did: str, proxies: Optional[Dict] = None) -> Optional[str]: |
| 354 | """ |
| 355 | 检查 Sentinel 拦截 |
| 356 | |
| 357 | Args: |
| 358 | did: Device ID |
| 359 | proxies: 代理配置 |
| 360 | |
| 361 | Returns: |
| 362 | Sentinel token 或 None |
| 363 | """ |
| 364 | from ..config.constants import OPENAI_API_ENDPOINTS |
| 365 | |
| 366 | try: |
| 367 | pow_token = build_sentinel_pow_token(self.default_headers.get("User-Agent", "")) |
| 368 | sen_req_body = json.dumps({ |
| 369 | "p": pow_token, |
| 370 | "id": did, |
| 371 | "flow": "authorize_continue", |
| 372 | }, separators=(",", ":")) |
| 373 | |
| 374 | response = self.post( |
| 375 | OPENAI_API_ENDPOINTS["sentinel"], |
| 376 | headers={ |
| 377 | "origin": "https://sentinel.openai.com", |
| 378 | "referer": "https://sentinel.openai.com/backend-api/sentinel/frame.html?sv=20260219f9f6", |
| 379 | "content-type": "text/plain;charset=UTF-8", |
| 380 | }, |
| 381 | data=sen_req_body, |
| 382 | ) |
| 383 | |
| 384 | if response.status_code == 200: |
| 385 | return response.json().get("token") |
| 386 | else: |
| 387 | logger.warning(f"Sentinel 检查失败: {response.status_code}") |
| 388 | return None |
| 389 | |
| 390 | except SentinelPOWError as e: |
| 391 | logger.error(f"Sentinel POW 求解失败: {e}") |
| 392 | return None |
| 393 | except Exception as e: |
| 394 | logger.error(f"Sentinel 检查异常: {e}") |
| 395 | return None |
| 396 | |
| 397 | |
| 398 | def create_http_client( |