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
   | import base64 import json import requests from mitmproxy import http
 
  def request(flow: http.HTTPFlow) -> None:          if flow.request.pretty_url.startswith("http://tzxm.jxzwfww.gov.cn/icity/api-v2/jxtzxm.app.icity.ipro.IproCmd/"):
                   data = {"group": "zzz", "action": "test", "param": ""}
                   res = requests.post("http://127.0.0.1:12080/go", data=data)
                   res_json = json.loads(res.text)["data"]         data_json = json.loads(res_json)         print("Received data:", data_json)
                   sig = data_json["sig"]         t = data_json["t"]         tkey = data_json["tkey"]
                   new_url = flow.request.pretty_url.split('?')[0]           new_url += f"?s={sig}&t={t}&o={tkey}"
          code_res = requests.get(f"http://tzxm.jxzwfww.gov.cn/icity/bsp/verifyCode?time={t}")         url = "http://127.0.0.1:8888/reg"         headers = {             "Authorization": "Basic f0ngauth",             "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:97.0) Gecko/20100101 Firefox/97.0",             "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",             "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",             "Accept-Encoding": "gzip, deflate",             "Connection": "keep-alive",             "Upgrade-Insecure-Requests": "1",             "Content-Type": "application/x-www-form-urlencoded"           }
                   if isinstance(code_res.content, bytes):             encoded_data = base64.b64encode(code_res.content).decode('utf-8')         elif isinstance(code_res.content, str):             encoded_data = base64.b64encode(code_res.content.encode('utf-8')).decode('utf-8')         else:             raise ValueError("不支持的数据类型进行Base64编码")
          data = encoded_data                  headers["Content-Length"] = str(len(data))
          response = requests.post(url, headers=headers, data=data)         Code = response.text
          request_body_dict = flow.request.json()                  request_body_dict["verifyCode"] = Code                  flow.request.text = request_body_dict.__str__()                  flow.request.url = new_url
   |