From 2b0fd12f4b0baa8af87eb8b1a68d9632d3a21e52 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Tue, 19 Aug 2025 23:14:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(maizone=5Frefactored):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96Cookie=E6=9C=8D=E5=8A=A1=E4=B8=AD=E5=A4=87=E7=94=A8HTT?= =?UTF-8?q?P=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将获取Cookie的HTTP请求从GET改为POST,并增加domain参数,以适配更可靠的实现。同时,增强了对返回数据的解析和校验逻辑,确保能正确处理并转换Cookie字符串格式,提高了服务的健壮性和兼容性。 --- .../services/cookie_service.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugins/built_in/maizone_refactored/services/cookie_service.py b/src/plugins/built_in/maizone_refactored/services/cookie_service.py index d4587cda8..ab7c07a6c 100644 --- a/src/plugins/built_in/maizone_refactored/services/cookie_service.py +++ b/src/plugins/built_in/maizone_refactored/services/cookie_service.py @@ -79,11 +79,21 @@ class CookieService: try: timeout = aiohttp.ClientTimeout(total=15) + # 根据更可靠的实现,这里应该使用POST并传递domain + payload = {"domain": "user.qzone.qq.com"} async with aiohttp.ClientSession() as session: - async with session.get(http_url, timeout=timeout) as response: + async with session.post(http_url, json=payload, timeout=timeout) as response: response.raise_for_status() - # 假设API直接返回JSON格式的cookie - return await response.json() + data = await response.json() + + # 确保返回的数据格式被正确解析,兼容Adapter的返回结构 + cookie_str = data.get("data", {}).get("cookies") + if cookie_str and isinstance(cookie_str, str): + logger.info("从HTTP备用地址成功解析Cookie字符串。") + return {k.strip(): v.strip() for k, v in (p.split('=', 1) for p in cookie_str.split('; ') if '=' in p)} + + logger.warning(f"从HTTP备用地址获取的Cookie格式不正确或为空: {data}") + return None except Exception as e: logger.error(f"通过HTTP备用地址 {http_url} 获取Cookie失败: {e}") return None