From 20867a2135de368f0cbd15bcf943a4e0a63edbb2 Mon Sep 17 00:00:00 2001 From: kinori Date: Sat, 2 Sep 2023 12:42:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=80=E6=94=BE=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=8E=A5=E5=8F=A3=E5=90=AF=E7=94=A8=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blivedm/client.py | 4 +++- blivedm/open_live_client.py | 5 +++-- open_live_sample.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/blivedm/client.py b/blivedm/client.py index 7df3e03..e05d5c9 100644 --- a/blivedm/client.py +++ b/blivedm/client.py @@ -104,6 +104,7 @@ class BLiveClient: heartbeat_interval=30, ssl: Union[bool, ssl_.SSLContext] = True, + use_open_live: bool = False, open_live_app_id: Optional[int] = None, open_live_access_key: Optional[str] = None, open_live_access_secret: Optional[str] = None, @@ -150,10 +151,11 @@ class BLiveClient: self._heartbeat_timer_handle: Optional[asyncio.TimerHandle] = None """发心跳包定时器的handle""" + self._open_live_client = None self._host_server_auth_body: Dict = None """开放平台的完整鉴权body""" - if open_live_app_id and open_live_access_key and open_live_access_secret and open_live_code: + if use_open_live: self._open_live_client = OpenLiveClient(open_live_app_id, open_live_access_key, open_live_access_secret, self._session, self._ssl) self._open_live_auth_code = open_live_code diff --git a/blivedm/open_live_client.py b/blivedm/open_live_client.py index 456038a..e010bbe 100644 --- a/blivedm/open_live_client.py +++ b/blivedm/open_live_client.py @@ -149,7 +149,7 @@ class OpenLiveClient: return False try: - params = f'{{"app_id":"{self.app_id}","game_id":{self._game_id}}}' + params = f'{{"app_id":{self.app_id},"game_id":{self._game_id}}}' headers = self._sign_request_header(params) async with self._session.post( OPEN_LIVE_END_URL, headers=headers, data=params, ssl=self._ssl @@ -175,7 +175,8 @@ class OpenLiveClient: return False try: - params = f'{{""game_id":{self._game_id}}}' + params = f'{{"game_id":{self._game_id}}}' + print(params) headers = self._sign_request_header(params) async with self._session.post( OPEN_LIVE_HEARTBEAT_URL, headers=headers, data=params, ssl=self._ssl diff --git a/open_live_sample.py b/open_live_sample.py index 832d123..bf21222 100644 --- a/open_live_sample.py +++ b/open_live_sample.py @@ -19,14 +19,14 @@ async def main(): await run_start() async def run_start(): - client = blivedm.BLiveClient(open_live_app_id=APP_ID, open_live_access_key=ACCESS_KEY, open_live_access_secret=ACCESS_KEY_SECRET, open_live_code=TEST_AUTH_CODE, ssl=True) + client = blivedm.BLiveClient(use_open_live=True, open_live_app_id=APP_ID, open_live_access_key=ACCESS_KEY, open_live_access_secret=ACCESS_KEY_SECRET, open_live_code=TEST_AUTH_CODE, ssl=True) handler = OpenLiveHandlerInterface() client.add_handler(handler) client.start() try: # 演示60秒后停止 - await asyncio.sleep(60) + await asyncio.sleep(600) client.stop() await client.join()