From 8bfceb4b32aa7b3f2e0e1a131250194741efbbc3 Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 12 Sep 2023 22:12:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=B1=8F=E8=94=BD=E6=8E=89?= =?UTF-8?q?=E8=BE=93=E9=94=99=E8=BA=AB=E4=BB=BD=E7=A0=81=E7=9A=84=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/open_live.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/api/open_live.py b/api/open_live.py index 00732ac..803c0ae 100644 --- a/api/open_live.py +++ b/api/open_live.py @@ -6,6 +6,7 @@ import hmac import json import logging import random +import re from typing import * import aiohttp @@ -63,6 +64,10 @@ async def _request_open_live(url, body: dict) -> dict: cfg = config.get_config() assert cfg.is_open_live_configured + # 输错身份码的人太多了,临时处理屏蔽请求,不然要被B站下架了 + if url == START_GAME_OPEN_LIVE_URL: + _validate_auth_code(body.get('code', '')) + body_bytes = json.dumps(body).encode('utf-8') headers = { 'x-bili-accesskeyid': cfg.open_live_access_key_id, @@ -109,6 +114,19 @@ async def _read_response(req_ctx_mgr: AsyncContextManager[aiohttp.ClientResponse raise TransportError(f'{type(e).__name__}: {e}') +def _validate_auth_code(auth_code): + if re.fullmatch(r'[0-9A-Z]{11,16}', auth_code): + return + + logger.warning('Auth code error! auth_code=%s', auth_code) + raise BusinessError({ + 'code': 7007, + 'message': '身份码错误', + 'data': {}, + 'request_id': '0' + }) + + class _OpenLiveHandlerBase(api.base.ApiHandler): def prepare(self): super().prepare()