# -*- coding: utf-8 -*- # @Author: wangkun # @Time: 2023/2/13 import json import os class Demo: @classmethod def demo1(cls): # charles 抓包文件保存目录 chlsfile_path = f"../weixinzhishu_chlsfiles/" if len(os.listdir(chlsfile_path)) == 0: print("chlsfile文件夹为空") else: print(f"chlsfile_list:{sorted(os.listdir(chlsfile_path))}") # 获取最新的 chlsfile chlsfile = sorted(os.listdir(chlsfile_path))[-1] # 分离文件名与扩展名 new_file = os.path.splitext(chlsfile) # 重命名文件后缀 os.rename(os.path.join(chlsfile_path, chlsfile), os.path.join(chlsfile_path, new_file[0] + ".txt")) with open(f"{chlsfile_path}{new_file[0]}.txt", encoding='utf-8-sig', errors='ignore') as f: contents = json.load(f, strict=False) if "search.weixin.qq.com" not in [text['host'] for text in contents]: return "未找到search_key" else: for content in contents: if content["host"] == "search.weixin.qq.com" and content[ "path"] == "/cgi-bin/wxaweb/wxindexgetusergroup": print(f"content:{content}") text = content['request']['body']['text'] search_key = json.loads(text)['search_key'] openid = json.loads(text)['openid'] return search_key, openid if __name__ == "__main__": print(Demo.demo1())