mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-21 01:52:35 +08:00
Revert "去除parseBytes中的字段名称,返回结果更简洁;把对protobuf的依赖去除"
This reverts commit ca491c3b3a
.
This commit is contained in:
parent
ca491c3b3a
commit
4416fea906
@ -41,7 +41,7 @@ class tencent_struct:
|
||||
def __readString(self):
|
||||
try:
|
||||
length = self.__readUleb()
|
||||
res = self.__data[self.__off : self.__off + length]
|
||||
res = self.__data[self.__off: self.__off + length]
|
||||
self.__add(length)
|
||||
except:
|
||||
raise
|
||||
@ -78,36 +78,12 @@ class tencent_struct:
|
||||
def __readData(self):
|
||||
try:
|
||||
length = self.__readUleb()
|
||||
data = self.__data[self.__off : self.__off + length]
|
||||
data = self.__data[self.__off: self.__off + length]
|
||||
self.__add(length)
|
||||
return data
|
||||
except:
|
||||
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):
|
||||
self.__data = data
|
||||
self.__off = off
|
||||
@ -135,8 +111,10 @@ class tencent_struct:
|
||||
if key == 0:
|
||||
break
|
||||
op = None
|
||||
fieldName = ""
|
||||
if key in current_dict:
|
||||
op = current_dict[key]
|
||||
op = current_dict[key][1]
|
||||
fieldName = current_dict[key][0]
|
||||
else:
|
||||
break
|
||||
if isinstance(op, dict):
|
||||
@ -144,56 +122,31 @@ class tencent_struct:
|
||||
res[key] = []
|
||||
current_struct = self.__readData()
|
||||
recursion = tencent_struct(current_struct)
|
||||
res[key].append(recursion.readStruct(op))
|
||||
res[key].append((fieldName, recursion.readStruct(op)))
|
||||
elif op != "":
|
||||
res[key] = self.__contenttype__[op](self)
|
||||
res[key] = (fieldName, self.__contenttype__[op](self))
|
||||
else:
|
||||
break
|
||||
except:
|
||||
raise
|
||||
return res
|
||||
|
||||
__bytesExtraStruct1__ = {1: "I", 2: "I"}
|
||||
__struct1__ = {1: ("", "I"), 2: ("", "I")}
|
||||
|
||||
__bytesExtraMsgInfo__ = {1: "I", 2: "s"}
|
||||
__msgInfo__ = {1: ("", "I"), 2: ("msg_info", "s")}
|
||||
|
||||
__bytesExtra__ = {
|
||||
1: __bytesExtraStruct1__,
|
||||
3: __bytesExtraMsgInfo__,
|
||||
1: ("", __struct1__),
|
||||
3: ("msg_info_struct", __msgInfo__),
|
||||
}
|
||||
|
||||
__extraBufStruct1__ = {1: "s", 2: "s"}
|
||||
__struct2__ = {1: ("", "s"), 2: ("", "s")}
|
||||
|
||||
__extraBuf__ = {
|
||||
1: __extraBufStruct1__,
|
||||
1: ("", __struct2__),
|
||||
}
|
||||
|
||||
__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):
|
||||
def get_bytesExta_Content(self, data=None, off=0):
|
||||
self.__setVals__(data, off)
|
||||
try:
|
||||
return self.readStruct("__bytesExtra__")
|
||||
@ -207,24 +160,16 @@ class tencent_struct:
|
||||
except:
|
||||
raise
|
||||
|
||||
def get_chatRoomData_Content(self, data=None, off=0):
|
||||
self.__setVals__(data, off)
|
||||
try:
|
||||
return self.readStruct("__chatRoomData__")
|
||||
except:
|
||||
raise
|
||||
|
||||
__contenttype__ = {
|
||||
"s": __readString,
|
||||
"I": __readUleb,
|
||||
"P": __readData,
|
||||
"L": __readUlong,
|
||||
}
|
||||
|
||||
|
||||
def parseBytesExtra(content: bytes):
|
||||
def parseBytes(content: bytes):
|
||||
try:
|
||||
bytesExtra = tencent_struct().get_bytesExtra_Content(content)
|
||||
bytesExtra = tencent_struct().get_bytesExta_Content(content)
|
||||
return bytesExtra
|
||||
except:
|
||||
pass
|
||||
@ -238,30 +183,6 @@ def parseExtraBuf(content: bytes):
|
||||
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):
|
||||
off = 0
|
||||
types = [b"\x04", b"\x18", b"\x17", b"\x02", b"\x05"]
|
||||
@ -277,56 +198,56 @@ def decodeExtraBuf(extra_buf_content: bytes):
|
||||
"759378AD": "手机号",
|
||||
"74752C06": "性别",
|
||||
}
|
||||
res = {"手机号": {"18": ""}}
|
||||
res = {'手机号': {'18': ''}}
|
||||
while off < len(extra_buf_content):
|
||||
length = 4 # 块头
|
||||
trunk_head = extra_buf_content[off : off + length]
|
||||
trunk_head = extra_buf_content[off: off + length]
|
||||
off += length
|
||||
trunk_head = binascii.hexlify(trunk_head).decode().upper()
|
||||
if trunk_head in trunkName:
|
||||
trunk_head = trunkName[trunk_head]
|
||||
res[trunk_head] = {}
|
||||
char = extra_buf_content[off : off + 1]
|
||||
char = extra_buf_content[off: off + 1]
|
||||
off += 1
|
||||
field = binascii.hexlify(char).decode()
|
||||
if char == b"\x04": # 四个字节的int,小端序
|
||||
length = 4
|
||||
intContent = extra_buf_content[off : off + length]
|
||||
intContent = extra_buf_content[off: off + length]
|
||||
off += 4
|
||||
intContent = int.from_bytes(intContent, "little")
|
||||
res[trunk_head][field] = intContent
|
||||
elif char == b"\x18": # utf-16字符串
|
||||
length = 4
|
||||
lengthContent = extra_buf_content[off : off + length]
|
||||
lengthContent = extra_buf_content[off: off + length]
|
||||
off += 4
|
||||
lengthContent = int.from_bytes(lengthContent, "little")
|
||||
strContent = extra_buf_content[off : off + lengthContent]
|
||||
strContent = extra_buf_content[off: off + lengthContent]
|
||||
off += lengthContent
|
||||
res[trunk_head][field] = strContent.decode("utf-16").rstrip("\x00")
|
||||
elif char == b"\x17": # utf-8 protobuf
|
||||
length = 4
|
||||
lengthContent = extra_buf_content[off : off + length]
|
||||
lengthContent = extra_buf_content[off: off + length]
|
||||
off += 4
|
||||
lengthContent = int.from_bytes(lengthContent, "little")
|
||||
strContent = extra_buf_content[off : off + lengthContent]
|
||||
strContent = extra_buf_content[off: off + lengthContent]
|
||||
off += lengthContent
|
||||
res[trunk_head][field] = parseExtraBuf(strContent)
|
||||
elif char == b"\x02": # 一个字节的int
|
||||
content = extra_buf_content[off : off + 1]
|
||||
content = extra_buf_content[off: off + 1]
|
||||
off += 1
|
||||
res[trunk_head][field] = int.from_bytes(content, "little")
|
||||
elif char == b"\x05": # 暂时不知道有啥用,固定8个字节,先当int处理
|
||||
length = 8
|
||||
content = extra_buf_content[off : off + length]
|
||||
content = extra_buf_content[off: off + length]
|
||||
off += length
|
||||
res[trunk_head][field] = int.from_bytes(content, "little")
|
||||
# print(res)
|
||||
|
||||
return {
|
||||
"region": (res["国家"]["18"], res["省份"]["18"], res["市"]["18"]),
|
||||
"signature": res["个性签名"]["18"],
|
||||
"telephone": res["手机号"]["18"],
|
||||
"gender": res["性别"]["04"],
|
||||
'region': (res['国家']['18'], res['省份']['18'], res['市']['18']),
|
||||
'signature': res['个性签名']['18'],
|
||||
'telephone': res['手机号']['18'],
|
||||
'gender': res['性别']['04']
|
||||
}
|
||||
|
||||
|
||||
@ -416,10 +337,10 @@ class HardLink:
|
||||
video_db_lock.release()
|
||||
|
||||
def get_image(self, content, bytesExtra, thumb=False):
|
||||
bytesDict = parseBytesExtra(bytesExtra)
|
||||
bytesDict = parseBytes(bytesExtra)
|
||||
for msginfo in bytesDict[3]:
|
||||
if msginfo[1] == (3 if thumb else 4):
|
||||
pathh = msginfo[2] # wxid\FileStorage\...
|
||||
if msginfo[1][1][1] == (3 if thumb else 4):
|
||||
pathh = msginfo[1][2][1] # wxid\FileStorage\...
|
||||
pathh = "\\".join(pathh.split("\\")[1:])
|
||||
return pathh
|
||||
md5 = get_md5_from_xml(content)
|
||||
@ -436,10 +357,10 @@ class HardLink:
|
||||
return dat_image
|
||||
|
||||
def get_video(self, content, bytesExtra, thumb=False):
|
||||
bytesDict = parseBytesExtra(bytesExtra)
|
||||
bytesDict = parseBytes(bytesExtra)
|
||||
for msginfo in bytesDict[3]:
|
||||
if msginfo[1] == (3 if thumb else 4):
|
||||
pathh = msginfo[2] # wxid\FileStorage\...
|
||||
if msginfo[1][1][1] == (3 if thumb else 4):
|
||||
pathh = msginfo[1][2][1] # wxid\FileStorage\...
|
||||
pathh = "\\".join(pathh.split("\\")[1:])
|
||||
return pathh
|
||||
md5 = get_md5_from_xml(content, type_="video")
|
||||
|
@ -4,10 +4,10 @@ import sqlite3
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
from app.DataBase.hard_link import parseBytesExtra
|
||||
from app.DataBase.hard_link import parseBytes
|
||||
from app.log import logger
|
||||
from app.util.compress_content import parser_reply
|
||||
from app.DataBase.hard_link import parseBytesExtra
|
||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
||||
|
||||
db_path = "./app/Database/Msg/MSG.db"
|
||||
lock = threading.Lock()
|
||||
@ -66,11 +66,12 @@ class Msg:
|
||||
if is_sender:
|
||||
pass
|
||||
else:
|
||||
msgbytes = parseBytesExtra(message[10])
|
||||
for tmp in msgbytes[3]:
|
||||
if tmp[1] != 1:
|
||||
msgbytes = MessageBytesExtra()
|
||||
msgbytes.ParseFromString(message[10])
|
||||
for tmp in msgbytes.message2:
|
||||
if tmp.field1 != 1:
|
||||
continue
|
||||
wxid = tmp[2]
|
||||
wxid = tmp.field2
|
||||
new_message = (*message, wxid)
|
||||
new_messages.append(new_message)
|
||||
return new_messages
|
||||
@ -650,12 +651,12 @@ if __name__ == '__main__':
|
||||
else:
|
||||
show_display_name = appinfo.find('appname').text
|
||||
print(title, des, url, show_display_name)
|
||||
bytesDict = parseBytesExtra(msg[10])
|
||||
bytesDict = parseBytes(msg[10])
|
||||
for msginfo in bytesDict[3]:
|
||||
print(msginfo)
|
||||
if msginfo[1] == 3:
|
||||
thumb = msginfo[2]
|
||||
if msginfo[1][1][1] == 3:
|
||||
thumb = msginfo[1][2][1]
|
||||
print(thumb)
|
||||
if msginfo[1] == 4:
|
||||
app_logo = msginfo[2]
|
||||
if msginfo[1][1][1] == 4:
|
||||
app_logo = msginfo[1][2][1]
|
||||
print('logo',app_logo)
|
@ -1,8 +1,9 @@
|
||||
import threading
|
||||
|
||||
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.DataBase.hard_link import parseBytesExtra, parseChatRoomData
|
||||
|
||||
lock = threading.Lock()
|
||||
|
||||
@ -24,9 +25,9 @@ class PackageMsg:
|
||||
self.ChatRoomMap = {}
|
||||
|
||||
def get_package_message_all(self):
|
||||
"""
|
||||
'''
|
||||
获取完整的聊天记录
|
||||
"""
|
||||
'''
|
||||
updated_messages = [] # 用于存储修改后的消息列表
|
||||
|
||||
messages = msg_db.get_messages_all()
|
||||
@ -45,25 +46,26 @@ class PackageMsg:
|
||||
row_list.append(info[3])
|
||||
row_list.append(info[4])
|
||||
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:
|
||||
row_list.append("我")
|
||||
row_list.append('我')
|
||||
else:
|
||||
# 存在BytesExtra为空的情况,此时消息类型应该为提示性消息。跳过不处理
|
||||
if row[10] is None:
|
||||
continue
|
||||
# 解析BytesExtra
|
||||
msgbytes = parseBytesExtra(row[10])
|
||||
wxid = ""
|
||||
for tmp in msgbytes[3]:
|
||||
if tmp[1] != 1:
|
||||
msgbytes = MessageBytesExtra()
|
||||
msgbytes.ParseFromString(row[10])
|
||||
wxid = ''
|
||||
for tmp in msgbytes.message2:
|
||||
if tmp.field1 != 1:
|
||||
continue
|
||||
wxid = tmp[2]
|
||||
sender = ""
|
||||
wxid = tmp.field2
|
||||
sender = ''
|
||||
# 获取群聊成员列表
|
||||
membersMap = self.get_chatroom_member_list(strtalker)
|
||||
if membersMap is not None:
|
||||
@ -80,17 +82,17 @@ class PackageMsg:
|
||||
row_list.append(sender)
|
||||
else:
|
||||
if row[4] == 1:
|
||||
row_list.append("我")
|
||||
row_list.append('我')
|
||||
else:
|
||||
if info is not None:
|
||||
row_list.append(info[4])
|
||||
else:
|
||||
row_list.append("")
|
||||
row_list.append('')
|
||||
updated_messages.append(tuple(row_list))
|
||||
return updated_messages
|
||||
|
||||
|
||||
def get_package_message_by_wxid(self, chatroom_wxid):
|
||||
"""
|
||||
'''
|
||||
获取一个群聊的聊天记录
|
||||
return list
|
||||
a[0]: localId,
|
||||
@ -106,42 +108,43 @@ class PackageMsg:
|
||||
a[10]: BytesExtra,
|
||||
a[11]: CompressContent,
|
||||
a[12]: msg_sender, (ContactPC 或 ContactDefault 类型,这个才是群聊里的信息发送人,不是群聊或者自己是发送者没有这个字段)
|
||||
"""
|
||||
'''
|
||||
updated_messages = [] # 用于存储修改后的消息列表
|
||||
chatroom_members = self.get_chatroom_member_list(chatroom_wxid)
|
||||
messages = msg_db.get_messages(chatroom_wxid)
|
||||
for row in messages:
|
||||
message = list(row)
|
||||
if message[4] == 1: # 自己发送的就没必要解析了
|
||||
if message[4] == 1: # 自己发送的就没必要解析了
|
||||
message.append(Me())
|
||||
updated_messages.append(message)
|
||||
continue
|
||||
if message[10] is None: # BytesExtra是空的跳过
|
||||
if message[10] is None: # BytesExtra是空的跳过
|
||||
message.append(ContactDefault(wxid))
|
||||
updated_messages.append(message)
|
||||
continue
|
||||
msgbytes = parseBytesExtra(row[10])
|
||||
wxid = ""
|
||||
for tmp in msgbytes[3]:
|
||||
if tmp[1] != 1:
|
||||
msgbytes = MessageBytesExtra()
|
||||
msgbytes.ParseFromString(message[10])
|
||||
wxid = ''
|
||||
for tmp in msgbytes.message2:
|
||||
if tmp.field1 != 1:
|
||||
continue
|
||||
wxid = tmp[2]
|
||||
if wxid == "": # 系统消息里面 wxid 不存在
|
||||
wxid = tmp.field2
|
||||
if wxid == "": # 系统消息里面 wxid 不存在
|
||||
message.append(ContactDefault(wxid))
|
||||
updated_messages.append(message)
|
||||
continue
|
||||
contact_info_list = micro_msg_db.get_contact_by_username(wxid)
|
||||
if contact_info_list is None: # 群聊中已退群的联系人不会保存在数据库里
|
||||
if contact_info_list is None: # 群聊中已退群的联系人不会保存在数据库里
|
||||
message.append(ContactDefault(wxid))
|
||||
updated_messages.append(message)
|
||||
continue
|
||||
contact_info = {
|
||||
"UserName": contact_info_list[0],
|
||||
"Alias": contact_info_list[1],
|
||||
"Type": contact_info_list[2],
|
||||
"Remark": contact_info_list[3],
|
||||
"NickName": contact_info_list[4],
|
||||
"smallHeadImgUrl": contact_info_list[7],
|
||||
'UserName': contact_info_list[0],
|
||||
'Alias': contact_info_list[1],
|
||||
'Type': contact_info_list[2],
|
||||
'Remark': contact_info_list[3],
|
||||
'NickName': contact_info_list[4],
|
||||
'smallHeadImgUrl': contact_info_list[7]
|
||||
}
|
||||
contact = Contact(contact_info)
|
||||
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
|
||||
@ -152,9 +155,9 @@ class PackageMsg:
|
||||
|
||||
def get_chatroom_member_list(self, strtalker):
|
||||
membermap = {}
|
||||
"""
|
||||
'''
|
||||
获取群聊成员
|
||||
"""
|
||||
'''
|
||||
try:
|
||||
lock.acquire(True)
|
||||
if strtalker in self.ChatRoomMap:
|
||||
@ -164,18 +167,17 @@ class PackageMsg:
|
||||
if chatroom is None:
|
||||
return None
|
||||
# 解析RoomData数据
|
||||
parsechatroom = parseChatRoomData(chatroom[1])
|
||||
parsechatroom = ChatRoomData()
|
||||
parsechatroom.ParseFromString(chatroom[1])
|
||||
# 群成员数据放入字典存储
|
||||
print(parsechatroom[7])
|
||||
for mem in parsechatroom[1]:
|
||||
if mem[2] is not None and len(mem[2]) > 0:
|
||||
membermap[mem[1]] = mem[2] # wxid -> displayname
|
||||
for mem in parsechatroom.members:
|
||||
if mem.displayName is not None and len(mem.displayName) > 0:
|
||||
membermap[mem.wxID] = mem.displayName
|
||||
self.ChatRoomMap[strtalker] = membermap
|
||||
finally:
|
||||
lock.release()
|
||||
return membermap
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
p = PackageMsg()
|
||||
print(p.get_package_message_by_wxid("18508451193@chatroom"))
|
||||
print(p.get_package_message_by_wxid("48615079469@chatroom"))
|
||||
|
@ -8,7 +8,7 @@ import re
|
||||
from urllib.parse import urlparse
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from app.DataBase.hard_link import parseBytesExtra
|
||||
from app.DataBase.hard_link import parseBytes
|
||||
from ..util.file import get_file
|
||||
|
||||
|
||||
@ -149,15 +149,15 @@ def share_card(bytesExtra, compress_content_):
|
||||
else:
|
||||
if appinfo is not None:
|
||||
show_display_name = appinfo.find('appname').text
|
||||
bytesDict = parseBytesExtra(bytesExtra)
|
||||
bytesDict = parseBytes(bytesExtra)
|
||||
app_logo = ''
|
||||
thumbnail = ''
|
||||
for msginfo in bytesDict[3]:
|
||||
if msginfo[1] == 3:
|
||||
thumbnail = msginfo[2]
|
||||
if msginfo[1][1][1] == 3:
|
||||
thumbnail = msginfo[1][2][1]
|
||||
thumbnail = "\\".join(thumbnail.split('\\')[1:])
|
||||
if msginfo[1] == 4:
|
||||
app_logo = msginfo[2]
|
||||
if msginfo[1][1][1] == 4:
|
||||
app_logo = msginfo[1][2][1]
|
||||
app_logo = "\\".join(app_logo.split('\\')[1:])
|
||||
if sourceusername is not None:
|
||||
from app.DataBase import micro_msg_db # 放上面会导致循环依赖
|
||||
|
@ -5,7 +5,7 @@ import shutil
|
||||
import requests
|
||||
|
||||
from app.log import log, logger
|
||||
from app.DataBase.hard_link import parseBytesExtra
|
||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
||||
from ..person import Me
|
||||
|
||||
root_path = './data/files/'
|
||||
@ -22,13 +22,14 @@ class File:
|
||||
|
||||
def get_file(bytes_extra, file_name, output_path=root_path) -> str:
|
||||
try:
|
||||
msg_bytes = parseBytesExtra(bytes_extra)
|
||||
msg_bytes = MessageBytesExtra()
|
||||
msg_bytes.ParseFromString(bytes_extra)
|
||||
file_path = ''
|
||||
real_path = ''
|
||||
if len(msg_bytes[3]) > 0:
|
||||
for filed in msg_bytes[3]:
|
||||
if filed[1] == 4:
|
||||
file_original_path = filed[2]
|
||||
if len(msg_bytes.message2) > 0:
|
||||
for filed in msg_bytes.message2:
|
||||
if filed.field1 == 4:
|
||||
file_original_path = filed.field2
|
||||
file_path = os.path.join(output_path, file_name)
|
||||
if os.path.exists(file_path):
|
||||
# print('文件' + file_path + '已存在')
|
||||
|
@ -3,7 +3,7 @@ import traceback
|
||||
import shutil
|
||||
|
||||
from app.log import log, logger
|
||||
from app.DataBase.hard_link import parseBytesExtra
|
||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
||||
import requests
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
import re
|
||||
|
0
app/util/protocbuf/__init__.py
Normal file
0
app/util/protocbuf/__init__.py
Normal file
18
app/util/protocbuf/msg.proto
Normal file
18
app/util/protocbuf/msg.proto
Normal file
@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
54
app/util/protocbuf/msg_pb2.py
Normal file
54
app/util/protocbuf/msg_pb2.py
Normal file
@ -0,0 +1,54 @@
|
||||
# -*- 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)
|
34
app/util/protocbuf/readme.md
Normal file
34
app/util/protocbuf/readme.md
Normal file
@ -0,0 +1,34 @@
|
||||
# 说明
|
||||
|
||||
## 解析
|
||||
```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
|
||||
```
|
19
app/util/protocbuf/roomdata.proto
Normal file
19
app/util/protocbuf/roomdata.proto
Normal file
@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
45
app/util/protocbuf/roomdata_pb2.py
Normal file
45
app/util/protocbuf/roomdata_pb2.py
Normal file
@ -0,0 +1,45 @@
|
||||
# -*- 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,6 +12,8 @@ requests
|
||||
flask==3.0.0
|
||||
pyecharts==2.0.1
|
||||
jieba==0.42.1
|
||||
google==3.0.0
|
||||
protobuf==4.25.1
|
||||
soupsieve==2.5
|
||||
lz4==4.3.2
|
||||
pilk==0.2.4
|
||||
|
Loading…
Reference in New Issue
Block a user