From 848f16346b6e5af8ac854325cb9ba28b34a2a48e Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Sun, 17 Aug 2025 16:06:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(maizone):=20=E5=85=BC=E5=AE=B9=E6=96=B0?= =?UTF-8?q?=E7=89=88QQ=E7=A9=BA=E9=97=B4=E5=8A=A8=E6=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E7=9A=84JSON=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QQ空间监控好友动态的接口返回格式从 JSONP (_Callback(...)) 变更为纯 JSON。 本次提交通过增加判断,兼容了新旧两种数据格式,并修复了因此导致的动态拉取失败问题。 同时,为 `images` 循环中的未使用变量 `img_bytes` 添加下划线前缀,并为 `pic_bos` 和 `richvals` 两个未使用的变量添加 `# noqa: F841` 以消除 linter 警告。 --- .../services/qzone_service.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/plugins/built_in/maizone_refactored/services/qzone_service.py b/src/plugins/built_in/maizone_refactored/services/qzone_service.py index eb3664e61..b958478cd 100644 --- a/src/plugins/built_in/maizone_refactored/services/qzone_service.py +++ b/src/plugins/built_in/maizone_refactored/services/qzone_service.py @@ -283,11 +283,11 @@ class QZoneService: "qzreferrer": f"https://user.qzone.qq.com/{uin}", } if images: - pic_bos, richvals = [], [] + pic_bos, richvals = [], [] # noqa: F841 # The original logic for uploading images is complex and involves multiple steps. # This simplified version captures the essence. A full implementation would require # a separate, robust image upload function. - for img_bytes in images: + for _img_bytes in images: # This is a placeholder for the actual image upload logic which is quite complex. # In a real scenario, you would call a dedicated `_upload_image` method here. # For now, we assume the upload is successful and we get back dummy data. @@ -439,12 +439,19 @@ class QZoneService: res_text = await _request("GET", self.ZONE_LIST_URL, params=params) # 增加对返回内容的校验 - if not res_text.startswith("_Callback(") or not res_text.endswith(");"): + if res_text.startswith("_Callback("): + # 兼容旧版jsonp格式 + json_str = res_text[len("_Callback(") : -2] + else: + # 兼容新版纯json格式 + json_str = res_text + + try: + # 替换 undefined 为 null + json_data = json5.loads(json_str.replace("undefined", "null")) + except Exception: logger.warning(f"监控好友动态返回格式异常: {res_text}") return [] - - json_str = res_text[len("_Callback(") : -2].replace("undefined", "null") - json_data = json5.loads(json_str) feeds_data = [] if isinstance(json_data, dict): data_level1 = json_data.get("data")