Skip to content

Commit

Permalink
chore: 更改captcha参数的填写方法,适配更多格式 (#248)
Browse files Browse the repository at this point in the history
* chore: 更改captcha参数的填写方法,适配更多格式

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: 0-8-4 <ljd69154@liangjundi.cn>
  • Loading branch information
3 people authored Dec 19, 2023
1 parent fe46884 commit a7fb1b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions utils/captcha.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'''
Date: 2023-11-13 19:55:22
LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2023-11-25 15:59:40
LastEditTime: 2023-12-18 20:46:51
'''
import json

from .request import post
from .logger import log
Expand All @@ -26,13 +27,9 @@ async def get_validate(gt: str, challenge: str) -> GeetestResult: # pylint: dis
validate = None
if _conf.preference.geetest_url:
params = _conf.preference.geetest_params.copy()
for key, value in params.items():
if isinstance(value, str):
params[key] = value.format(gt=gt, challenge=challenge)
params = json.loads(json.dumps(params).replace("{gt}", gt).replace("{challenge}", challenge))
data = _conf.preference.geetest_data.copy()
for key, value in data.items():
if isinstance(value, str):
data[key] = value.format(gt=gt, challenge=challenge)
data = json.loads(json.dumps(data).replace("{gt}", gt).replace("{challenge}", challenge))
response = await post(
_conf.preference.geetest_url,
params=params,
Expand Down
6 changes: 3 additions & 3 deletions utils/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ApiResultHandler(BaseModel):
"""
content: Dict[str, Any]
"""API返回的JSON对象序列化以后的Dict对象"""
data: Optional[Dict[str, Any]] = None
data: Dict[str, Any] = {}
"""API返回的数据体"""
message: str = ""
"""API返回的消息内容"""
Expand All @@ -20,8 +20,8 @@ def __init__(self, content: Dict[str, Any]):
super().__init__(content=content)

for key in ["data", "entity"]:
if self.data is None:
self.data = self.content.get(key)
if self.data == {}:
self.data = self.content.get(key, {})
else:
break

Expand Down

0 comments on commit a7fb1b0

Please sign in to comment.