diff --git a/apps/third/king/k.py b/apps/third/king/k.py index 4d2ee508..4ee44e6e 100644 --- a/apps/third/king/k.py +++ b/apps/third/king/k.py @@ -40,12 +40,18 @@ class KingClient(HandleLogMixin): } _, res = self.request( **kapis['login'], json=json, timeout=10) + old_token = cache.get('king_token', '') cache.set('king_token', res['Authorization'], timeout=None) + if old_token: + _, res = self.request(**kapis['logout'], authorization=old_token) - def request(self, url: str, method: str = 'post', params=dict(), json=dict(), timeout=20, raise_exception=True): + def request(self, url: str, method: str = 'post', params=dict(), json=dict(), timeout=20, raise_exception=True, authorization=''): if not self.king_enabled: raise ParseError('亚控对接未启用') - self.headers['Authorization'] = cache.get('king_token', '') + if authorization: + self.headers['Authorization'] = authorization + else: + self.headers['Authorization'] = cache.get('king_token', '') self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method, "params": params, "body": json, "target": "king", "result": 10, "headers": self.headers} try: