Download app.py from Ourking/PK: direct link, hf CLI and curl.
- Browser
- Download file 32.5 kB
-
https://huggingface.co/spaces/Ourking/PK/resolve/main/app.py
- Command line
-
hf download hf://spaces/Ourking/PK/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Ourking/PK/resolve/main/app.py
32.5 kB
| import os | |
| import json | |
| import sys | |
| import time | |
| import uuid | |
| import hashlib | |
| import random | |
| import string | |
| import re | |
| import threading | |
| from datetime import datetime, timedelta | |
| from flask import Flask, render_template, jsonify, request | |
| # ===================== 基础目录 ===================== | |
| BASE_DIR = "/data" | |
| DATA_DIR = os.path.join(BASE_DIR, "data") | |
| ACCU_DIR = os.path.join(BASE_DIR, "accu") | |
| LOGS_DIR = os.path.join(BASE_DIR, "logs") | |
| ACCOUNT_FILE = os.path.join(ACCU_DIR, "accounts.json") | |
| os.makedirs(DATA_DIR, exist_ok=True) | |
| os.makedirs(ACCU_DIR, exist_ok=True) | |
| os.makedirs(LOGS_DIR, exist_ok=True) | |
| sys.path.insert(0, DATA_DIR) | |
| app = Flask(__name__) | |
| # ===================== 日志与运行状态 ===================== | |
| app_logs = [] | |
| is_running = False | |
| current_log_file = None | |
| stop_flag = False | |
| logs_lock = threading.Lock() # 线程安全锁 | |
| def log_print(*args, **kwargs): | |
| msg = " ".join(str(x) for x in args) | |
| with logs_lock: | |
| app_logs.append(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}") | |
| print(*args, **kwargs) | |
| if current_log_file: | |
| with open(current_log_file, "a", encoding="utf-8") as f: | |
| f.write(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}\n") | |
| # ===================== 账号存储 ===================== | |
| def load_accounts(): | |
| if not os.path.exists(ACCOUNT_FILE): | |
| return [] | |
| with open(ACCOUNT_FILE, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| def save_accounts(accounts): | |
| with open(ACCOUNT_FILE, "w", encoding="utf-8") as f: | |
| json.dump(accounts, f, ensure_ascii=False, indent=2) | |
| # ===================== 注册逻辑(修复接口报错处理) ===================== | |
| import requests | |
| from bs4 import BeautifulSoup | |
| # 设备信息部分 | |
| Name=["VIVO-",'OPPO-','HUAWEI-','Honor-','XIAOMI','HONGMI-','APPLE-'] | |
| Type=[" S "," pro ","A "] | |
| def A(): | |
| invite_code ="96237588" | |
| client_id = "YNxT9w7GMdWvEOKa" | |
| client_version="1.52.6" | |
| client_secret = "dbw2OtmVEeuUvIptb1Coyg" | |
| package_name="com.pikcloud.pikpak" | |
| password="q12345" | |
| appkey="com.pikcloud.pikpak1appkey" | |
| ep="qwqwqw12" | |
| return invite_code, client_id, client_version, client_secret, package_name, password,appkey,ep | |
| def B(): | |
| timestamp=str(int(time.time()) * 1000) | |
| device_id= str(uuid.uuid4()).replace("-", "") | |
| PM="" | |
| for i in range(3): | |
| r=chr(random.randint(65,90)) | |
| PM+=r | |
| PM=PM+"-" | |
| for i in range(5): | |
| if random.randint(0,4)!=2: | |
| r=chr(random.randint(65,90)) | |
| else: | |
| r = chr(random.randint(48,57)) | |
| PM+=r | |
| PB=Name[random.randint(0,6)]+str(random.randint(3,9))+Type[random.randint(0,2)]+str(random.randint(5,6))+"G" | |
| return timestamp, device_id,PM,PB | |
| class C: | |
| r= '\033[91m' | |
| g = '\033[92m' | |
| y = '\033[93m' | |
| b = '\033[94m' | |
| m = '\033[95m' | |
| c = '\033[96m' | |
| re = '\033[0m' | |
| def get_ua_key(id,k): | |
| rank_1 = hashlib.sha1((id +k).encode("utf-8")).hexdigest() | |
| rank_2 = get_hash(rank_1) | |
| return id + rank_2 | |
| def get_UA(id, U, t,PM,PB): | |
| UA = "ANDROID-com.pikcloud.pikpak/1.52.6 accessmode/ devicename/"+PB+" appname/ android-com.pikcloud.pikpak appid/ action_type/ clientid/ YNxT9w7GMdWvEOKa deviceid/"+id+"refresh_token/ grant_type/ devicemodel/ "+PM+" networktype/WIFI accesstype/ sessionid/ osversion/"+"13."+str(random.randint(0,9))+"."+str(random.randint(0,9))+" datetime/"+t+" protocolversion/200 sdkversion/2.0.1.200200 clientversion/1.52.6 providername/NONE clientip/ session_origin/ devicesign/div101."+U+"platformversion/10 usrno/" | |
| return UA | |
| # 签名部分 | |
| salts=[{"alg":"md5","salt":"qLATQ928tXC8FYL5lL3VO"},{"alg":"md5","salt":"fqKUImZkgBpZKliDeQwDSP9lzhfl5aZjAGfvxVXw6k"},{"alg":"md5","salt":"3lFWgyuGxnYqNcJ6r6mvdfgVMriMY7ShhMUzM+2xiX0MtncGos"},{"alg":"md5","salt":"MpVaAf0ZzQ451ybLB3cHuh"},{"alg":"md5","salt":"ZttehUJNiTvri6mwwyCH3CRSkppKz0i01b5DvHdCY4"},{"alg":"md5","salt":"PtuHFIax2xQFQrnSB4yD/J"},{"alg":"md5","salt":"MFjXFbI/Mpc0XgYym6l90tWObnt1E"},{"alg":"md5","salt":"rm7faeCz+1YrW2B51LiOVin"}] | |
| def get_sign(orgin_str): | |
| for salt in salts: | |
| orgin_str = get_hash(orgin_str + salt["salt"]) | |
| return orgin_str | |
| def get_hash(str): | |
| obj = hashlib.md5() | |
| obj.update(str.encode("utf-8")) | |
| result = obj.hexdigest() | |
| return result | |
| def etoi(e): | |
| el = 'PiPk'+e.lower().strip() | |
| md5_hash = hashlib.md5(el.encode('utf-8')).hexdigest() | |
| return f"{md5_hash[:8]}-{md5_hash[8:12]}-{md5_hash[12:16]}-{md5_hash[16:20]}-{md5_hash[20:]}" | |
| # 修复邮箱接口报错处理 | |
| def 读邮件(e): | |
| id=etoi(e) | |
| try: | |
| response = requests.get(f'https://pipk6.fun/api/emails/{id}',headers={"X-API-Key": "mk_2JaLcQ8YU825SVFqG7LARK6-RFj0CvQv"}, timeout=15) | |
| response.raise_for_status() | |
| a = response.json() | |
| except Exception as e: | |
| log_print(f"邮箱读取接口报错:{str(e)}") | |
| return 0 | |
| if a['total']!=0: | |
| try: | |
| s=BeautifulSoup(a['messages'][0]['html'], 'html.parser') | |
| h=s.find_all('h2')[0] | |
| p_tags = s.find_all('p') | |
| p_tags.insert(3,h) | |
| result = '\n\n'.join([p.get_text().strip() for p in p_tags if p.get_text().strip()]) | |
| log_print(result) | |
| return h.get_text().strip() | |
| except: | |
| log_print(a) | |
| return 0 | |
| else: | |
| return 0 | |
| def get_delet(e): | |
| id=etoi(e) | |
| try: | |
| a=json.loads(requests.get(f'https://pipk6.fun/api/emails/{id}',headers={"X-API-Key": "mk_2JaLcQ8YU825SVFqG7LARK6-RFj0CvQv"}).text)['messages'] | |
| for i in range(len(a)): | |
| mid=a[i]['id'] | |
| log_print("邮件id:",mid) | |
| log_print("邮件删除结果:",requests.delete(f'https://pipk6.fun/api/emails/{id}/{mid}',headers={"X-API-Key": "mk_2JaLcQ8YU825SVFqG7LARK6-RFj0CvQv"}).text) | |
| except Exception as e: | |
| log_print(f"邮件删除接口报错:{str(e)}") | |
| # 修复邮箱生成接口报错处理 | |
| def creat_email(e): | |
| try: | |
| response = requests.post('https://pipk6.fun/api/emails/generate',headers={"X-API-Key": "mk_2JaLcQ8YU825SVFqG7LARK6-RFj0CvQv"},json={"name":e,"domain":"pipk6.fun","expiryTime":0}, timeout=15) | |
| response.raise_for_status() | |
| log_print("邮箱生成响应:", response.text) | |
| except Exception as e: | |
| log_print(f"邮箱生成接口报错:{str(e)}") | |
| # 修复打码接口报错处理 | |
| def get_txcaptcha(): | |
| for i in range(100): | |
| if stop_flag: return {"ticket": "", "randstr": ""} | |
| log_print(f'正在通知打码平台发送结果:{i}\n') | |
| time.sleep(2) | |
| try: | |
| res=requests.post("https://ourking-dm.hf.space/go?665",timeout=15) | |
| res.raise_for_status() | |
| # 处理 JSON 解析失败 | |
| try: | |
| res_json = res.json() | |
| except json.JSONDecodeError: | |
| log_print("打码接口返回非 JSON 数据:", res.text) | |
| continue | |
| log_print(f'收到结果:{res_json}\n') | |
| if res_json.get('ticket'): | |
| return res_json | |
| except Exception as e: | |
| log_print(f"打码接口报错:{str(e)}") | |
| log_print("打码平台多次调用失败,终止任务") | |
| return {"ticket": "", "randstr": ""} | |
| # 修复 PikPak 接口报错处理 | |
| def p1(client_id, captcha_token, device_id, captcha_sign, email, timestamp, User_Agent,x): | |
| url = "https://user.mypikpak.net/v1/shield/captcha/init?client_id=YNxT9w7GMdWvEOKa" | |
| querystring = {"client_id": client_id} | |
| payload = {"action": "POST:/v1/auth/verification","redirect_uri": "xlaccsdk01://xbase.cloud/callback?state=harbor","captcha_token": captcha_token,"client_id": client_id, "device_id": device_id,"meta": {"captcha_sign": "1." + captcha_sign,"user_id": "","package_name": "com.pikcloud.pikpak","client_version": "1.52.6","email": email,"timestamp": timestamp},} | |
| headers = {"X-Device-Id": device_id,"User-Agent": User_Agent,} | |
| headers.update(basicRequestHeaders_1) | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers, params=querystring,proxies=x, timeout=15) | |
| response.raise_for_status() | |
| log_print("邮箱类型判断: ", response.text) | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p1 接口报错:{str(E)}") | |
| return {"captcha_token": ""} | |
| def p2(client_id, captcha_token, email, device_id, User_Agent,x): | |
| url = "https://pipkzf.pipk7.top/?url=https://user.mypikpak.net/v1/auth/verification" | |
| querystring = {"client_id": client_id} | |
| payload = {"captcha_token":captcha_token,"email": email,"locale": "zh-CN","target": "ANY","client_id": client_id} | |
| headers = {"X-Device-Id": device_id,"User-Agent": User_Agent,} | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers, params=querystring,proxies=x, timeout=15) | |
| response.raise_for_status() | |
| log_print() | |
| log_print() | |
| log_print("正在发送验证码: ", response.text) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p2 接口报错:{str(E)}") | |
| return {"verification_id": ""} | |
| def p3(client_id, verification_id, verification_code, device_id, User_Agent,proxies): | |
| url = "https://user.mypikpak.net/v1/auth/verification/verify?client_id=YNxT9w7GMdWvEOKa" | |
| querystring = {"client_id": client_id} | |
| payload = { | |
| "client_id": client_id, | |
| "verification_id": verification_id, | |
| "verification_code": verification_code | |
| } | |
| headers = { | |
| "X-Device-Id": device_id, | |
| "User-Agent": User_Agent, | |
| } | |
| headers.update(basicRequestHeaders_1) | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers, params=querystring,proxies=proxies, timeout=15) | |
| response.raise_for_status() | |
| log_print("提交验证码: ", response.text) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p3 接口报错:{str(E)}") | |
| return {"verification_token": ""} | |
| def p4(client_id, captcha_token, device_id, captcha_sign, email, timestamp, User_Agent,proxies): | |
| url = "https://user.mypikpak.net/v1/shield/captcha/init?client_id=YNxT9w7GMdWvEOKa" | |
| querystring = {"client_id": client_id} | |
| payload = { | |
| "action": "POST:/v1/auth/signup", | |
| "captcha_token": captcha_token, | |
| "client_id": client_id, | |
| "device_id": device_id, | |
| "meta": { | |
| "captcha_sign": "1." + captcha_sign, | |
| "user_id": "", | |
| "package_name": "com.pikcloud.pikpak", | |
| "client_version": "1.52.6", | |
| "email": email, | |
| "timestamp": timestamp | |
| }, | |
| "redirect_uri": "xlaccsdk01://xbase.cloud/callback?state=harbor" | |
| } | |
| headers = { | |
| "Host": "user.mypikpak.com", | |
| "x-device-id": device_id, | |
| "user-agent": User_Agent, | |
| "accept-language": "zh", | |
| "content-type": "application/json", | |
| "accept-encoding": "gzip" | |
| } | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers, params=querystring,proxies=proxies, timeout=15) | |
| response.raise_for_status() | |
| log_print("安全信息提交:", response.text) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p4 接口报错:{str(E)}") | |
| return {"captcha_token": ""} | |
| # 修复安全检查接口参数错误 | |
| def part5_1(device_id, captcha_token, request_id, sign,rtc_token,user_agent, referer,x,txCaptcha,rand_str): | |
| url = "https://user.mypikpak.net/credit/v1/report?client_id=YNxT9w7GMdWvEOKa" | |
| # 移除无效参数,修复 400 错误 | |
| querystring = { | |
| "deviceid": device_id, | |
| "captcha_token": captcha_token, | |
| "type": "txCaptcha", | |
| "result": "0", | |
| "data": txCaptcha, | |
| "rand_str": rand_str | |
| } | |
| headers = { | |
| "Host": "user.mypikpak.com", | |
| "accept": "application/json, text/plain, */*", | |
| "user-agent": user_agent, | |
| "referer": referer, | |
| } | |
| headers.update(basicRequestHeaders_2) | |
| try: | |
| response = requests.request("GET", url, headers=headers, params=querystring,proxies=x, timeout=15) | |
| response.raise_for_status() | |
| log_print() | |
| log_print() | |
| log_print("安全检查: ", response.text) | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"part5_1 接口报错:{str(E)}") | |
| return {"captcha_token": ""} | |
| basicRequestHeaders_1 = { | |
| "Accept-Language": "zh", | |
| "Content-Type": "application/json; charset=utf-8", | |
| "Host": "user.mypikpak.com", | |
| "Connection": "Keep-Alive", | |
| "Accept-Encoding": "gzip", | |
| "content-type": "application/json"} | |
| basicRequestHeaders_2 = { | |
| "x-requested-with": "com.pikcloud.pikpak", | |
| "sec-fetch-site": "same-origin", | |
| "sec-fetch-mode": "cors", | |
| "sec-fetch-dest": "empty", | |
| "accept-encoding": "gzip, deflate", | |
| "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7", | |
| "cookie": "mainHost=user.mypikpak.com"} | |
| def p5(client_id, captcha_token, client_secret, email, name, password, verification_token, device_id, User_Agent,proxies): | |
| url = "https://pipkzf.pipk7.top/?url=https://user.mypikpak.net/v1/auth/signup?client_id=YNxT9w7GMdWvEOKa" | |
| querystring = {"client_id": client_id} | |
| payload = { | |
| "captcha_token": captcha_token, | |
| "client_id": client_id, | |
| "client_secret": client_secret, | |
| "email": email, | |
| "name": name, | |
| "password": password, | |
| "verification_token": verification_token | |
| } | |
| headers = { | |
| "X-Device-Id": device_id, | |
| "User-Agent": User_Agent, | |
| } | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers, params=querystring,proxies=proxies, timeout=15) | |
| response.raise_for_status() | |
| log_print("注册信息提交: ", response.text) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p5 接口报错:{str(E)}") | |
| return {"sub": ""} | |
| def p6(client_id, captcha_token, device_id, captcha_sign, user_id, timestamp, User_Agent,proxies): | |
| url = "https://user.mypikpak.net/v1/shield/captcha/init?client_id=YNxT9w7GMdWvEOKa" | |
| querystring = {"client_id": client_id} | |
| payload = { | |
| "action": "POST:/vip/v1/activity/invite", | |
| "captcha_token": captcha_token, | |
| "client_id": client_id, | |
| "device_id": device_id, | |
| "meta": { | |
| "captcha_sign": "1." + captcha_sign, | |
| "user_id": user_id, | |
| "package_name": "com.pikcloud.pikpak", | |
| "client_version": "1.52.6", | |
| "timestamp": timestamp | |
| }, | |
| "redirect_uri": "xlaccsdk01://xbase.cloud/callback?state=harbor" | |
| } | |
| headers = { | |
| "X-Device-Id": device_id, | |
| "User-Agent": User_Agent, | |
| } | |
| headers.update(basicRequestHeaders_1) | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers, params=querystring,proxies=proxies, timeout=15) | |
| response.raise_for_status() | |
| log_print("邀请信息检查: ", response.text) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p6 接口报错:{str(E)}") | |
| return {"captcha_token": ""} | |
| def p7(user_id, phoneModel, phoneBuilder, invite_code, captcha_token, device_id, access_token, User_Agent,proxies): | |
| url = "https://api-drive.mypikpak.net/vip/v1/activity/invite?client_id=YNxT9w7GMdWvEOKa" | |
| payload = { | |
| "data": { | |
| "sdk_int": "33", | |
| "uuid": device_id, | |
| "userType": "1", | |
| "userid": user_id, | |
| "userSub": "", | |
| "product_flavor_name": "cha", | |
| "language_system": "zh-CN", | |
| "language_app": "zh-CN", | |
| "build_version_release": "13", | |
| "phoneModel": phoneModel, | |
| "build_manufacturer": phoneBuilder, | |
| "build_sdk_int": "33", | |
| "channel": "official", | |
| "versionCode": "10150", | |
| "versionName": "1.52.6", | |
| "installFrom": "other", | |
| "country": "PL" | |
| }, | |
| "apk_extra": {"channel": "official"} | |
| } | |
| headers ={ | |
| "Host": "api-drive.mypikpak.com", | |
| "authorization": "Bearer " + access_token, | |
| "product_flavor_name": "cha", | |
| "x-captcha-token": captcha_token, | |
| "x-client-version-code": "10150", | |
| "x-device-id": device_id, | |
| "user-agent": User_Agent, | |
| "country": "PL", | |
| "accept-language": "zh-CN", | |
| "x-peer-id": device_id, | |
| "x-user-region": "2", | |
| "x-system-language": "zh-CN", | |
| "x-alt-capability": "3", | |
| "accept-encoding": "gzip", | |
| "content-type": "application/json" | |
| } | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers,proxies=proxies, timeout=15) | |
| response.raise_for_status() | |
| log_print("邀请过程: ", response.text) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p7 接口报错:{str(E)}") | |
| return {} | |
| def p8(user_id, phoneModel, phoneBuilder, invite_code, captcha_token, device_id,access_token, User_Agent,proxies): | |
| url = "https://api-drive.mypikpak.net/vip/v1/order/activation-code?client_id=YNxT9w7GMdWvEOKa" | |
| payload = {"activation_code": invite_code} | |
| headers = { | |
| "Host": "api-drive.mypikpak.com", | |
| "authorization": "Bearer " + access_token, | |
| "product_flavor_name": "cha", | |
| "x-captcha-token": captcha_token, | |
| "x-client-version-code": "10150", | |
| "x-device-id": device_id, | |
| "user-agent": User_Agent, | |
| "country": "DK", | |
| "accept-language": "zh-CN", | |
| "x-peer-id": device_id, | |
| "x-user-region": "2", | |
| "x-system-language": "zh-CN", | |
| "x-alt-capability": "3", | |
| "content-length": "30", | |
| "accept-encoding": "gzip", | |
| "content-type": "application/json" | |
| } | |
| try: | |
| response = requests.request("POST", url, json=payload, headers=headers,proxies=proxies, timeout=15) | |
| response.raise_for_status() | |
| log_print("邀请结果: ", response.text) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p8 接口报错:{str(E)}") | |
| return {} | |
| def p9(user_id, phoneModel, phoneBuilder, captcha_token, device_id, access_token, User_Agent,proxies): | |
| url = "https://api-drive.mypikpak.net/vip/v1/activity/inviteCode?client_id=YNxT9w7GMdWvEOKa" | |
| payload = { | |
| "data": { | |
| "sdk_int": "33", | |
| "uuid": device_id, | |
| "userType": "1", | |
| "userid": user_id, | |
| "userSub": "", | |
| "product_flavor_name": "cha", | |
| "language_system": "zh-CN", | |
| "language_app": "zh-CN", | |
| "build_version_release": "13", | |
| "phoneModel": phoneModel, | |
| "build_manufacturer": phoneBuilder, | |
| "build_sdk_int": "33", | |
| "channel": "official", | |
| "versionCode": "10150", | |
| "versionName": "1.52.6", | |
| "installFrom": "other", | |
| "country": "PL" | |
| }, | |
| "apk_extra": {"channel": "official"} | |
| } | |
| headers ={ | |
| "Host": "api-drive.mypikpak.com", | |
| "authorization": "Bearer " + access_token, | |
| "product_flavor_name": "cha", | |
| "x-captcha-token": captcha_token, | |
| "x-client-version-code": "10150", | |
| "x-device-id": device_id, | |
| "user-agent": User_Agent, | |
| "country": "PL", | |
| "accept-language": "zh-CN", | |
| "x-peer-id": device_id, | |
| "x-user-region": "2", | |
| "x-system-language": "zh-CN", | |
| "x-alt-capability": "3", | |
| "accept-encoding": "gzip", | |
| "content-type": "application/json" | |
| } | |
| try: | |
| response = requests.request("GET", url, json=payload, headers=headers,proxies=proxies, timeout=15) | |
| response.raise_for_status() | |
| a=response.text | |
| log_print("自身邀请码: ", a[a.index(":"):][2:10]) | |
| log_print() | |
| log_print() | |
| return response.json() | |
| except Exception as E: | |
| log_print(f"p9 接口报错:{str(E)}") | |
| return {} | |
| def get_tc(): | |
| log_print("请粘贴 TDC 响应数据(含开头前缀也可,粘贴完成后按【空行】结束输入):") | |
| raw_response = [] | |
| while True: | |
| line = input() | |
| if not line.strip(): | |
| break | |
| raw_response.append(line) | |
| raw_response = '\n'.join(raw_response).strip() | |
| json_match = re.search(r'\{[\s\S]*\}', raw_response, re.DOTALL) | |
| if not json_match: | |
| log_print("错误:未找到合法的 JSON 数据") | |
| exit(1) | |
| valid_json = json_match.group() | |
| try: | |
| data = json.loads(valid_json) | |
| if data.get("errorCode") == "0": | |
| ticket = data.get("ticket") | |
| randstr = data.get("randstr") | |
| log_print("\n提取成功!") | |
| log_print(f"ticket: {ticket}") | |
| log_print(f"randstr: {randstr}") | |
| return {"ticket": f"{ticket}","randstr":f"{randstr}"} | |
| else: | |
| log_print(f"\n验证失败,错误信息:{data.get('errMessage', '未知错误')}") | |
| except json.JSONDecodeError as e: | |
| log_print(f"\nJSON 解析失败:{e}") | |
| # ===================== 注册主流程 ===================== | |
| def run_register_logic(invite_code, join_invite_plan): | |
| global stop_flag | |
| stop_flag = False | |
| y=invite_code if invite_code else A()[0] | |
| c=A()[1] | |
| v=A()[2] | |
| s=A()[3] | |
| a=A()[4] | |
| p=A()[5] | |
| k=A()[6] | |
| t=B()[0] | |
| id=B()[1] | |
| PM=B()[2] | |
| PB=B()[3] | |
| q=get_sign(c+v+a+id+t) | |
| s_w=53 | |
| log_print("—"*s_w) | |
| log_print(datetime.now().strftime('时间:%Y年%m月%d日%H时%M分%S秒')) | |
| log_print() | |
| log_print("手机:",PB) | |
| log_print() | |
| log_print("型号:",PM) | |
| log_print() | |
| log_print("设备:",PB,PM) | |
| log_print() | |
| log_print("时间戳:",t) | |
| log_print() | |
| log_print("设备ID:",id) | |
| log_print() | |
| U=get_ua_key(id,k) | |
| log_print("设备key:",U) | |
| log_print() | |
| u=get_UA(id, U, t, PM, PB) | |
| log_print("设备信息:",u) | |
| log_print() | |
| log_print("—"*s_w) | |
| log_print() | |
| log_print() | |
| log_print("开始准备注册") | |
| e=''.join(random.choice(string.ascii_letters + string.digits) for _ in range(5)) | |
| creat_email(e) | |
| e=e+'@pipk6.fun' | |
| log_print() | |
| log_print("email: ",e) | |
| log_print() | |
| x="" | |
| a=get_txcaptcha() | |
| if stop_flag or not a.get('ticket'): | |
| log_print("打码获取失败,终止注册") | |
| return None | |
| inp=[] | |
| inp.append(a['ticket']+'---'+a['randstr']) | |
| log_print('验证码集合:',inp) | |
| log_print() | |
| xxx=inp[0] | |
| txCaptcha=xxx.split('---')[0] | |
| rand_str=xxx.split('---')[1] | |
| # 循环重试直到获取 captcha_token | |
| s1 = {"captcha_token": ""} | |
| for i in range(6): | |
| if stop_flag: return None | |
| s1 = p1(c, "", id, q, e, t, u,x) | |
| if s1["captcha_token"]: | |
| break | |
| log_print(f"p1 重试 {i+1}/6") | |
| if not s1["captcha_token"]: | |
| log_print("p1 接口多次失败,终止注册") | |
| return None | |
| log_print() | |
| log_print(txCaptcha,rand_str) | |
| # 安全检查重试 | |
| s4 = {"captcha_token": ""} | |
| for i in range(6): | |
| if stop_flag: return None | |
| s4 = part5_1(id,s1["captcha_token"],'','','',u,s1.get('url',''),'',txCaptcha,rand_str) | |
| if s4["captcha_token"]: | |
| break | |
| log_print(f"part5_1 重试 {i+1}/6") | |
| if not s4["captcha_token"]: | |
| log_print("part5_1 接口多次失败,终止注册") | |
| return None | |
| # 发送验证码重试 | |
| s5 = {"verification_id": ""} | |
| for i in range(6): | |
| if stop_flag: return None | |
| s5 = p2(c,s4["captcha_token"],e, id, u,x) | |
| if s5.get('verification_id'): | |
| break | |
| log_print(f"p2 重试 {i+1}/6") | |
| if not s5.get('verification_id'): | |
| log_print("p2 接口多次失败,终止注册") | |
| return None | |
| # 读取验证码 | |
| verification_code = 0 | |
| for i in range(666): | |
| if stop_flag: return None | |
| verification_code = 读邮件(e) | |
| if verification_code!=0: | |
| break | |
| log_print(f"等待验证码... {i+1}") | |
| if verification_code == 0: | |
| log_print("未获取到验证码,终止注册") | |
| return None | |
| # 提交验证码重试 | |
| s6 = {"verification_token": ""} | |
| for i in range(6): | |
| if stop_flag: return None | |
| s6 = p3(c,s5['verification_id'], verification_code,id,u,x) | |
| if s6.get('verification_token'): | |
| break | |
| log_print(f"p3 重试 {i+1}/6") | |
| if not s6.get('verification_token'): | |
| log_print("p3 接口多次失败,终止注册") | |
| return None | |
| # 安全信息提交重试 | |
| s7 = {"captcha_token": ""} | |
| for i in range(6): | |
| if stop_flag: return None | |
| s7 = p4(c, s1["captcha_token"],id,q,e,t,u,x) | |
| if s7["captcha_token"]: | |
| break | |
| log_print(f"p4 重试 {i+1}/6") | |
| if not s7["captcha_token"]: | |
| log_print("p4 接口多次失败,终止注册") | |
| return None | |
| n= e.split("@")[0] | |
| # 注册提交重试 | |
| s8 = {"sub": ""} | |
| for i in range(6): | |
| if stop_flag: return None | |
| s8 = p5(c,s7['captcha_token'],s,e,n,p,s6['verification_token'],id,u,x) | |
| if s8.get('sub'): | |
| break | |
| log_print(f"p5 重试 {i+1}/6") | |
| if not s8.get('sub'): | |
| log_print("p5 接口多次失败,终止注册") | |
| return None | |
| # 邀请码填写逻辑 | |
| if invite_code: | |
| s9 = {"captcha_token": ""} | |
| for i in range(6): | |
| if stop_flag: return None | |
| s9 = p6(c,s7['captcha_token'],id,q,s8['sub'],t,u,x) | |
| if s9["captcha_token"]: | |
| break | |
| log_print(f"p6 重试 {i+1}/6") | |
| if s9["captcha_token"]: | |
| for i in range(6): | |
| if stop_flag: return None | |
| a=p7(s8['sub'],PM,PB,y,s9['captcha_token'],id,s8.get('access_token',''),u,x) | |
| if a:break | |
| log_print(f"p7 重试 {i+1}/6") | |
| for i in range(6): | |
| if stop_flag: return None | |
| s11=p8(s8['sub'],PM,PB,y,s9['captcha_token'],id,s8.get('access_token',''),u,x) | |
| if s11:break | |
| log_print(f"p8 重试 {i+1}/6") | |
| # 邀请计划加入 | |
| if join_invite_plan: | |
| try: | |
| response = requests.post('https://api-referral.mypikpak.net/promoting/v1/join',headers ={"authorization": "Bearer " + s8.get('access_token','')}, timeout=15) | |
| log_print("邀请计划加入响应:", response.text) | |
| except Exception as e: | |
| log_print(f"邀请计划加入报错:{str(e)}") | |
| # 文件分享 | |
| for i in range(6): | |
| if stop_flag: return None | |
| try: | |
| access_token = s8.get('access_token','') | |
| if not access_token: | |
| break | |
| file_response = requests.get('https://api-drive.mypikpak.net/drive/v1/files?parent_id=*&page_token=&with_audit=true&thumbnail_size=SIZE_LARGE&filters=%7B%22phase%22%3A%7B%22eq%22%3A%22PHASE_TYPE_COMPLETE%22%7D%7D&space=*&limit=5',headers ={"authorization": "Bearer " + access_token}, timeout=15) | |
| file_data = file_response.json() | |
| file_id = file_data['files'][0]['id'] | |
| share_response = requests.post('https://pipkzf.pipk7.top/?url=https://api-drive.mypikpak.net/drive/v1/share',headers ={"authorization": "Bearer " + access_token},json={"file_ids":[f"{file_id}"],"share_to":"publiclink","expiration_days":-1,"pass_code_option":"NOT_REQUIRED"}, timeout=15) | |
| log_print("文件分享响应:", share_response.text) | |
| break | |
| except Exception as E: | |
| log_print(f"文件分享报错:{str(E)}") | |
| # 输出结果 | |
| log_print("—"*s_w) | |
| log_print("email: ",e) | |
| log_print("password: ",p) | |
| log_print("—"*s_w) | |
| return {"email": e, "password": p} | |
| # ===================== 路由 ===================== | |
| def index(): | |
| return render_template("index.html") | |
| def api_log(): | |
| with logs_lock: | |
| return "\n".join(app_logs) | |
| def api_status(): | |
| return jsonify({"is_running": is_running}) | |
| def api_accounts(): | |
| return jsonify(load_accounts()) | |
| def api_save(): | |
| data = request.get_json() | |
| _id = data.get("id") | |
| email = data.get("email").strip() | |
| pwd = data.get("pwd").strip() | |
| accounts = load_accounts() | |
| if _id: | |
| for a in accounts: | |
| if a["id"] == int(_id): | |
| a["email"] = email | |
| a["pwd"] = pwd | |
| break | |
| else: | |
| new_id = max([a.get("id",0) for a in accounts], default=0) + 1 | |
| accounts.append({"id": new_id, "email": email, "pwd": pwd}) | |
| save_accounts(accounts) | |
| return jsonify({"ok": True}) | |
| def api_delete(): | |
| _id = request.get_json()["id"] | |
| accounts = [a for a in load_accounts() if a["id"] != _id] | |
| save_accounts(accounts) | |
| return jsonify({"ok": True}) | |
| def api_batch_delete(): | |
| ids = request.get_json()["ids"] | |
| accounts = [a for a in load_accounts() if a["id"] not in ids] | |
| save_accounts(accounts) | |
| return jsonify({"ok": True}) | |
| def api_batch_import(): | |
| accounts = request.get_json()["accounts"] | |
| existing = load_accounts() | |
| max_id = max([a.get("id",0) for a in existing], default=0) | |
| for acc in accounts: | |
| max_id += 1 | |
| existing.append({"id": max_id, "email": acc["email"], "pwd": acc["pwd"]}) | |
| save_accounts(existing) | |
| return jsonify({"ok": True}) | |
| def api_start(): | |
| global app_logs, is_running, current_log_file, stop_flag | |
| if is_running: | |
| return jsonify({"ok": False, "msg": "已有任务在运行"}) | |
| app_logs = [] | |
| stop_flag = False | |
| run_timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") | |
| current_log_file = os.path.join(LOGS_DIR, f"run_{run_timestamp}.log") | |
| log_print("=" * 40) | |
| log_print(f"新注册任务开始:{run_timestamp}") | |
| log_print("=" * 40) | |
| data = request.get_json() or {} | |
| invite_code = data.get("invite_code", "").strip() | |
| join_invite_plan = data.get("join_invite_plan", False) | |
| is_running = True | |
| def task(): | |
| global is_running | |
| try: | |
| account = run_register_logic(invite_code, join_invite_plan) | |
| if account and not stop_flag: | |
| accounts = load_accounts() | |
| new_id = max([a.get("id",0) for a in accounts], default=0) + 1 | |
| accounts.append({"id": new_id, "email": account["email"], "pwd": account["password"]}) | |
| save_accounts(accounts) | |
| log_print("注册任务完成,账号已保存") | |
| except Exception as e: | |
| log_print(f"注册任务异常:{str(e)}") | |
| finally: | |
| is_running = False | |
| threading.Thread(target=task, daemon=True).start() | |
| return jsonify({"ok": True, "msg": "任务已启动"}) | |
| def api_stop(): | |
| global stop_flag, is_running | |
| stop_flag = True | |
| is_running = False | |
| log_print("用户手动停止注册任务") | |
| return jsonify({"ok": True}) | |
| def api_log_files(): | |
| date = request.args.get("date") | |
| if not date: return jsonify([]) | |
| files = [] | |
| for f in os.listdir(LOGS_DIR): | |
| if f.startswith(f"run_{date}"): | |
| files.append(f) | |
| files.sort() | |
| return jsonify(files) | |
| def api_log_content(): | |
| filename = request.args.get("file") | |
| if not filename: return "" | |
| path = os.path.join(LOGS_DIR, filename) | |
| if not os.path.exists(path): return "" | |
| with open(path, "r", encoding="utf-8") as f: | |
| return f.read() | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860, debug=False) | |