Browse Source

获取自动回复卡片任务优化

luojunhui 4 days ago
parent
commit
ea1f630e8a

+ 28 - 2
app/domains/monitor_tasks/auto_reply_cards_monitor/_utils.py

@@ -137,7 +137,33 @@ class AutoReplyCardsMonitorUtils:
         return video_id, root_source_id
 
     @staticmethod
-    async def get_cover_url(aes_key, total_size, file_id):
+    async def get_cover_url(aes_key, file_id):
+        url = "https://wechat-protocol.aiddit.com/xed/getCdnUrl"
+        data = {
+            "file_id": file_id,
+            "aes_key": aes_key
+        }
+        headers = {
+            "Content-Type": "application/json",
+        }
+        try:
+            async with AsyncHttpClient() as client:
+                response = await client.post(
+                    url, headers=headers, data=json.dumps(data)
+                )
+            if response and response.get("status") != 0:
+                print(f"[ERROR] get_cover_url API error: status={response.get('status')}, msg={response.get('msg')}")
+                return None
+            return response
+        except Exception as e:
+            print(f"[ERROR] get_cover_url failed: {e}")
+            return None
+
+    @staticmethod
+    async def get_cover_url_old(aes_key, total_size, file_id):
+        """
+        gewe API 暂时失效
+        """
         url = "http://api.geweapi.com/gewe/v2/api/message/downloadCdn"
         data = {
             "appId": "wx_anFlUnezoUynU3SKcqTWk",
@@ -201,7 +227,7 @@ class AutoReplyCardsMonitorUtils:
     @staticmethod
     def download_cover(file_name, cover_obj, timeout=10):
         try:
-            cover_url = cover_obj["data"]["fileUrl"]
+            cover_url = cover_obj["oss_object"]["cdn_url"]
         except (KeyError, TypeError):
             print(f"[WARN] Invalid cover_obj structure: {cover_obj}")
             return None

+ 2 - 3
app/domains/monitor_tasks/auto_reply_cards_monitor/entrance.py

@@ -49,9 +49,8 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
         video_id, root_source_id = self.tool.extract_page_path(page_path)
 
         aes_key = xml_obj.get("aes_key")
-        file_size = xml_obj.get("file_size")
         file_id = xml_obj.get("file_id")
-        if not all([aes_key, file_size, file_id]):
+        if not all([aes_key, file_id]):
             await self.log_service.log(
                 contents={
                     "task": "auto_reply_cards_monitor",
@@ -63,7 +62,7 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
             )
             return False
 
-        cover_obj = await self.tool.get_cover_url(aes_key, file_size, file_id)
+        cover_obj = await self.tool.get_cover_url(aes_key, file_id)
         if not cover_obj:
             await self.log_service.log(
                 contents={