feat: kingClient登录优化

This commit is contained in:
caoqianming 2024-04-25 12:34:56 +08:00
parent 0c6fe5e37c
commit f1e1ae5dc6
1 changed files with 8 additions and 2 deletions

View File

@ -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: