feat: kingClient登录优化
This commit is contained in:
parent
0c6fe5e37c
commit
f1e1ae5dc6
|
@ -40,12 +40,18 @@ class KingClient(HandleLogMixin):
|
||||||
}
|
}
|
||||||
_, res = self.request(
|
_, res = self.request(
|
||||||
**kapis['login'], json=json, timeout=10)
|
**kapis['login'], json=json, timeout=10)
|
||||||
|
old_token = cache.get('king_token', '')
|
||||||
cache.set('king_token', res['Authorization'], timeout=None)
|
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:
|
if not self.king_enabled:
|
||||||
raise ParseError('亚控对接未启用')
|
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,
|
self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method,
|
||||||
"params": params, "body": json, "target": "king", "result": 10, "headers": self.headers}
|
"params": params, "body": json, "target": "king", "result": 10, "headers": self.headers}
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue