mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-22 19:02:17 +08:00
去除parseBytes中的字段名称,返回结果更简洁;把对protobuf的依赖去除
This commit is contained in:
parent
90037f8cb5
commit
ca491c3b3a
@ -41,7 +41,7 @@ class tencent_struct:
|
|||||||
def __readString(self):
|
def __readString(self):
|
||||||
try:
|
try:
|
||||||
length = self.__readUleb()
|
length = self.__readUleb()
|
||||||
res = self.__data[self.__off: self.__off + length]
|
res = self.__data[self.__off : self.__off + length]
|
||||||
self.__add(length)
|
self.__add(length)
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
@ -78,12 +78,36 @@ class tencent_struct:
|
|||||||
def __readData(self):
|
def __readData(self):
|
||||||
try:
|
try:
|
||||||
length = self.__readUleb()
|
length = self.__readUleb()
|
||||||
data = self.__data[self.__off: self.__off + length]
|
data = self.__data[self.__off : self.__off + length]
|
||||||
self.__add(length)
|
self.__add(length)
|
||||||
return data
|
return data
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def __readChar(self):
|
||||||
|
c = None
|
||||||
|
try:
|
||||||
|
c = self.__data[self.__off]
|
||||||
|
self.__add()
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
return c
|
||||||
|
|
||||||
|
def __readUlong(self):
|
||||||
|
i = 0
|
||||||
|
j = 0
|
||||||
|
l = 0
|
||||||
|
while True:
|
||||||
|
assert i < 64
|
||||||
|
try:
|
||||||
|
j = self.__readChar()
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
l = l | (j & 0x7F) << i
|
||||||
|
if (j & 0x80) == 0:
|
||||||
|
return l
|
||||||
|
i = i + 7
|
||||||
|
|
||||||
def __init__(self, data=None, off=0):
|
def __init__(self, data=None, off=0):
|
||||||
self.__data = data
|
self.__data = data
|
||||||
self.__off = off
|
self.__off = off
|
||||||
@ -111,10 +135,8 @@ class tencent_struct:
|
|||||||
if key == 0:
|
if key == 0:
|
||||||
break
|
break
|
||||||
op = None
|
op = None
|
||||||
fieldName = ""
|
|
||||||
if key in current_dict:
|
if key in current_dict:
|
||||||
op = current_dict[key][1]
|
op = current_dict[key]
|
||||||
fieldName = current_dict[key][0]
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if isinstance(op, dict):
|
if isinstance(op, dict):
|
||||||
@ -122,31 +144,56 @@ class tencent_struct:
|
|||||||
res[key] = []
|
res[key] = []
|
||||||
current_struct = self.__readData()
|
current_struct = self.__readData()
|
||||||
recursion = tencent_struct(current_struct)
|
recursion = tencent_struct(current_struct)
|
||||||
res[key].append((fieldName, recursion.readStruct(op)))
|
res[key].append(recursion.readStruct(op))
|
||||||
elif op != "":
|
elif op != "":
|
||||||
res[key] = (fieldName, self.__contenttype__[op](self))
|
res[key] = self.__contenttype__[op](self)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
return res
|
return res
|
||||||
|
|
||||||
__struct1__ = {1: ("", "I"), 2: ("", "I")}
|
__bytesExtraStruct1__ = {1: "I", 2: "I"}
|
||||||
|
|
||||||
__msgInfo__ = {1: ("", "I"), 2: ("msg_info", "s")}
|
__bytesExtraMsgInfo__ = {1: "I", 2: "s"}
|
||||||
|
|
||||||
__bytesExtra__ = {
|
__bytesExtra__ = {
|
||||||
1: ("", __struct1__),
|
1: __bytesExtraStruct1__,
|
||||||
3: ("msg_info_struct", __msgInfo__),
|
3: __bytesExtraMsgInfo__,
|
||||||
}
|
}
|
||||||
|
|
||||||
__struct2__ = {1: ("", "s"), 2: ("", "s")}
|
__extraBufStruct1__ = {1: "s", 2: "s"}
|
||||||
|
|
||||||
__extraBuf__ = {
|
__extraBuf__ = {
|
||||||
1: ("", __struct2__),
|
1: __extraBufStruct1__,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_bytesExta_Content(self, data=None, off=0):
|
__chatRoomMember__ = {
|
||||||
|
1: "s",
|
||||||
|
2: "s",
|
||||||
|
3: "I",
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
field1: wxid,
|
||||||
|
field2: displayName,
|
||||||
|
field3: state
|
||||||
|
"""
|
||||||
|
|
||||||
|
__chatRoomData__ = {
|
||||||
|
1: __chatRoomMember__,
|
||||||
|
2: "I",
|
||||||
|
3: "I",
|
||||||
|
4: "I",
|
||||||
|
5: "I",
|
||||||
|
6: "L",
|
||||||
|
7: "L",
|
||||||
|
8: "L",
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
field5: roomCapacity
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_bytesExtra_Content(self, data=None, off=0):
|
||||||
self.__setVals__(data, off)
|
self.__setVals__(data, off)
|
||||||
try:
|
try:
|
||||||
return self.readStruct("__bytesExtra__")
|
return self.readStruct("__bytesExtra__")
|
||||||
@ -160,16 +207,24 @@ class tencent_struct:
|
|||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def get_chatRoomData_Content(self, data=None, off=0):
|
||||||
|
self.__setVals__(data, off)
|
||||||
|
try:
|
||||||
|
return self.readStruct("__chatRoomData__")
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
|
||||||
__contenttype__ = {
|
__contenttype__ = {
|
||||||
"s": __readString,
|
"s": __readString,
|
||||||
"I": __readUleb,
|
"I": __readUleb,
|
||||||
"P": __readData,
|
"P": __readData,
|
||||||
|
"L": __readUlong,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def parseBytes(content: bytes):
|
def parseBytesExtra(content: bytes):
|
||||||
try:
|
try:
|
||||||
bytesExtra = tencent_struct().get_bytesExta_Content(content)
|
bytesExtra = tencent_struct().get_bytesExtra_Content(content)
|
||||||
return bytesExtra
|
return bytesExtra
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -183,6 +238,30 @@ def parseExtraBuf(content: bytes):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def parseChatRoomData(content: bytes):
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
1: {
|
||||||
|
1: wxid,
|
||||||
|
2: displayName,
|
||||||
|
3: state
|
||||||
|
}, # chatRoomMember
|
||||||
|
2: int,
|
||||||
|
3: int,
|
||||||
|
4: int,
|
||||||
|
5: int, # roomCapacity
|
||||||
|
6: long,
|
||||||
|
7: long,
|
||||||
|
8: long,
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
extraBuf = tencent_struct().get_chatRoomData_Content(content)
|
||||||
|
return extraBuf
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def decodeExtraBuf(extra_buf_content: bytes):
|
def decodeExtraBuf(extra_buf_content: bytes):
|
||||||
off = 0
|
off = 0
|
||||||
types = [b"\x04", b"\x18", b"\x17", b"\x02", b"\x05"]
|
types = [b"\x04", b"\x18", b"\x17", b"\x02", b"\x05"]
|
||||||
@ -198,56 +277,56 @@ def decodeExtraBuf(extra_buf_content: bytes):
|
|||||||
"759378AD": "手机号",
|
"759378AD": "手机号",
|
||||||
"74752C06": "性别",
|
"74752C06": "性别",
|
||||||
}
|
}
|
||||||
res = {'手机号': {'18': ''}}
|
res = {"手机号": {"18": ""}}
|
||||||
while off < len(extra_buf_content):
|
while off < len(extra_buf_content):
|
||||||
length = 4 # 块头
|
length = 4 # 块头
|
||||||
trunk_head = extra_buf_content[off: off + length]
|
trunk_head = extra_buf_content[off : off + length]
|
||||||
off += length
|
off += length
|
||||||
trunk_head = binascii.hexlify(trunk_head).decode().upper()
|
trunk_head = binascii.hexlify(trunk_head).decode().upper()
|
||||||
if trunk_head in trunkName:
|
if trunk_head in trunkName:
|
||||||
trunk_head = trunkName[trunk_head]
|
trunk_head = trunkName[trunk_head]
|
||||||
res[trunk_head] = {}
|
res[trunk_head] = {}
|
||||||
char = extra_buf_content[off: off + 1]
|
char = extra_buf_content[off : off + 1]
|
||||||
off += 1
|
off += 1
|
||||||
field = binascii.hexlify(char).decode()
|
field = binascii.hexlify(char).decode()
|
||||||
if char == b"\x04": # 四个字节的int,小端序
|
if char == b"\x04": # 四个字节的int,小端序
|
||||||
length = 4
|
length = 4
|
||||||
intContent = extra_buf_content[off: off + length]
|
intContent = extra_buf_content[off : off + length]
|
||||||
off += 4
|
off += 4
|
||||||
intContent = int.from_bytes(intContent, "little")
|
intContent = int.from_bytes(intContent, "little")
|
||||||
res[trunk_head][field] = intContent
|
res[trunk_head][field] = intContent
|
||||||
elif char == b"\x18": # utf-16字符串
|
elif char == b"\x18": # utf-16字符串
|
||||||
length = 4
|
length = 4
|
||||||
lengthContent = extra_buf_content[off: off + length]
|
lengthContent = extra_buf_content[off : off + length]
|
||||||
off += 4
|
off += 4
|
||||||
lengthContent = int.from_bytes(lengthContent, "little")
|
lengthContent = int.from_bytes(lengthContent, "little")
|
||||||
strContent = extra_buf_content[off: off + lengthContent]
|
strContent = extra_buf_content[off : off + lengthContent]
|
||||||
off += lengthContent
|
off += lengthContent
|
||||||
res[trunk_head][field] = strContent.decode("utf-16").rstrip("\x00")
|
res[trunk_head][field] = strContent.decode("utf-16").rstrip("\x00")
|
||||||
elif char == b"\x17": # utf-8 protobuf
|
elif char == b"\x17": # utf-8 protobuf
|
||||||
length = 4
|
length = 4
|
||||||
lengthContent = extra_buf_content[off: off + length]
|
lengthContent = extra_buf_content[off : off + length]
|
||||||
off += 4
|
off += 4
|
||||||
lengthContent = int.from_bytes(lengthContent, "little")
|
lengthContent = int.from_bytes(lengthContent, "little")
|
||||||
strContent = extra_buf_content[off: off + lengthContent]
|
strContent = extra_buf_content[off : off + lengthContent]
|
||||||
off += lengthContent
|
off += lengthContent
|
||||||
res[trunk_head][field] = parseExtraBuf(strContent)
|
res[trunk_head][field] = parseExtraBuf(strContent)
|
||||||
elif char == b"\x02": # 一个字节的int
|
elif char == b"\x02": # 一个字节的int
|
||||||
content = extra_buf_content[off: off + 1]
|
content = extra_buf_content[off : off + 1]
|
||||||
off += 1
|
off += 1
|
||||||
res[trunk_head][field] = int.from_bytes(content, "little")
|
res[trunk_head][field] = int.from_bytes(content, "little")
|
||||||
elif char == b"\x05": # 暂时不知道有啥用,固定8个字节,先当int处理
|
elif char == b"\x05": # 暂时不知道有啥用,固定8个字节,先当int处理
|
||||||
length = 8
|
length = 8
|
||||||
content = extra_buf_content[off: off + length]
|
content = extra_buf_content[off : off + length]
|
||||||
off += length
|
off += length
|
||||||
res[trunk_head][field] = int.from_bytes(content, "little")
|
res[trunk_head][field] = int.from_bytes(content, "little")
|
||||||
# print(res)
|
# print(res)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'region': (res['国家']['18'], res['省份']['18'], res['市']['18']),
|
"region": (res["国家"]["18"], res["省份"]["18"], res["市"]["18"]),
|
||||||
'signature': res['个性签名']['18'],
|
"signature": res["个性签名"]["18"],
|
||||||
'telephone': res['手机号']['18'],
|
"telephone": res["手机号"]["18"],
|
||||||
'gender': res['性别']['04']
|
"gender": res["性别"]["04"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -337,10 +416,10 @@ class HardLink:
|
|||||||
video_db_lock.release()
|
video_db_lock.release()
|
||||||
|
|
||||||
def get_image(self, content, bytesExtra, thumb=False):
|
def get_image(self, content, bytesExtra, thumb=False):
|
||||||
bytesDict = parseBytes(bytesExtra)
|
bytesDict = parseBytesExtra(bytesExtra)
|
||||||
for msginfo in bytesDict[3]:
|
for msginfo in bytesDict[3]:
|
||||||
if msginfo[1][1][1] == (3 if thumb else 4):
|
if msginfo[1] == (3 if thumb else 4):
|
||||||
pathh = msginfo[1][2][1] # wxid\FileStorage\...
|
pathh = msginfo[2] # wxid\FileStorage\...
|
||||||
pathh = "\\".join(pathh.split("\\")[1:])
|
pathh = "\\".join(pathh.split("\\")[1:])
|
||||||
return pathh
|
return pathh
|
||||||
md5 = get_md5_from_xml(content)
|
md5 = get_md5_from_xml(content)
|
||||||
@ -357,10 +436,10 @@ class HardLink:
|
|||||||
return dat_image
|
return dat_image
|
||||||
|
|
||||||
def get_video(self, content, bytesExtra, thumb=False):
|
def get_video(self, content, bytesExtra, thumb=False):
|
||||||
bytesDict = parseBytes(bytesExtra)
|
bytesDict = parseBytesExtra(bytesExtra)
|
||||||
for msginfo in bytesDict[3]:
|
for msginfo in bytesDict[3]:
|
||||||
if msginfo[1][1][1] == (3 if thumb else 4):
|
if msginfo[1] == (3 if thumb else 4):
|
||||||
pathh = msginfo[1][2][1] # wxid\FileStorage\...
|
pathh = msginfo[2] # wxid\FileStorage\...
|
||||||
pathh = "\\".join(pathh.split("\\")[1:])
|
pathh = "\\".join(pathh.split("\\")[1:])
|
||||||
return pathh
|
return pathh
|
||||||
md5 = get_md5_from_xml(content, type_="video")
|
md5 = get_md5_from_xml(content, type_="video")
|
||||||
|
@ -4,10 +4,10 @@ import sqlite3
|
|||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from app.DataBase.hard_link import parseBytes
|
from app.DataBase.hard_link import parseBytesExtra
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.util.compress_content import parser_reply
|
from app.util.compress_content import parser_reply
|
||||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
from app.DataBase.hard_link import parseBytesExtra
|
||||||
|
|
||||||
db_path = "./app/Database/Msg/MSG.db"
|
db_path = "./app/Database/Msg/MSG.db"
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
@ -66,12 +66,11 @@ class Msg:
|
|||||||
if is_sender:
|
if is_sender:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
msgbytes = MessageBytesExtra()
|
msgbytes = parseBytesExtra(message[10])
|
||||||
msgbytes.ParseFromString(message[10])
|
for tmp in msgbytes[3]:
|
||||||
for tmp in msgbytes.message2:
|
if tmp[1] != 1:
|
||||||
if tmp.field1 != 1:
|
|
||||||
continue
|
continue
|
||||||
wxid = tmp.field2
|
wxid = tmp[2]
|
||||||
new_message = (*message, wxid)
|
new_message = (*message, wxid)
|
||||||
new_messages.append(new_message)
|
new_messages.append(new_message)
|
||||||
return new_messages
|
return new_messages
|
||||||
@ -651,12 +650,12 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
show_display_name = appinfo.find('appname').text
|
show_display_name = appinfo.find('appname').text
|
||||||
print(title, des, url, show_display_name)
|
print(title, des, url, show_display_name)
|
||||||
bytesDict = parseBytes(msg[10])
|
bytesDict = parseBytesExtra(msg[10])
|
||||||
for msginfo in bytesDict[3]:
|
for msginfo in bytesDict[3]:
|
||||||
print(msginfo)
|
print(msginfo)
|
||||||
if msginfo[1][1][1] == 3:
|
if msginfo[1] == 3:
|
||||||
thumb = msginfo[1][2][1]
|
thumb = msginfo[2]
|
||||||
print(thumb)
|
print(thumb)
|
||||||
if msginfo[1][1][1] == 4:
|
if msginfo[1] == 4:
|
||||||
app_logo = msginfo[1][2][1]
|
app_logo = msginfo[2]
|
||||||
print('logo',app_logo)
|
print('logo',app_logo)
|
@ -1,9 +1,8 @@
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
from app.DataBase import msg_db, micro_msg_db, misc_db
|
from app.DataBase import msg_db, micro_msg_db, misc_db
|
||||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
|
||||||
from app.util.protocbuf.roomdata_pb2 import ChatRoomData
|
|
||||||
from app.person import Contact, Me, ContactDefault
|
from app.person import Contact, Me, ContactDefault
|
||||||
|
from app.DataBase.hard_link import parseBytesExtra, parseChatRoomData
|
||||||
|
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
@ -25,9 +24,9 @@ class PackageMsg:
|
|||||||
self.ChatRoomMap = {}
|
self.ChatRoomMap = {}
|
||||||
|
|
||||||
def get_package_message_all(self):
|
def get_package_message_all(self):
|
||||||
'''
|
"""
|
||||||
获取完整的聊天记录
|
获取完整的聊天记录
|
||||||
'''
|
"""
|
||||||
updated_messages = [] # 用于存储修改后的消息列表
|
updated_messages = [] # 用于存储修改后的消息列表
|
||||||
|
|
||||||
messages = msg_db.get_messages_all()
|
messages = msg_db.get_messages_all()
|
||||||
@ -46,26 +45,25 @@ class PackageMsg:
|
|||||||
row_list.append(info[3])
|
row_list.append(info[3])
|
||||||
row_list.append(info[4])
|
row_list.append(info[4])
|
||||||
else:
|
else:
|
||||||
row_list.append('')
|
row_list.append("")
|
||||||
row_list.append('')
|
row_list.append("")
|
||||||
# 判断是否是群聊
|
# 判断是否是群聊
|
||||||
if strtalker.__contains__('@chatroom'):
|
if strtalker.__contains__("@chatroom"):
|
||||||
# 自己发送
|
# 自己发送
|
||||||
if row[4] == 1:
|
if row[4] == 1:
|
||||||
row_list.append('我')
|
row_list.append("我")
|
||||||
else:
|
else:
|
||||||
# 存在BytesExtra为空的情况,此时消息类型应该为提示性消息。跳过不处理
|
# 存在BytesExtra为空的情况,此时消息类型应该为提示性消息。跳过不处理
|
||||||
if row[10] is None:
|
if row[10] is None:
|
||||||
continue
|
continue
|
||||||
# 解析BytesExtra
|
# 解析BytesExtra
|
||||||
msgbytes = MessageBytesExtra()
|
msgbytes = parseBytesExtra(row[10])
|
||||||
msgbytes.ParseFromString(row[10])
|
wxid = ""
|
||||||
wxid = ''
|
for tmp in msgbytes[3]:
|
||||||
for tmp in msgbytes.message2:
|
if tmp[1] != 1:
|
||||||
if tmp.field1 != 1:
|
|
||||||
continue
|
continue
|
||||||
wxid = tmp.field2
|
wxid = tmp[2]
|
||||||
sender = ''
|
sender = ""
|
||||||
# 获取群聊成员列表
|
# 获取群聊成员列表
|
||||||
membersMap = self.get_chatroom_member_list(strtalker)
|
membersMap = self.get_chatroom_member_list(strtalker)
|
||||||
if membersMap is not None:
|
if membersMap is not None:
|
||||||
@ -82,17 +80,17 @@ class PackageMsg:
|
|||||||
row_list.append(sender)
|
row_list.append(sender)
|
||||||
else:
|
else:
|
||||||
if row[4] == 1:
|
if row[4] == 1:
|
||||||
row_list.append('我')
|
row_list.append("我")
|
||||||
else:
|
else:
|
||||||
if info is not None:
|
if info is not None:
|
||||||
row_list.append(info[4])
|
row_list.append(info[4])
|
||||||
else:
|
else:
|
||||||
row_list.append('')
|
row_list.append("")
|
||||||
updated_messages.append(tuple(row_list))
|
updated_messages.append(tuple(row_list))
|
||||||
return updated_messages
|
return updated_messages
|
||||||
|
|
||||||
def get_package_message_by_wxid(self, chatroom_wxid):
|
def get_package_message_by_wxid(self, chatroom_wxid):
|
||||||
'''
|
"""
|
||||||
获取一个群聊的聊天记录
|
获取一个群聊的聊天记录
|
||||||
return list
|
return list
|
||||||
a[0]: localId,
|
a[0]: localId,
|
||||||
@ -108,7 +106,7 @@ class PackageMsg:
|
|||||||
a[10]: BytesExtra,
|
a[10]: BytesExtra,
|
||||||
a[11]: CompressContent,
|
a[11]: CompressContent,
|
||||||
a[12]: msg_sender, (ContactPC 或 ContactDefault 类型,这个才是群聊里的信息发送人,不是群聊或者自己是发送者没有这个字段)
|
a[12]: msg_sender, (ContactPC 或 ContactDefault 类型,这个才是群聊里的信息发送人,不是群聊或者自己是发送者没有这个字段)
|
||||||
'''
|
"""
|
||||||
updated_messages = [] # 用于存储修改后的消息列表
|
updated_messages = [] # 用于存储修改后的消息列表
|
||||||
chatroom_members = self.get_chatroom_member_list(chatroom_wxid)
|
chatroom_members = self.get_chatroom_member_list(chatroom_wxid)
|
||||||
messages = msg_db.get_messages(chatroom_wxid)
|
messages = msg_db.get_messages(chatroom_wxid)
|
||||||
@ -122,13 +120,12 @@ class PackageMsg:
|
|||||||
message.append(ContactDefault(wxid))
|
message.append(ContactDefault(wxid))
|
||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
continue
|
continue
|
||||||
msgbytes = MessageBytesExtra()
|
msgbytes = parseBytesExtra(row[10])
|
||||||
msgbytes.ParseFromString(message[10])
|
wxid = ""
|
||||||
wxid = ''
|
for tmp in msgbytes[3]:
|
||||||
for tmp in msgbytes.message2:
|
if tmp[1] != 1:
|
||||||
if tmp.field1 != 1:
|
|
||||||
continue
|
continue
|
||||||
wxid = tmp.field2
|
wxid = tmp[2]
|
||||||
if wxid == "": # 系统消息里面 wxid 不存在
|
if wxid == "": # 系统消息里面 wxid 不存在
|
||||||
message.append(ContactDefault(wxid))
|
message.append(ContactDefault(wxid))
|
||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
@ -139,12 +136,12 @@ class PackageMsg:
|
|||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
continue
|
continue
|
||||||
contact_info = {
|
contact_info = {
|
||||||
'UserName': contact_info_list[0],
|
"UserName": contact_info_list[0],
|
||||||
'Alias': contact_info_list[1],
|
"Alias": contact_info_list[1],
|
||||||
'Type': contact_info_list[2],
|
"Type": contact_info_list[2],
|
||||||
'Remark': contact_info_list[3],
|
"Remark": contact_info_list[3],
|
||||||
'NickName': contact_info_list[4],
|
"NickName": contact_info_list[4],
|
||||||
'smallHeadImgUrl': contact_info_list[7]
|
"smallHeadImgUrl": contact_info_list[7],
|
||||||
}
|
}
|
||||||
contact = Contact(contact_info)
|
contact = Contact(contact_info)
|
||||||
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
|
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
|
||||||
@ -155,9 +152,9 @@ class PackageMsg:
|
|||||||
|
|
||||||
def get_chatroom_member_list(self, strtalker):
|
def get_chatroom_member_list(self, strtalker):
|
||||||
membermap = {}
|
membermap = {}
|
||||||
'''
|
"""
|
||||||
获取群聊成员
|
获取群聊成员
|
||||||
'''
|
"""
|
||||||
try:
|
try:
|
||||||
lock.acquire(True)
|
lock.acquire(True)
|
||||||
if strtalker in self.ChatRoomMap:
|
if strtalker in self.ChatRoomMap:
|
||||||
@ -167,17 +164,18 @@ class PackageMsg:
|
|||||||
if chatroom is None:
|
if chatroom is None:
|
||||||
return None
|
return None
|
||||||
# 解析RoomData数据
|
# 解析RoomData数据
|
||||||
parsechatroom = ChatRoomData()
|
parsechatroom = parseChatRoomData(chatroom[1])
|
||||||
parsechatroom.ParseFromString(chatroom[1])
|
|
||||||
# 群成员数据放入字典存储
|
# 群成员数据放入字典存储
|
||||||
for mem in parsechatroom.members:
|
print(parsechatroom[7])
|
||||||
if mem.displayName is not None and len(mem.displayName) > 0:
|
for mem in parsechatroom[1]:
|
||||||
membermap[mem.wxID] = mem.displayName
|
if mem[2] is not None and len(mem[2]) > 0:
|
||||||
|
membermap[mem[1]] = mem[2] # wxid -> displayname
|
||||||
self.ChatRoomMap[strtalker] = membermap
|
self.ChatRoomMap[strtalker] = membermap
|
||||||
finally:
|
finally:
|
||||||
lock.release()
|
lock.release()
|
||||||
return membermap
|
return membermap
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
p = PackageMsg()
|
p = PackageMsg()
|
||||||
print(p.get_package_message_by_wxid("48615079469@chatroom"))
|
print(p.get_package_message_by_wxid("18508451193@chatroom"))
|
||||||
|
@ -8,7 +8,7 @@ import re
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from app.DataBase.hard_link import parseBytes
|
from app.DataBase.hard_link import parseBytesExtra
|
||||||
from ..util.file import get_file
|
from ..util.file import get_file
|
||||||
|
|
||||||
|
|
||||||
@ -149,15 +149,15 @@ def share_card(bytesExtra, compress_content_):
|
|||||||
else:
|
else:
|
||||||
if appinfo is not None:
|
if appinfo is not None:
|
||||||
show_display_name = appinfo.find('appname').text
|
show_display_name = appinfo.find('appname').text
|
||||||
bytesDict = parseBytes(bytesExtra)
|
bytesDict = parseBytesExtra(bytesExtra)
|
||||||
app_logo = ''
|
app_logo = ''
|
||||||
thumbnail = ''
|
thumbnail = ''
|
||||||
for msginfo in bytesDict[3]:
|
for msginfo in bytesDict[3]:
|
||||||
if msginfo[1][1][1] == 3:
|
if msginfo[1] == 3:
|
||||||
thumbnail = msginfo[1][2][1]
|
thumbnail = msginfo[2]
|
||||||
thumbnail = "\\".join(thumbnail.split('\\')[1:])
|
thumbnail = "\\".join(thumbnail.split('\\')[1:])
|
||||||
if msginfo[1][1][1] == 4:
|
if msginfo[1] == 4:
|
||||||
app_logo = msginfo[1][2][1]
|
app_logo = msginfo[2]
|
||||||
app_logo = "\\".join(app_logo.split('\\')[1:])
|
app_logo = "\\".join(app_logo.split('\\')[1:])
|
||||||
if sourceusername is not None:
|
if sourceusername is not None:
|
||||||
from app.DataBase import micro_msg_db # 放上面会导致循环依赖
|
from app.DataBase import micro_msg_db # 放上面会导致循环依赖
|
||||||
|
@ -5,7 +5,7 @@ import shutil
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from app.log import log, logger
|
from app.log import log, logger
|
||||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
from app.DataBase.hard_link import parseBytesExtra
|
||||||
from ..person import Me
|
from ..person import Me
|
||||||
|
|
||||||
root_path = './data/files/'
|
root_path = './data/files/'
|
||||||
@ -22,14 +22,13 @@ class File:
|
|||||||
|
|
||||||
def get_file(bytes_extra, file_name, output_path=root_path) -> str:
|
def get_file(bytes_extra, file_name, output_path=root_path) -> str:
|
||||||
try:
|
try:
|
||||||
msg_bytes = MessageBytesExtra()
|
msg_bytes = parseBytesExtra(bytes_extra)
|
||||||
msg_bytes.ParseFromString(bytes_extra)
|
|
||||||
file_path = ''
|
file_path = ''
|
||||||
real_path = ''
|
real_path = ''
|
||||||
if len(msg_bytes.message2) > 0:
|
if len(msg_bytes[3]) > 0:
|
||||||
for filed in msg_bytes.message2:
|
for filed in msg_bytes[3]:
|
||||||
if filed.field1 == 4:
|
if filed[1] == 4:
|
||||||
file_original_path = filed.field2
|
file_original_path = filed[2]
|
||||||
file_path = os.path.join(output_path, file_name)
|
file_path = os.path.join(output_path, file_name)
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
# print('文件' + file_path + '已存在')
|
# print('文件' + file_path + '已存在')
|
||||||
|
@ -3,7 +3,7 @@ import traceback
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from app.log import log, logger
|
from app.log import log, logger
|
||||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
from app.DataBase.hard_link import parseBytesExtra
|
||||||
import requests
|
import requests
|
||||||
from urllib.parse import urlparse, parse_qs
|
from urllib.parse import urlparse, parse_qs
|
||||||
import re
|
import re
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package app.protobuf;
|
|
||||||
option go_package=".;proto";
|
|
||||||
|
|
||||||
message SubMessage1 {
|
|
||||||
int32 field1 = 1;
|
|
||||||
int32 field2 = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message SubMessage2 {
|
|
||||||
int32 field1 = 1;
|
|
||||||
string field2 = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message MessageBytesExtra {
|
|
||||||
SubMessage1 message1 = 1;
|
|
||||||
repeated SubMessage2 message2 = 3;
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
||||||
# source: msg.proto
|
|
||||||
"""Generated protocol buffer code."""
|
|
||||||
from google.protobuf import descriptor as _descriptor
|
|
||||||
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
||||||
from google.protobuf import message as _message
|
|
||||||
from google.protobuf import reflection as _reflection
|
|
||||||
from google.protobuf import symbol_database as _symbol_database
|
|
||||||
# @@protoc_insertion_point(imports)
|
|
||||||
|
|
||||||
_sym_db = _symbol_database.Default()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tmsg.proto\x12\x0c\x61pp.protobuf\"-\n\x0bSubMessage1\x12\x0e\n\x06\x66ield1\x18\x01 \x01(\x05\x12\x0e\n\x06\x66ield2\x18\x02 \x01(\x05\"-\n\x0bSubMessage2\x12\x0e\n\x06\x66ield1\x18\x01 \x01(\x05\x12\x0e\n\x06\x66ield2\x18\x02 \x01(\t\"m\n\x11MessageBytesExtra\x12+\n\x08message1\x18\x01 \x01(\x0b\x32\x19.app.protobuf.SubMessage1\x12+\n\x08message2\x18\x03 \x03(\x0b\x32\x19.app.protobuf.SubMessage2b\x06proto3')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_SUBMESSAGE1 = DESCRIPTOR.message_types_by_name['SubMessage1']
|
|
||||||
_SUBMESSAGE2 = DESCRIPTOR.message_types_by_name['SubMessage2']
|
|
||||||
_MESSAGEBYTESEXTRA = DESCRIPTOR.message_types_by_name['MessageBytesExtra']
|
|
||||||
SubMessage1 = _reflection.GeneratedProtocolMessageType('SubMessage1', (_message.Message,), {
|
|
||||||
'DESCRIPTOR' : _SUBMESSAGE1,
|
|
||||||
'__module__' : 'msg_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:app.protobuf.SubMessage1)
|
|
||||||
})
|
|
||||||
_sym_db.RegisterMessage(SubMessage1)
|
|
||||||
|
|
||||||
SubMessage2 = _reflection.GeneratedProtocolMessageType('SubMessage2', (_message.Message,), {
|
|
||||||
'DESCRIPTOR' : _SUBMESSAGE2,
|
|
||||||
'__module__' : 'msg_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:app.protobuf.SubMessage2)
|
|
||||||
})
|
|
||||||
_sym_db.RegisterMessage(SubMessage2)
|
|
||||||
|
|
||||||
MessageBytesExtra = _reflection.GeneratedProtocolMessageType('MessageBytesExtra', (_message.Message,), {
|
|
||||||
'DESCRIPTOR' : _MESSAGEBYTESEXTRA,
|
|
||||||
'__module__' : 'msg_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:app.protobuf.MessageBytesExtra)
|
|
||||||
})
|
|
||||||
_sym_db.RegisterMessage(MessageBytesExtra)
|
|
||||||
|
|
||||||
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
||||||
|
|
||||||
DESCRIPTOR._options = None
|
|
||||||
_SUBMESSAGE1._serialized_start=27
|
|
||||||
_SUBMESSAGE1._serialized_end=72
|
|
||||||
_SUBMESSAGE2._serialized_start=74
|
|
||||||
_SUBMESSAGE2._serialized_end=119
|
|
||||||
_MESSAGEBYTESEXTRA._serialized_start=121
|
|
||||||
_MESSAGEBYTESEXTRA._serialized_end=230
|
|
||||||
# @@protoc_insertion_point(module_scope)
|
|
@ -1,34 +0,0 @@
|
|||||||
# 说明
|
|
||||||
|
|
||||||
## 解析
|
|
||||||
```shell
|
|
||||||
protoc --decode_raw < msg_data.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
## 根据解析结果,设置.proto文件
|
|
||||||
```shell
|
|
||||||
1 {
|
|
||||||
1: 16
|
|
||||||
2: 0
|
|
||||||
}
|
|
||||||
3 {
|
|
||||||
1: 1
|
|
||||||
2: "wxid_4b1t09d63spw22"
|
|
||||||
}
|
|
||||||
3 {
|
|
||||||
1: 7
|
|
||||||
2: "<msgsource>\n\t<alnode>\n\t\t<fr>2</fr>\n\t</alnode>\n\t<sec_msg_node>\n\t\t<uuid>c6680ab2c57499a1a22e44a7eada76e8_</uuid>\n\t</sec_msg_node>\n\t<silence>1</silence>\n\t<membercount>198</membercount>\n\t<signature>v1_Gj7hfmi5</signature>\n\t<tmp_node>\n\t\t<publisher-id></publisher-id>\n\t</tmp_node>\n</msgsource>\n"
|
|
||||||
}
|
|
||||||
3 {
|
|
||||||
1: 2
|
|
||||||
2: "c13acbc95512d1a59bb686d684fd64d8"
|
|
||||||
}
|
|
||||||
3 {
|
|
||||||
1: 4
|
|
||||||
2: "yiluoAK_47\\FileStorage\\Cache\\2023-08\\2286b5852db82f6cbd9c2084ccd52358"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
## 生成python文件
|
|
||||||
```shell
|
|
||||||
protoc --python_out=. msg.proto
|
|
||||||
```
|
|
@ -1,19 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package app.protobuf;
|
|
||||||
option go_package=".;proto";
|
|
||||||
|
|
||||||
message ChatRoomData {
|
|
||||||
message ChatRoomMember {
|
|
||||||
string wxID = 1;
|
|
||||||
string displayName = 2;
|
|
||||||
int32 state = 3;
|
|
||||||
}
|
|
||||||
repeated ChatRoomMember members = 1;
|
|
||||||
int32 field_2 = 2;
|
|
||||||
int32 field_3 = 3;
|
|
||||||
int32 field_4 = 4;
|
|
||||||
int32 room_capacity = 5;
|
|
||||||
int32 field_6 = 6;
|
|
||||||
int64 field_7 = 7;
|
|
||||||
int64 field_8 = 8;
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
||||||
# source: roomdata.proto
|
|
||||||
"""Generated protocol buffer code."""
|
|
||||||
from google.protobuf import descriptor as _descriptor
|
|
||||||
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
||||||
from google.protobuf import message as _message
|
|
||||||
from google.protobuf import reflection as _reflection
|
|
||||||
from google.protobuf import symbol_database as _symbol_database
|
|
||||||
# @@protoc_insertion_point(imports)
|
|
||||||
|
|
||||||
_sym_db = _symbol_database.Default()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0eroomdata.proto\x12\x0c\x61pp.protobuf\"\x8b\x02\n\x0c\x43hatRoomData\x12:\n\x07members\x18\x01 \x03(\x0b\x32).app.protobuf.ChatRoomData.ChatRoomMember\x12\x0f\n\x07\x66ield_2\x18\x02 \x01(\x05\x12\x0f\n\x07\x66ield_3\x18\x03 \x01(\x05\x12\x0f\n\x07\x66ield_4\x18\x04 \x01(\x05\x12\x15\n\rroom_capacity\x18\x05 \x01(\x05\x12\x0f\n\x07\x66ield_6\x18\x06 \x01(\x05\x12\x0f\n\x07\x66ield_7\x18\x07 \x01(\x03\x12\x0f\n\x07\x66ield_8\x18\x08 \x01(\x03\x1a\x42\n\x0e\x43hatRoomMember\x12\x0c\n\x04wxID\x18\x01 \x01(\t\x12\x13\n\x0b\x64isplayName\x18\x02 \x01(\t\x12\r\n\x05state\x18\x03 \x01(\x05\x62\x06proto3')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_CHATROOMDATA = DESCRIPTOR.message_types_by_name['ChatRoomData']
|
|
||||||
_CHATROOMDATA_CHATROOMMEMBER = _CHATROOMDATA.nested_types_by_name['ChatRoomMember']
|
|
||||||
ChatRoomData = _reflection.GeneratedProtocolMessageType('ChatRoomData', (_message.Message,), {
|
|
||||||
|
|
||||||
'ChatRoomMember' : _reflection.GeneratedProtocolMessageType('ChatRoomMember', (_message.Message,), {
|
|
||||||
'DESCRIPTOR' : _CHATROOMDATA_CHATROOMMEMBER,
|
|
||||||
'__module__' : 'roomdata_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:app.protobuf.ChatRoomData.ChatRoomMember)
|
|
||||||
})
|
|
||||||
,
|
|
||||||
'DESCRIPTOR' : _CHATROOMDATA,
|
|
||||||
'__module__' : 'roomdata_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:app.protobuf.ChatRoomData)
|
|
||||||
})
|
|
||||||
_sym_db.RegisterMessage(ChatRoomData)
|
|
||||||
_sym_db.RegisterMessage(ChatRoomData.ChatRoomMember)
|
|
||||||
|
|
||||||
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
||||||
|
|
||||||
DESCRIPTOR._options = None
|
|
||||||
_CHATROOMDATA._serialized_start=33
|
|
||||||
_CHATROOMDATA._serialized_end=300
|
|
||||||
_CHATROOMDATA_CHATROOMMEMBER._serialized_start=234
|
|
||||||
_CHATROOMDATA_CHATROOMMEMBER._serialized_end=300
|
|
||||||
# @@protoc_insertion_point(module_scope)
|
|
@ -12,8 +12,6 @@ requests
|
|||||||
flask==3.0.0
|
flask==3.0.0
|
||||||
pyecharts==2.0.1
|
pyecharts==2.0.1
|
||||||
jieba==0.42.1
|
jieba==0.42.1
|
||||||
google==3.0.0
|
|
||||||
protobuf==4.25.1
|
|
||||||
soupsieve==2.5
|
soupsieve==2.5
|
||||||
lz4==4.3.2
|
lz4==4.3.2
|
||||||
pilk==0.2.4
|
pilk==0.2.4
|
||||||
|
Loading…
Reference in New Issue
Block a user