Ejemplo n.º 1
0
 def __init__(self):
     super().__init__()
     self.spy = WeChatSpy(parser=parser, key=key)
     self.layout_main = QHBoxLayout(self)
     self.layout_left = QVBoxLayout(self)
     self.layout_middle = QVBoxLayout(self)
     self.layout_right = QVBoxLayout(self)
     self.layout_main.addLayout(self.layout_left)
     self.layout_main.addLayout(self.layout_middle)
     self.layout_main.addLayout(self.layout_right)
     self.label_profilephoto = QLabel(self)
     self.TE_contact_search = QTextEdit(self)
     self.LW_contact_search = QListWidget(self)
     self.TW_contact = QTabWidget(self)
     self.tab_friend = QListWidget()
     self.tab_group = QListWidget()
     self.tab_office = QListWidget()
     self.LW_chat_record = QListWidget(self)
     self.TE_send = SendTextEdit(self)
     self.CB_select_all_contact = QCheckBox("全选")
     self.CB_select_all_contact.setCheckState(Qt.Unchecked)
     self.setting_widget = SettingWidget(self)
     self.wxid = ""
     self.init_ui()
def init(sub_service_context: SubServiceContext) -> bool:
    try:
        if os.path.isdir(PATCH_PATH):
            shutil.rmtree(PATCH_PATH)
        if not os.path.exists(PATCH_PATH):
            with open(PATCH_PATH, "a") as wf:
                wf.write("")

        global subServiceContext
        subServiceContext = sub_service_context

        global wechatSpy
        wechatSpy = WeChatSpy(response_queue=wechatQueue,
                              key=None,
                              logger=None)
    except Exception as e:
        print('Plugin-in init error: ' + str(e))
        print(traceback.format_exc())
        return False
    finally:
        pass
    return True
Ejemplo n.º 3
0
            print(details.source)
    elif data.type == HEART_BEAT:
        # 心跳
        pass
    elif data.type == SET_REMARK:
        print("-" * 10, "备注设置完成", "-" * 10)
        print(data)
    elif data.type == CONTACT_STATUS:
        print("-" * 10, "联系人状态", "-" * 10)
        print(data)
    elif data.type == GET_CHATROOM_INVITATION_URL:
        print("-" * 10, "群邀请链接", "-" * 10)
        for message in data.message_list.message:
            if message.type == 321:
                url = message.content
                try:
                    requests.post(url, allow_redirects=False)
                except requests.exceptions.InvalidSchema:
                    pass
                except Exception as e:
                    #: TODO 网络异常处理
                    print(e)


if __name__ == '__main__':
    spy = WeChatSpy(parser=my_proto_parser,
                    key="18d421169d93611a5584affac335e690",
                    logger=logger)
    spy.run(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    input()
Ejemplo n.º 4
0
from PyWeChatSpy import WeChatSpy
from PyWeChatSpy.command import *
from PyWeChatSpy.proto import spy_pb2
import random
import re


def my_parser(data):
    if data.type == CHAT_MESSAGE:  # 判断是微信消息数据
        chat_message = spy_pb2.ChatMessage()
        chat_message.ParseFromString(data.bytes)
        for message in chat_message.message:  # 遍历微信消息
            _type = message.type  # 消息类型 1.文本|3.图片...自行探索
            _from = message.wxidFrom.str  # 消息发送方
            _to = message.wxidTo.str  # 消息接收方
            content = message.content.str  # 消息内容
            print(_type, _from, _to, content)
            if _type == 10000:  # 判断是微信拍一拍系统提示
                # 因为微信系统消息很多 因此需要用正则匹配消息内容进一步过滤拍一拍提示
                m = re.search('".*" 拍了拍你', content)
                if m:  # 搜索到了匹配的字符串 判断为拍一拍
                    image_path = f"images/{random.randint(1, 7)}.jpg"  # 随机选一张回复用的图片
                    spy.send_file(_from, image_path)  # 发送图片


if __name__ == '__main__':
    spy = WeChatSpy(parser=my_parser)
    spy.run(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    input()
Ejemplo n.º 5
0
    if data['type'] == 4:
        pass

    # 微信消息
    if data['type'] == 5:
        for item in data[
                'data']:  #{"self":0,"msg_type":1,"wxid1":"","wxid2":"","head":"","content":""}
            if item['self'] == 0:  #消息由他人发出
                if item['wxid2'] is None and item[
                        'msg_type'] == 1:  # 消息来源是联系人好友,且消息类型是文本
                    who = item['wxid1']
                    what = get_reply(item['content'])
                    # wcp.send_text(who,what)
            if item['self'] == 1:  #消息由当前登录账号发出
                pass

    # 联系人最新信息
    if data['type'] == 6:
        pass

    # 联系人状态
    if data['type'] == 7:
        print("联系人状态")

    if data['type'] == 8:
        pass


wcp = WeChatSpy(parser=my_parser)
wcp.run()
Ejemplo n.º 6
0
from threading import Thread
import os
import re
from PyWeChatSpy import WeChatSpy
import qdarkstyle
from PyWeChatSpy.proto.spy_pb2 import Response, AccountDetails, Contacts
from PyWeChatSpy.command import WECHAT_CONNECTED, WECHAT_LOGIN, WECHAT_LOGOUT, ACCOUNT_DETAILS, CONTACTS_LIST


my_response_queue = Queue()
key = None
if os.path.exists("key.txt"):
    with open("key.txt", "r") as rf:
        key = rf.read()
print("key:", key)
spy = WeChatSpy(response_queue=my_response_queue, key=key)
contact_filter = ("qmessage", "qqmail", "tmessage", "medianote", "floatbottle", "fmessage")
root_dir = os.path.dirname(__file__)
profile_photo_dir = os.path.join(root_dir, "profilephotos")


class MsgThread(QThread):
    signal = pyqtSignal(Response)

    def __init__(self):
        super().__init__()

    def run(self):
        while True:
            msg = my_response_queue.get()
            self.signal.emit(msg)
Ejemplo n.º 7
0
            # 高风险操作 频率较高容易引发微信风控
            # spy.add_contact(
            #     member.wxid,
            #     chatroom_wxid,
            #     "来自PyWeChatSpy(https://zhuanlan.zhihu.com/p/118674498)的问候",
            #     ADD_CONTACT_A)
    elif data.type == CONTACT_DETAILS:
        print("-" * 10, "联系人详情", "-" * 10)
        for details in data.contact_list.contact:
            print(details.wxid)
            print(details.nickname)
            print(details.wechatid)
            print(details.remark)
            print(details.profilephoto)
            print(details.profilephoto_hd)
            print(details.sex)
            print(details.whats_up)
            print(details.country)
            print(details.province)
            print(details.city)
            print(details.source)
    elif data.type == HEART_BEAT:
        # 心跳
        pass


spy = WeChatSpy(parser=my_proto_parser, key="授权Key", logger=logger)

if __name__ == '__main__':
    spy.run()
Ejemplo n.º 8
0
from PyWeChatSpy import WeChatSpy
import threading


def parser(data):
    # 微信信息
    if data.get("type") == 1:
        length = len(threading.enumerate())  # 枚举返回个列表
        print("线程数量:", length)
        print(data)
        spy.send_text(data.get('wx_ID'), "python server已接收到消息!")
        # spy.query_personal_info()  # 获取用户个人信息

    # 用户个人信息
    elif data.get("type") == 2:
        print(data)


if __name__ == '__main__':
    spy = WeChatSpy(parser=parser)
    spy.run()
Ejemplo n.º 9
0
            group_member_details.ParseFromString(data.bytes)
            # print(group_member_details)
        elif data.type == GROUP_MEMBER_EVENT:  # 群成员进出事件
            group_member_event = spy_pb2.GroupMemberEvent()
            group_member_event.ParseFromString(data.bytes)
            # print(group_member_event)
        elif data.type == LOGIN_QRCODE:  # 登录二维码
            qrcode = spy_pb2.LoginQRCode()
            qrcode.ParseFromString(data.bytes)
            with open("qrcode.png", "wb") as _wf:
                _wf.write(qrcode.qrcodeBytes)
        elif data.type == GROUP_ENTER_URL:  # 进群链接
            group_enter_url = spy_pb2.GroupEnterUrl()
            group_enter_url.ParseFromString(data.bytes)
            print(group_enter_url)
            # 进群直接post请求链接
            # try:
            #     requests.post(group_enter_url.url)
            # except requests.exceptions.InvalidSchema:
            #     pass
            # except Exception as e:
            #     logger.error(f"进群失败:{e}")
        else:
            print(data)


if __name__ == '__main__':
    spy = WeChatSpy(response_queue=my_response_queue, key="", logger=logger)
    pid = spy.run(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    handle_response()
Ejemplo n.º 10
0
                file_name = "{}.jpg".format(uuid4().__str__().replace("-", ""))
                with open(os.path.join("images", file_name), "wb") as wf:
                    wf.write(base64.b64decode(message.content))
                post_data = {
                    "type": 3,
                    "wxid1": message.wxid1,
                    "wxid2": message.wxid2,
                    "content": file_name,
                    "self": message.self,
                    "wechatid": port2wechatid.get(data.port)
                }
                requests.post(f"{SYNC_HOST}?mod=wxrobot", json=post_data)


app = Flask(__name__)
spy = WeChatSpy(parser=parser)


@app.route("/sendMessage", methods=["POST"])
def send_message():
    if not (message_type := request.json.get("type")):
        return jsonify({"success": 0, "msg": "未找到参数type"})
    elif not (wechatid := request.json.get("wechatid")):
        return jsonify({"success": 0, "msg": "未找到参数wechatid"})
    if not (port := wechatid2port.get(wechatid)):
        return jsonify({"success": 0, "msg": f"根据微信号{wechatid}未找到对应port"})
    if message_type == 1:
        if not (wxid1 := request.json.get("wxid1")):
            return jsonify({"success": 0, "msg": "未找到参数wxid1"})
        elif not (content := request.json.get("content")):
            return jsonify({"success": 0, "msg": "未找到参数content"})
Ejemplo n.º 11
0
class SpyUI(QWidget):
    def __init__(self):
        super().__init__()
        self.spy = WeChatSpy(parser=parser, key=key)
        self.layout_main = QHBoxLayout(self)
        self.layout_left = QVBoxLayout(self)
        self.layout_middle = QVBoxLayout(self)
        self.layout_right = QVBoxLayout(self)
        self.layout_main.addLayout(self.layout_left)
        self.layout_main.addLayout(self.layout_middle)
        self.layout_main.addLayout(self.layout_right)
        self.label_profilephoto = QLabel(self)
        self.TE_contact_search = QTextEdit(self)
        self.LW_contact_search = QListWidget(self)
        self.TW_contact = QTabWidget(self)
        self.tab_friend = QListWidget()
        self.tab_group = QListWidget()
        self.tab_office = QListWidget()
        self.LW_chat_record = QListWidget(self)
        self.TE_send = SendTextEdit(self)
        self.CB_select_all_contact = QCheckBox("全选")
        self.CB_select_all_contact.setCheckState(Qt.Unchecked)
        self.setting_widget = SettingWidget(self)
        self.wxid = ""
        self.init_ui()

    def init_ui(self):
        fg = self.frameGeometry()
        center = QDesktopWidget().availableGeometry().center()
        fg.moveCenter(center)
        # 设置窗体
        self.setting_widget.resize(300, 200)
        self.setting_widget.move(fg.topLeft())
        self.setting_widget.hide()
        # 主窗体
        self.resize(858, 608)
        self.move(fg.topLeft())
        self.setWindowTitle("PyWeChatSpyUI Beta 1.3.3")
        # 设置登录信息头像
        self.label_profilephoto.setFixedSize(32, 32)
        default_profilephoto = QPixmap("profilephotos/default.jpg").scaled(
            32, 32)
        self.label_profilephoto.setPixmap(default_profilephoto)
        self.layout_left.addWidget(self.label_profilephoto)
        button_open_wechat = QPushButton(self)
        button_open_wechat.setText("打开\n微信")
        button_open_wechat.clicked.connect(
            lambda: self.spy.run(background=True))
        button_open_wechat.setFixedSize(32, 32)
        button_settings = QPushButton(self)
        button_settings.setText("设置")
        button_settings.setFixedSize(32, 32)
        button_settings.clicked.connect(self.setting_widget.show)
        self.layout_left.addWidget(button_open_wechat)
        self.layout_left.addWidget(button_settings)
        # 联系人列表
        self.TW_contact.currentChanged["int"].connect(self.tab_changed)
        self.TW_contact.addTab(self.tab_friend, "好友")
        self.TW_contact.addTab(self.tab_group, "群聊")
        self.TW_contact.addTab(self.tab_office, "公众号")
        self.tab_friend.itemClicked.connect(self.contact_clicked)
        self.tab_group.itemClicked.connect(self.contact_clicked)
        self.tab_office.itemClicked.connect(self.contact_clicked)
        self.TE_contact_search.setFixedSize(250, 24)
        self.TE_contact_search.textChanged.connect(self.search_contact)
        self.TE_contact_search.setPlaceholderText("搜索")
        self.LW_contact_search.setFixedSize(250, 200)
        self.LW_contact_search.itemClicked.connect(self.contact_search_clicked)
        self.layout_middle.addWidget(self.TE_contact_search)
        self.CB_select_all_contact.stateChanged[int].connect(
            self.contact_select_all)
        self.layout_middle.addWidget(self.CB_select_all_contact)
        self.layout_middle.addWidget(self.TW_contact)
        # 聊天区域
        self.LW_chat_record.setFixedSize(468, 400)
        self.LW_chat_record.setContextMenuPolicy(3)
        self.LW_chat_record.customContextMenuRequested[QPoint].connect(
            self.rightMenuShow)
        self.layout_right.addWidget(self.LW_chat_record)
        layout = QHBoxLayout(self)
        button_file = QPushButton(self)
        button_file.setText("添加文件")
        button_file.clicked.connect(self.insert_file)
        layout.addWidget(button_file)
        self.layout_right.addLayout(layout)
        self.TE_send.setFixedSize(468, 100)
        self.layout_right.addWidget(self.TE_send)
        button_send = QPushButton(self)
        button_send.setText("发送")
        button_send.clicked.connect(self.send_msg)
        self.layout_right.addWidget(button_send)
        self.setLayout(self.layout_main)
        msg_thread = MsgThread()
        msg_thread.signal.connect(self.parser)
        msg_thread.start()
        self.show()
        self.LW_contact_search.raise_()
        self.LW_contact_search.move(self.TE_contact_search.x(),
                                    self.TE_contact_search.y() + 24)
        self.LW_contact_search.hide()

    def parser(self, data: dict):
        _type = data.pop("type")
        if _type == 1:
            # 登录成功
            self.wxid = data["wxid"]
            profilephoto_path = f"profilephotos/{data['wxid']}.jpg"
            if not os.path.exists(profilephoto_path):
                if not download_image(data["profilephoto_url"],
                                      profilephoto_path):
                    profilephoto_path = "profilephotos/default.jpg"
            profilephoto = QPixmap(profilephoto_path).scaled(32, 32)
            self.label_profilephoto.setPixmap(profilephoto)
            self.spy.query_contact_list()
        elif _type == 2:
            if profilephoto_url := data.get("profilephoto_url"):
                download_image(profilephoto_url,
                               f"profilephotos/{data['wxid']}.jpg")
            if contact_need_details:
                wxid = contact_need_details.pop()
                self.spy.query_contact_details(wxid)
            else:
                self.refresh_contact_list()
        elif _type == 3:
            for contact in data["data"]:
                wxid_contact[contact["wxid"]] = contact
                if contact["wxid"] not in contact_filter:
                    if not os.path.exists(
                            f"profilephotos/{contact['wxid']}.jpg"):
                        contact_need_details.append(contact["wxid"])
                    if contact["wxid"].endswith("chatroom"):
                        GROUP_LIST.append(contact)
                    elif contact["wxid"].startswith("gh_"):
                        OFFICE_LIST.append(contact)
                    else:
                        FRIEND_LIST.append(contact)
            if data["total_page"] == data["current_page"]:
                self.refresh_contact_list()
                if contact_need_details:
                    wxid = contact_need_details.pop()
                    self.spy.query_contact_details(wxid)
Ejemplo n.º 12
0
        print("-" * 10, "联系人状态", "-" * 10)
        print(data)
    elif data.type == GET_CHATROOM_INVITATION_URL:
        print("-" * 10, "群邀请链接", "-" * 10)
        for message in data.message:
            if message.type == 321:
                url = message.content
                try:
                    requests.post(url, allow_redirects=False)
                except requests.exceptions.InvalidSchema:
                    pass
                except Exception as e:
                    #: TODO 网络异常处理
                    print(e)
    elif data.type == DECRYPT_IMAGE:
        print("-" * 10, "解密后的图片", "-" * 10)
        for message in data.message:
            md5 = message.wxid1
            content = message.content
            with open(f"image_cache/{md5}.jpg", "wb") as wf:
                content = base64.b64decode(content)
                wf.write(content)


if __name__ == '__main__':
    spy = WeChatSpy(parser=my_proto_parser,
                    key="3ea954244f76a8cfb7e5f8f544cf6878",
                    logger=logger)
    subprocess.Popen(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    input()
Ejemplo n.º 13
0
        # 微信登出
        print("微信退出登录")


def my_parser_sync(data):
    if data["type"] == 100:
        qrcode = spy.show_qrcode()
        print(qrcode)
    if data["type"] == 202:
        # 微信登录
        print("微信登录")
        login_info = spy.query_login_info()
        print(login_info)
        contact_info = spy.query_contact_list()
        for contact in contact_info["data"]:
            print(contact)
            details = spy.query_contact_details(contact["wxid"])
            print(details)
            break
        print(contact_info["data"][2])
        status = spy.check_contact_status(contact_info["data"][2]["wxid"])
        print(status)


spy = WeChatSpy(parser=my_parser_sync, key="授权Key", logger=logger)  # 同步处理
# spy = WeChatSpy(parser=my_parser_async, key="授权Key", logger=logger)  # 异步处理

if __name__ == '__main__':
    spy.run(_async=False)  # 同步处理
    # spy.run()  # 异步处理
Ejemplo n.º 14
0
                if contact := contact_dict.get(wxid1):
                    print(contact)
                else:
                    spy.query_contact_details(wxid1)
                if wxid1.endswith("chatroom") and wxid2:
                    if contact := contact_dict.get(wxid2):
                        print(contact)
                    else:
                        spy.query_contact_details(wxid2, wxid1)
            elif item["msg_type"] == 37:
                # 好友请求消息
                obj = etree.XML(item["content"])
                encryptusername, ticket = obj.xpath(
                    "/msg/@encryptusername")[0], obj.xpath("/msg/@ticket")[0]
                spy.accept_new_contact(encryptusername, ticket)
    elif data["type"] == 2:
        # 联系人详情
        print(data)
    elif data["type"] == 3:
        # 联系人列表
        for contact in data["data"]:
            print(contact)
    elif data["type"] == 9527:
        spy.logger.warning(data)


if __name__ == '__main__':
    spy = WeChatSpy(parser=parser)
    spy.add_log_output_file()  # 添加日志输出文件
    spy.run()
Ejemplo n.º 15
0
            if '@小岚' in msg["content"]:
                if msg["msg_type"] == 1 and msg["self"] == 0:
                    b = msg["content"]
                    a = b.replace("@小岚\u2005", "")
                    answer = get_content(a)
                    time.sleep(1)
                    if answer == '':  # 防止返回内容为空
                        for i in range(2):
                            time.sleep(2)
                            answer = get_content(a)
                            if answer != '' and answer != "emmmm,我不是很懂你的意思":
                                break
                            else:
                                answer = "emmmm,我不是很懂你的意思"
                    spy.send_text(msg["wxid1"], answer)
            elif "#" in msg["content"]:
                if msg["msg_type"] == 1 and msg["self"] == 0:
                    b = msg["content"]
                    a = b.replace("#", "")
                    answer = get_content_cyjl(a)
                    time.sleep(1)
                    spy.send_text(msg["wxid1"], answer)
            else:
                break


spy = WeChatSpy(parser=my_parser)  # 实例化WeChatSpy类

if __name__ == '__main__':
    spy.run()  # 运行代码
Ejemplo n.º 16
0
            group_member_details.ParseFromString(data.bytes)
            # print(group_member_details)
        elif data.type == GROUP_MEMBER_EVENT:  # 群成员进出事件
            group_member_event = spy_pb2.GroupMemberEvent()
            group_member_event.ParseFromString(data.bytes)
            # print(group_member_event)
        elif data.type == LOGIN_QRCODE:  # 登录二维码
            qrcode = spy_pb2.LoginQRCode()
            qrcode.ParseFromString(data.bytes)
            with open("qrcode.png", "wb") as _wf:
                _wf.write(qrcode.qrcodeBytes)
        elif data.type == GROUP_ENTER_URL:  # 进群链接
            group_enter_url = spy_pb2.GroupEnterUrl()
            group_enter_url.ParseFromString(data.bytes)
            print(group_enter_url)
            # 进群直接post请求链接
            # try:
            #     requests.post(group_enter_url.url)
            # except requests.exceptions.InvalidSchema:
            #     pass
            # except Exception as e:
            #     logger.error(f"进群失败:{e}")
        else:
            print(data)


if __name__ == '__main__':
    spy = WeChatSpy(response_queue=my_response_queue, key="7d30e1a7903a5a4de12a792ed24ae5ea", logger=logger)
    pid = spy.run(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    handle_response()
Ejemplo n.º 17
0
        print("-" * 10, "联系人状态", "-" * 10)
        print(data)
    elif data.type == GET_CHATROOM_INVITATION_URL:
        print("-" * 10, "群邀请链接", "-" * 10)
        for message in data.message:
            if message.type == 321:
                url = message.content
                try:
                    requests.post(url, allow_redirects=False)
                except requests.exceptions.InvalidSchema:
                    pass
                except Exception as e:
                    #: TODO 网络异常处理
                    print(e)
    elif data.type == DECRYPT_IMAGE:
        print("-" * 10, "解密后的图片", "-" * 10)
        for message in data.message:
            md5 = message.wxid1
            content = message.content
            with open(f"image_cache/{md5}.jpg", "wb") as wf:
                content = base64.b64decode(content)
                wf.write(content)


if __name__ == '__main__':
    spy = WeChatSpy(parser=my_proto_parser,
                    key="3ea954244f76a8cfb7e5f8f544cf6878",
                    logger=logger)
    spy.run(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    input()
Ejemplo n.º 18
0
groups = []
USER = "******"
WECHAT_PROFILE = rf"C:\Users\{USER}\Documents\WeChat Files"
PATCH_PATH = rf"C:\Users\{USER}\AppData\Roaming\Tencent\WeChat\patch"
if not os.path.exists(WECHAT_PROFILE):
    logger.error("请先设置计算机用户名,并完善WECHAT_PROFILE和PATCH_PATH")
    exit()
if os.path.isdir(PATCH_PATH):
    shutil.rmtree(PATCH_PATH)
if not os.path.exists(PATCH_PATH):
    with open(PATCH_PATH, "a") as wf:
        wf.write("")
my_response_queue = Queue()
spy = WeChatSpy(response_queue=my_response_queue,
                key="ab28d8c4768ab3bc2ba86841313f6e32",
                logger=logger)
tod = TruthOrDare(spy)


def pop_response():
    while True:
        data = my_response_queue.get()
        handle_response(data)


def handle_response(data):
    if data.type == PROFESSIONAL_KEY:
        if not data.code:
            logger.warning(data.message)
    elif data.type == WECHAT_CONNECTED:  # 微信接入
Ejemplo n.º 19
0
    return resp.text


def parser(data):
    if data["type"] == 1:
        # 登录信息
        print(data)
        # 查询联系人列表
        spy.query_contact_list()
    elif data["type"] == 203:
        # 微信登出
        print("微信退出登录")
    elif data["type"] == 5:
        # 消息
        for item in data["data"]:
            print(item)
    elif data["type"] == 2:
        # 联系人详情
        print(data)
    elif data["type"] == 3:
        # 联系人列表
        for contact in data["data"]:
            print(contact)
    elif data["type"] == 9527:
        spy.logger.warning(data)


if __name__ == '__main__':
    spy = WeChatSpy(parser=parser, key="18d421169d93611a5584affac335e690")
    spy.run()
Ejemplo n.º 20
0
            # spy.add_contact(
            #     member.wxid,
            #     chatroom_wxid,
            #     "来自PyWeChatSpy(https://zhuanlan.zhihu.com/p/118674498)的问候",
            #     ADD_CONTACT_A)
    elif data.type == CONTACT_DETAILS:
        print("-"*10, "联系人详情", "-"*10)
        for details in data.contact_list.contact:
            print(details.wxid)
            print(details.nickname)
            print(details.wechatid)
            print(details.remark)
            print(details.profilephoto)
            print(details.profilephoto_hd)
            print(details.sex)
            print(details.whats_up)
            print(details.country)
            print(details.province)
            print(details.city)
            print(details.source)
    elif data.type == HEART_BEAT:
        # 心跳
        pass


spy = WeChatSpy(parser=my_proto_parser, key="18d421169d93611a5584affac335e690", logger=logger)


if __name__ == '__main__':
    spy.run()
Ejemplo n.º 21
0
                            member_wxid = group_member.wxid
                            member_nickname = group_member.nickname
                            print(member_wxid, member_nickname)
                        pass
            else:
                logger.error(data.message)
        elif data.type == GET_CONTACTS_LIST and not data.code:
            logger.error(data.message)
        elif data.type == CREATE_GROUP_CALLBACK:  # 创建群聊回调
            callback = spy_pb2.CreateGroupCallback()
            callback.ParseFromString(data.bytes)
            print(callback)
        elif data.type == GROUP_MEMBER_DETAILS:  # 群成员详情
            group_member_details = spy_pb2.GroupMemberDetails()
            group_member_details.ParseFromString(data.bytes)
            print(group_member_details)
        elif data.type == GROUP_MEMBER_EVENT:
            group_member_event = spy_pb2.GroupMemberEvent()
            group_member_event.ParseFromString(data.bytes)
            print(group_member_event)
        else:
            print(data)


if __name__ == '__main__':
    spy = WeChatSpy(response_queue=my_response_queue,
                    key="18d421169d93611a5584affac335e690",
                    logger=logger)
    pid = spy.run(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    handle_response()
Ejemplo n.º 22
0
import re
from queue import Queue

my_response_queue = Queue()


def parse():
    while True:
        data = my_response_queue.get()
        if data.type == CHAT_MESSAGE:  # 判断是微信消息数据
            chat_message = spy_pb2.ChatMessage()
            chat_message.ParseFromString(data.bytes)
            for message in chat_message.message:  # 遍历微信消息
                _type = message.type  # 消息类型 1.文本|3.图片...自行探索
                _from = message.wxidFrom.str  # 消息发送方
                _to = message.wxidTo.str  # 消息接收方
                content = message.content.str  # 消息内容
                print(_type, _from, _to, content)
                if _type == 10000:  # 判断是微信拍一拍系统提示
                    # 因为微信系统消息很多 因此需要用正则匹配消息内容进一步过滤拍一拍提示
                    m = re.search('".*" 拍了拍我', content)
                    if m:  # 搜索到了匹配的字符串 判断为拍一拍
                        image_path = f"images/{random.randint(1, 7)}.jpg"  # 随机选一张回复用的图片
                        spy.send_file(_from, image_path)  # 发送图片


if __name__ == '__main__':
    spy = WeChatSpy(response_queue=my_response_queue)
    spy.run(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe")
    parse()