From ad61f61664e0c3e713b9252b72b64946d0e7f56f Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 22 Apr 2025 16:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4wcf=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/server.py | 40 ++++++++++++++++------------ gewechat/client/fetchContactsList.py | 8 +++--- plugins/beautyleg/main.py | 3 --- plugins/message_summary/main.py | 18 ++++--------- plugins/plugin_manager/main.py | 2 -- utils/decorator/points_decorator.py | 24 +++++++---------- utils/wechat/message_to_db.py | 2 +- 7 files changed, 44 insertions(+), 53 deletions(-) diff --git a/admin/dashboard/server.py b/admin/dashboard/server.py index 6eb767a..5d6144b 100644 --- a/admin/dashboard/server.py +++ b/admin/dashboard/server.py @@ -8,6 +8,9 @@ import sys import threading import time from datetime import datetime + +from gewechat_client import GewechatClient + from db.message_storage import MessageStorageDB from db.stats_db import StatsDBOperator from flask import Flask, send_from_directory @@ -44,8 +47,8 @@ class DashboardServer: self.contact_manager = robot_instance.contact_manager self.plugin_manager = robot_instance.plugin_manager self.plugin_registry = robot_instance.plugin_registry - # 获取WCF实例 - self.wcf = robot_instance.wcf + self.client:GewechatClient= robot_instance.client + self.app_id = robot_instance.app_id self.logger.info("使用Robot实例的对象进行初始化") else: self.logger.error("未提供Robot实例,Dashboard无法正常工作") @@ -173,27 +176,30 @@ class DashboardServer: def get_current_user_info(self): """获取当前登录的微信用户信息""" try: - if not self.wcf: - self.logger.error("WCF实例不可用,无法获取当前用户信息") - return {"success": False, "message": "WCF实例不可用"} + if not self.client: + self.logger.error("client实例不可用,无法获取当前用户信息") + return {"success": False, "message": "实例不可用"} # 获取当前登录的微信ID - wx_id = self.self.message_util.get_self_wxid() - if not wx_id: - return {"success": False, "message": "未获取到微信ID"} - - # 获取用户详细信息 - user_info = self.self.message_util.get_user_info() - self.logger.info(f"获取用户信息:{user_info}") + resp = self.client.get_profile(self.app_id) + + if not resp or resp.get("ret") != 200: + self.logger.error(f"获取用户信息失败: {resp}") + return {"success": False, "message": "获取用户信息失败"} + + # 从新的resp格式中获取用户信息 + user_data = resp.get("data", {}) + if not user_data: + return {"success": False, "message": "未获取到用户数据"} return { "success": True, "data": { - "wx_id": user_info.get("wxid", wx_id), - "nickname": user_info.get("name", "未知用户"), - "avatar": "logo.png", # 使用默认LOGO - "mobile": user_info.get("mobile", ""), - "home": user_info.get("home", "") + "wx_id": user_data.get("wxid", ""), + "nickname": user_data.get("nickName", "未知用户"), + "avatar": user_data.get("smallHeadImgUrl", "logo.png"), # 使用小头像URL + "mobile": user_data.get("mobile", ""), + "home": f"{user_data.get('province', '')}-{user_data.get('city', '')}" # 组合省市信息 } } except Exception as e: diff --git a/gewechat/client/fetchContactsList.py b/gewechat/client/fetchContactsList.py index 1ab6dc9..5030c6c 100644 --- a/gewechat/client/fetchContactsList.py +++ b/gewechat/client/fetchContactsList.py @@ -1,11 +1,11 @@ import requests import json -url = "/contacts/fetchContactsList" +url = "/login/deviceList" base_url="http://192.168.2.240:2531/v2/api" payload = json.dumps({ - "appId": "wx_3BC6eSHGE5xEm_hH3__7c" + }) headers = { @@ -15,4 +15,6 @@ headers = { response = requests.request("POST", base_url+url, headers=headers, data=payload) -print(response.text) \ No newline at end of file +print(response.text) + + diff --git a/plugins/beautyleg/main.py b/plugins/beautyleg/main.py index 786ab76..40ab45c 100644 --- a/plugins/beautyleg/main.py +++ b/plugins/beautyleg/main.py @@ -3,7 +3,6 @@ import os import random from typing import Dict, Any, List, Optional, Tuple -from wcferry import Wcf from message_util import MessageUtil from plugin_common.message_plugin_interface import MessagePluginInterface @@ -52,7 +51,6 @@ class BeautyLegPlugin(MessagePluginInterface): self.LOG.info(f"正在初始化 {self.name} 插件...") # 保存上下文对象 - self.wcf = context.get("wcf") self.event_system = context.get("event_system") self.message_util: MessageUtil = context.get("message_util") self.gbm = context.get("gbm") @@ -99,7 +97,6 @@ class BeautyLegPlugin(MessagePluginInterface): self.LOG.info(f"插件执行: {self.name}:{content}") sender = message.get("sender") roomid = message.get("roomid", "") - wcf: Wcf = message.get("wcf") gbm: GroupBotManager = message.get("gbm") # 检查权限 diff --git a/plugins/message_summary/main.py b/plugins/message_summary/main.py index 3119881..cb95a80 100644 --- a/plugins/message_summary/main.py +++ b/plugins/message_summary/main.py @@ -133,21 +133,13 @@ class MessageSummaryPlugin(MessagePluginInterface): # 生成总结 summary, image_path = self._generate_summary(chat_content, group_name) - # 发送总结结果 - wcf = message.get("wcf") - if wcf: - # if summary: - # self.message_util.send_text(f"总结已生成:\n{summary}", group_id, message.get("sender")) - - if image_path: - self.message_util.send_file(image_path, group_id) - else: - self.message_util.send_text("❌ 生成总结图片失败", group_id) + if image_path: + self.message_util.send_file(image_path, group_id) + else: + self.message_util.send_text("❌ 生成总结图片失败", group_id) except Exception as e: self.LOG.error(f"异步生成总结失败: {e}") - wcf = message.get("wcf") - if wcf: - self.message_util.send_text(f"❌ 生成总结失败: {str(e)}", group_id) + self.message_util.send_text(f"❌ 生成总结失败: {str(e)}", group_id) def _sanitize_group_name(self, group_name: str) -> str: """处理群名,去除特殊字符并限制长度""" diff --git a/plugins/plugin_manager/main.py b/plugins/plugin_manager/main.py index 206fd97..9aafe6d 100644 --- a/plugins/plugin_manager/main.py +++ b/plugins/plugin_manager/main.py @@ -57,7 +57,6 @@ class PluginManagerPlugin(MessagePluginInterface): self.LOG.info(f"正在初始化 {self.name} 插件...") # 保存上下文对象 - self.wcf = context.get("wcf") self.event_system = context.get("event_system") self.message_util = context.get("message_util") @@ -87,7 +86,6 @@ class PluginManagerPlugin(MessagePluginInterface): sender = message.get("sender") roomid = message.get("roomid", "") - wcf = message.get("wcf") gbm = message.get("gbm") target = roomid if roomid else sender diff --git a/utils/decorator/points_decorator.py b/utils/decorator/points_decorator.py index 8b88709..2c8d731 100644 --- a/utils/decorator/points_decorator.py +++ b/utils/decorator/points_decorator.py @@ -141,14 +141,12 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature = user_points = points_db.get_user_points(sender, roomid) if user_points["total_points"] < points: # 积分不足 - wcf = message.get("wcf") - if wcf: - self.message_util.send_text( - f"❌ 积分不足\n无法使用 {plugin_name} 功能\n" - f"🪙 先参与积分活动[签到,答题/t]赚取吧!\n" - f"💰 有: {user_points['total_points']} | 需: {points} |差: {points - user_points['total_points']} ", - (roomid if roomid else sender), sender - ) + self.message_util.send_text( + f"❌ 积分不足\n无法使用 {plugin_name} 功能\n" + f"🪙 先参与积分活动[签到,答题/t]赚取吧!\n" + f"💰 有: {user_points['total_points']} | 需: {points} |差: {points - user_points['total_points']} ", + (roomid if roomid else sender), sender + ) logger.info(f"用户 {sender} 积分不足,无法使用功能") return False, "积分不足" @@ -168,12 +166,10 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature = # 添加对 response 的类型检查 if isinstance(response, str) and "积分" not in response: response += f"\n\n💰 已消费 {points} 积分" - wcf = message.get("wcf") - if wcf: - self.message_util.send_text( - f"💰消费 {points} 积分", - (roomid if roomid else sender), sender - ) + self.message_util.send_text( + f"💰消费 {points} 积分", + (roomid if roomid else sender), sender + ) else: logger.warning(f"用户 {sender} 积分扣除失败: {deduct_result}") diff --git a/utils/wechat/message_to_db.py b/utils/wechat/message_to_db.py index bd067c1..beb18b5 100644 --- a/utils/wechat/message_to_db.py +++ b/utils/wechat/message_to_db.py @@ -98,7 +98,7 @@ class MessageStorage: def process_image(self, msg: WxMessage): """异步处理图片消息,与消息存档分离""" - if msg.msg_type != 3 or not self.client: # 不是图片消息或没有WCF实例 + if msg.msg_type != 3 or not self.client: # 不是图片消息或没有client实例 return False # 提交任务到图片处理线程池