855 协议版本-调整完毕内容
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
"""
|
||||
联系人管理器 - 提供全局访问联系人信息的单例类
|
||||
"""
|
||||
import logging
|
||||
|
||||
from loguru import logger
|
||||
from typing import Dict, Optional, List, Tuple
|
||||
|
||||
from gewechat_client import GewechatClient
|
||||
|
||||
from utils.json_converter import json_to_object
|
||||
|
||||
@@ -20,7 +20,7 @@ class ContactManager:
|
||||
_official_accounts: Dict[str, str] = {} # 公众号
|
||||
_head_images: Dict[str, str] = {} # 头像信息
|
||||
_initialized = False
|
||||
_logger = logging.getLogger("ContactManager")
|
||||
_logger = logger
|
||||
_friends: List[Dict] = []
|
||||
_group_contacts_friends: Dict[str, Dict[str, str]] = {}
|
||||
# 定义公共好友列表
|
||||
|
||||
@@ -1,29 +1,24 @@
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
import xml.etree.ElementTree as ET
|
||||
import logging
|
||||
import concurrent.futures # 添加线程池支持
|
||||
import os
|
||||
|
||||
from gewechat_client import GewechatClient
|
||||
|
||||
from db.connection import DBConnectionManager
|
||||
from db.message_storage import MessageStorageDB
|
||||
# 导入积分系统
|
||||
from db.points_db import PointsDBOperator, PointSource
|
||||
from gewechat.call_back_message.message import WxMessage, MessageType
|
||||
from wechat_ipad import WechatAPIClient
|
||||
from wechat_ipad.models.message import WxMessage, MessageType
|
||||
|
||||
# 配置日志
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
logger = logging.getLogger("MessageStorage")
|
||||
from loguru import logger
|
||||
|
||||
logging = logger
|
||||
|
||||
|
||||
class MessageStorage:
|
||||
|
||||
def __init__(self, client: GewechatClient = None):
|
||||
def __init__(self, client: WechatAPIClient = None):
|
||||
# 获取数据库连接管理器的单例
|
||||
self.db_manager = DBConnectionManager.get_instance()
|
||||
self.message_db = MessageStorageDB(self.db_manager)
|
||||
@@ -123,38 +118,38 @@ class MessageStorage:
|
||||
if not os.path.exists(target_dir):
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
# 尝试使用wcf下载图片到分组后的目录
|
||||
json = self.client.download_image(msg.appid, msg.content.xml_content, 2)
|
||||
# {
|
||||
# "ret": 200,
|
||||
# "msg": "操作成功",
|
||||
# "data": {
|
||||
# "fileUrl": "/download/20240720/wx_BTVoJ_o_r6DpxNCNiycFE/0ca5b675-8e2c-4dc1-b288-3c44a40086ec4"
|
||||
# }
|
||||
# }
|
||||
# 解析JSON http://192.168.2.240:2532/download/20250428/wx_3BC6eSHGE5xEm_hH3__7c/03ab5c03-5524-4a39-aabe-27ca014a4d1e.png
|
||||
if json and json.get('data') and json['data'].get('fileUrl'):
|
||||
file_url = json['data']['fileUrl']
|
||||
if file_url:
|
||||
logger.info(f"记录gewe服务端图片路径成功: {msg.msg_id} -> {file_url}")
|
||||
# 后续如果需要使用,则去服务器端提取图片
|
||||
# 直接使用下载后的路径更新数据库
|
||||
self.message_db.update_message_image_path(msg.msg_id, file_url)
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
'message_id': msg.msg_id,
|
||||
'roomid': msg.roomid,
|
||||
'sender': msg.sender,
|
||||
'file_path': file_url
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'success': False,
|
||||
'message_id': msg.msg_id,
|
||||
'roomid': msg.roomid,
|
||||
'sender': msg.sender,
|
||||
'error': "图片下载失败"
|
||||
}
|
||||
# json = self.client.download_image(msg.appid, msg.content.xml_content, 2)
|
||||
# # {
|
||||
# # "ret": 200,
|
||||
# # "msg": "操作成功",
|
||||
# # "data": {
|
||||
# # "fileUrl": "/download/20240720/wx_BTVoJ_o_r6DpxNCNiycFE/0ca5b675-8e2c-4dc1-b288-3c44a40086ec4"
|
||||
# # }
|
||||
# # }
|
||||
# # 解析JSON http://192.168.2.240:2532/download/20250428/wx_3BC6eSHGE5xEm_hH3__7c/03ab5c03-5524-4a39-aabe-27ca014a4d1e.png
|
||||
# if json and json.get('data') and json['data'].get('fileUrl'):
|
||||
# file_url = json['data']['fileUrl']
|
||||
# if file_url:
|
||||
# logger.info(f"记录gewe服务端图片路径成功: {msg.msg_id} -> {file_url}")
|
||||
# # 后续如果需要使用,则去服务器端提取图片
|
||||
# # 直接使用下载后的路径更新数据库
|
||||
# self.message_db.update_message_image_path(msg.msg_id, file_url)
|
||||
#
|
||||
# return {
|
||||
# 'success': True,
|
||||
# 'message_id': msg.msg_id,
|
||||
# 'roomid': msg.roomid,
|
||||
# 'sender': msg.sender,
|
||||
# 'file_path': file_url
|
||||
# }
|
||||
# else:
|
||||
# return {
|
||||
# 'success': False,
|
||||
# 'message_id': msg.msg_id,
|
||||
# 'roomid': msg.roomid,
|
||||
# 'sender': msg.sender,
|
||||
# 'error': "图片下载失败"
|
||||
# }
|
||||
else:
|
||||
return {
|
||||
'success': False,
|
||||
|
||||
Reference in New Issue
Block a user