Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: failed to download image of group of gewechat #168

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions channel/gewechat/gewechat_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,16 @@ def download_image(self):
try:
try:
# 尝试下载高清图片
image_info = self.client.download_image(app_id=self.app_id, xml=self.msg['Data']['Content']['string'], type=1)
content_xml = self.msg['Data']['Content']['string']
# Find the position of '<?xml' declaration and remove any prefix
xml_start = content_xml.find('<?xml version=')
if xml_start != -1:
content_xml = content_xml[xml_start:]
image_info = self.client.download_image(app_id=self.app_id, xml=content_xml, type=1)
except Exception as e:
logger.warning(f"[gewechat] Failed to download high-quality image: {e}")
# 尝试下载普通图片
image_info = self.client.download_image(app_id=self.app_id, xml=self.msg['Data']['Content']['string'], type=2)
image_info = self.client.download_image(app_id=self.app_id, xml=content_xml, type=2)
if image_info['ret'] == 200 and image_info['data']:
file_url = image_info['data']['fileUrl']
logger.info(f"[gewechat] Download image file from {file_url}")
Expand Down
Loading