demo.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/2/13
  4. import json
  5. import os
  6. class Demo:
  7. @classmethod
  8. def demo1(cls):
  9. # charles 抓包文件保存目录
  10. chlsfile_path = f"../weixinzhishu_chlsfiles/"
  11. if len(os.listdir(chlsfile_path)) == 0:
  12. print("chlsfile文件夹为空")
  13. else:
  14. print(f"chlsfile_list:{sorted(os.listdir(chlsfile_path))}")
  15. # 获取最新的 chlsfile
  16. chlsfile = sorted(os.listdir(chlsfile_path))[-1]
  17. # 分离文件名与扩展名
  18. new_file = os.path.splitext(chlsfile)
  19. # 重命名文件后缀
  20. os.rename(os.path.join(chlsfile_path, chlsfile),
  21. os.path.join(chlsfile_path, new_file[0] + ".txt"))
  22. with open(f"{chlsfile_path}{new_file[0]}.txt", encoding='utf-8-sig', errors='ignore') as f:
  23. contents = json.load(f, strict=False)
  24. if "search.weixin.qq.com" not in [text['host'] for text in contents]:
  25. return "未找到search_key"
  26. else:
  27. for content in contents:
  28. if content["host"] == "search.weixin.qq.com" and content[
  29. "path"] == "/cgi-bin/wxaweb/wxindexgetusergroup":
  30. print(f"content:{content}")
  31. text = content['request']['body']['text']
  32. search_key = json.loads(text)['search_key']
  33. openid = json.loads(text)['openid']
  34. return search_key, openid
  35. if __name__ == "__main__":
  36. print(Demo.demo1())