-
Notifications
You must be signed in to change notification settings - Fork 182
/
UI.py
231 lines (205 loc) · 7.92 KB
/
UI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
from PyQt5.QtWidgets import (
QApplication,
QWidget,
QHBoxLayout,
QVBoxLayout,
QDesktopWidget,
QPushButton,
QLabel,
QTabWidget,
QMenu, QAction, QTextEdit, QFileDialog, QListWidget, QListWidgetItem, QCheckBox)
from PyQt5.QtGui import QPixmap, QCursor
from PyQt5.QtCore import QSize, QThread, pyqtSignal, Qt, QPoint
from PyWeChatSpy import WeChatSpy
from lxml import etree
import requests
import sys
from queue import Queue
from time import sleep
from threading import Thread
import os
import re
FRIEND_LIST = []
GROUP_LIST = []
OFFICE_LIST = []
cb_contact_list = []
contact_need_details = []
current_row = 0
msg_queue = Queue()
wxid_contact = {}
contact_filter = ("qmessage", "qqmail", "tmessage", "medianote", "floatbottle", "fmessage")
key = "18d421169d93611a5584affac335e690"
if os.path.exists("key"):
with open("key", "r") as rf:
key = rf.read()
def parser(data: dict):
msg_queue.put(data)
class MsgThread(QThread):
signal = pyqtSignal(dict)
def __init__(self):
super().__init__()
def run(self):
while True:
if not msg_queue.empty():
msg = msg_queue.get()
self.signal.emit(msg)
else:
sleep(0.1)
def download_image(url: str, output: str):
resp = requests.get(url)
if resp.status_code == 200:
with open(output, "wb") as wf:
wf.write(resp.content)
return True
return False
class ContactWidget(QWidget):
def __init__(self, contact: dict, select_changed: classmethod):
super().__init__()
layout = QHBoxLayout(self)
checkbox_contact = QCheckBox()
checkbox_contact.__setattr__("wxid", contact["wxid"])
checkbox_contact.setFixedSize(20, 20)
checkbox_contact.stateChanged[int].connect(select_changed)
cb_contact_list.append(checkbox_contact)
layout.addWidget(checkbox_contact)
label_profilephoto = QLabel(self)
label_profilephoto.setFixedSize(32, 32)
profilephoto_path = "profilephotos/default.jpg"
if os.path.exists(f"profilephotos/{contact['wxid']}.jpg"):
profilephoto_path = f"profilephotos/{contact['wxid']}.jpg"
default_profilephoto = QPixmap(profilephoto_path).scaled(32, 32)
label_profilephoto.setPixmap(default_profilephoto)
layout.addWidget(label_profilephoto)
label_nickname = QLabel(self)
nickname = contact["nickname"]
if remark := contact.get("remark"):
nickname = f"{nickname}({remark})"
if count := contact.get("member_count"):
nickname = f"{nickname}[{count}]"
label_nickname.setText(nickname)
layout.addWidget(label_nickname)
class ContactSearchWidget(QWidget):
def __init__(self, contact: dict):
super().__init__()
layout = QHBoxLayout(self)
label_profilephoto = QLabel(self)
label_profilephoto.setFixedSize(32, 32)
profilephoto_path = "profilephotos/default.jpg"
if os.path.exists(f"profilephotos/{contact['wxid']}.jpg"):
profilephoto_path = f"profilephotos/{contact['wxid']}.jpg"
default_profilephoto = QPixmap(profilephoto_path).scaled(32, 32)
label_profilephoto.setPixmap(default_profilephoto)
layout.addWidget(label_profilephoto)
label_nickname = QLabel(self)
nickname = contact["nickname"]
if remark := contact.get("remark"):
nickname = f"{nickname}({remark})"
if count := contact.get("member_count"):
nickname = f"{nickname}[{count}]"
label_nickname.setText(nickname)
layout.addWidget(label_nickname)
class MessageWidget(QWidget):
def __init__(self, message: dict):
super().__init__()
layout_main = QHBoxLayout(self)
layout_side = QVBoxLayout(self)
label_content = QLabel(self)
label_content.setWordWrap(True)
label_content.adjustSize()
label_content.setFixedWidth(300)
label_speaker = QLabel(self)
if message["self"]:
layout_main.setAlignment(Qt.AlignRight)
label_content.setAlignment(Qt.AlignRight)
label_speaker.setAlignment(Qt.AlignRight)
else:
layout_main.setAlignment(Qt.AlignLeft)
label_content.setAlignment(Qt.AlignLeft)
label_speaker.setAlignment(Qt.AlignLeft)
label_profilephoto = QLabel(self)
label_profilephoto.setFixedSize(32, 32)
profilephoto_path = "profilephotos/default.jpg"
if os.path.exists(f"profilephotos/{message['wxid1']}.jpg"):
profilephoto_path = f"profilephotos/{message['wxid1']}.jpg"
default_profilephoto = QPixmap(profilephoto_path).scaled(32, 32)
label_profilephoto.setPixmap(default_profilephoto)
speaker = ""
wxid1 = message["wxid1"]
if contact := wxid_contact.get(wxid1):
speaker = contact["nickname"]
if remark := contact.get("remark"):
speaker = f"{speaker}({remark})"
label_speaker.setText(speaker)
layout_side.addWidget(label_speaker)
if message["msg_type"] == 1:
label_content.setText(message["content"])
elif message["msg_type"] == 3:
label_content.setText("图片消息,请在手机上查看")
elif message["msg_type"] == 43:
if message.get("content"):
label_content.setText("不支持的消息类型,请在手机上查看")
else:
label_content.setText("视频消息,请在手机上查看")
elif message["msg_type"] == 47:
label_content.setText("表情包消息,请在手机上查看")
elif message["msg_type"] == 49:
label_content.setText("小程序或其他分享消息,请在手机上查看")
else:
label_content.setText("不支持的消息类型,请在手机上查看")
layout_side.addWidget(label_content)
if message["self"]:
layout_main.addLayout(layout_side)
layout_main.addWidget(label_profilephoto)
else:
layout_main.addWidget(label_profilephoto)
layout_main.addLayout(layout_side)
class SettingWidget(QWidget):
def __init__(self, parent):
super().__init__()
self.setWindowTitle("设置")
self.parent = parent
self.tab_widget = QTabWidget(self)
self.tab_widget.setTabPosition(QTabWidget.West)
self.tab_widget.setFixedSize(300, 200)
self.tab_common = QListWidget(self)
self.tab_widget.addTab(self.tab_common, "通用")
item = QListWidgetItem()
item.setSizeHint(QSize(200, 50))
self.cb_auto_accept = QCheckBox("自动通过好友请求")
self.tab_common.addItem(item)
self.tab_common.setItemWidget(item, self.cb_auto_accept)
class SendTextEdit(QTextEdit):
def __init__(self, parent):
super().__init__()
self.parent = parent
def keyPressEvent(self, event):
QTextEdit.keyPressEvent(self, event)
if event.key() == Qt.Key_Return:
if QApplication.keyboardModifiers() == Qt.ControlModifier:
self.append("")
else:
self.parent.send_msg()
class SpyUI(QWidget):
def __init__(self):
super().__init__()
self.layout_main = QHBoxLayout(self)
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.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
spy = SpyUI()
sys.exit(app.exec_())