import requests import json from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import base64 def aes_encrypt_ecb_hex(text, key): cipher = AES.new(key.encode('utf-8'), AES.MODE_ECB) padded_text = pad(text.encode('utf-8'), AES.block_size) encrypted = cipher.encrypt(padded_text) return encrypted.hex() def hex_to_bytes(hex_str): return bytes.fromhex(hex_str) def aes_decrypt_ecb_base64(encrypted_base64, key): encrypted = base64.b64decode(encrypted_base64) cipher = AES.new(key.encode('utf-8'), AES.MODE_ECB) decrypted = unpad(cipher.decrypt(encrypted), AES.block_size) return decrypted.decode('utf-8') url = "https://xcx.jnsi.cxql.net/sbwxxcx/asd/sco/getPhotoNoSbCard" aes_key = "jnsbwxxcx@20211110hJnLEncD0TgzZX" input_file = "/storage/emulated/0/Python源码/批量数据/批量.txt" output_directory = "/storage/emulated/0/Python源码/大头/" with open(input_file, "r") as file: lines = file.readlines() for line in lines: line = line.strip() if not line: continue #解析在这里 if "-" in line: name, idCard = line.split("-") else: name, idCard = line.split(" ", 1) request_data = { "xm": name, "sfzhm": idCard } params_aes = aes_encrypt_ecb_hex(json.dumps(request_data), aes_key) headers = {} response = requests.post(url, data={"paramsAes": params_aes}, headers=headers) if response.ok: response_data = response.json() if "data" in response_data: encrypted_photo_hex = response_data["data"] encrypted_photo_base64 = base64.b64encode(hex_to_bytes(encrypted_photo_hex)).decode('utf-8') photo_base64 = aes_decrypt_ecb_base64(encrypted_photo_base64, aes_key) birth_year = idCard[6:10] birth_month = idCard[10:12] birth_day = idCard[12:14] birth_date = f"{birth_year} 年 {birth_month} 月 {birth_day} 日" print("姓名: " + name) print("公民身份号码: " + idCard) print("出生: " + birth_date) output_file = f"{output_directory}{name}-{idCard}.png" with open(output_file, "wb") as file: file.write(base64.b64decode(photo_base64))