兼容虎牙四段账号格式
支持虎牙号、密码、手机号、验证码链接导入,并补充美国等国际手机号格式处理。
This commit is contained in:
+131
-4
@@ -36,6 +36,108 @@ SMS_CODE_URL = "https://udblgn.huya.com/web/v2/smsCode"
|
||||
SMS_LOGIN_URL = "https://udblgn.huya.com/web/v2/smsLogin"
|
||||
DF_TOKEN_URL = "https://df.huya.com/web/df/token"
|
||||
DF_COLLECT_URL = "https://df.huya.com/web/df/collect"
|
||||
HUYA_COUNTRY_CALLING_CODES = frozenset({
|
||||
"1",
|
||||
"7",
|
||||
"20",
|
||||
"27",
|
||||
"30",
|
||||
"31",
|
||||
"32",
|
||||
"33",
|
||||
"34",
|
||||
"36",
|
||||
"39",
|
||||
"40",
|
||||
"41",
|
||||
"43",
|
||||
"44",
|
||||
"45",
|
||||
"46",
|
||||
"47",
|
||||
"48",
|
||||
"49",
|
||||
"52",
|
||||
"55",
|
||||
"60",
|
||||
"61",
|
||||
"62",
|
||||
"63",
|
||||
"64",
|
||||
"65",
|
||||
"66",
|
||||
"81",
|
||||
"82",
|
||||
"84",
|
||||
"86",
|
||||
"90",
|
||||
"91",
|
||||
"92",
|
||||
"93",
|
||||
"94",
|
||||
"95",
|
||||
"98",
|
||||
"212",
|
||||
"213",
|
||||
"216",
|
||||
"218",
|
||||
"234",
|
||||
"254",
|
||||
"351",
|
||||
"352",
|
||||
"353",
|
||||
"354",
|
||||
"355",
|
||||
"356",
|
||||
"357",
|
||||
"358",
|
||||
"359",
|
||||
"370",
|
||||
"371",
|
||||
"372",
|
||||
"373",
|
||||
"374",
|
||||
"375",
|
||||
"376",
|
||||
"377",
|
||||
"378",
|
||||
"380",
|
||||
"381",
|
||||
"382",
|
||||
"385",
|
||||
"386",
|
||||
"387",
|
||||
"389",
|
||||
"420",
|
||||
"421",
|
||||
"852",
|
||||
"853",
|
||||
"855",
|
||||
"856",
|
||||
"886",
|
||||
"960",
|
||||
"961",
|
||||
"962",
|
||||
"963",
|
||||
"964",
|
||||
"965",
|
||||
"966",
|
||||
"967",
|
||||
"968",
|
||||
"971",
|
||||
"972",
|
||||
"973",
|
||||
"974",
|
||||
"975",
|
||||
"976",
|
||||
"977",
|
||||
"992",
|
||||
"993",
|
||||
"994",
|
||||
"995",
|
||||
"996",
|
||||
"998",
|
||||
})
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -52,13 +154,36 @@ class HuyaSmsCodeResult:
|
||||
request_id: str = ""
|
||||
|
||||
|
||||
def _split_country_calling_code(digits: str) -> tuple[str, str]:
|
||||
"""从国际号码中拆出国家/地区区号。"""
|
||||
for size in (3, 2, 1):
|
||||
code = digits[:size]
|
||||
if code in HUYA_COUNTRY_CALLING_CODES and len(digits) > size:
|
||||
return code, digits[size:]
|
||||
return "", digits
|
||||
|
||||
|
||||
def _format_huya_international_phone(code: str, national_number: str) -> str:
|
||||
"""转换成虎牙短信接口使用的三位区号格式。"""
|
||||
return f"{code.zfill(3)}{national_number}"
|
||||
|
||||
|
||||
def normalize_huya_phone(phone: str) -> str:
|
||||
"""归一化虎牙短信接口手机号格式。"""
|
||||
"""归一化虎牙短信接口手机号格式,兼容国内号和显式国际区号。"""
|
||||
raw = str(phone or "").strip()
|
||||
digits = "".join(ch for ch in raw if ch.isdigit())
|
||||
if raw.startswith("+1") and len(digits) == 11:
|
||||
return f"001{digits[1:]}"
|
||||
if digits.startswith("001") and len(digits) == 13:
|
||||
if not digits:
|
||||
return ""
|
||||
if raw.startswith("+"):
|
||||
code, national_number = _split_country_calling_code(digits)
|
||||
if code:
|
||||
return _format_huya_international_phone(code, national_number)
|
||||
if digits.startswith("00") and len(digits) > 4:
|
||||
code, national_number = _split_country_calling_code(digits[2:])
|
||||
if code:
|
||||
return _format_huya_international_phone(code, national_number)
|
||||
return digits
|
||||
if digits.startswith("0") and len(digits) > 11:
|
||||
return digits
|
||||
if digits.startswith("086"):
|
||||
return digits
|
||||
@@ -66,6 +191,8 @@ def normalize_huya_phone(phone: str) -> str:
|
||||
return f"0{digits}"
|
||||
if len(digits) == 11:
|
||||
return f"086{digits}"
|
||||
if len(digits) == 10:
|
||||
return f"001{digits}"
|
||||
return digits
|
||||
|
||||
|
||||
|
||||
+19
-6
@@ -6,6 +6,7 @@ import json
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
|
||||
@@ -42,24 +43,36 @@ class SmsPollResult:
|
||||
|
||||
|
||||
def parse_sms_lines(text: str) -> list[SmsLine]:
|
||||
"""解析手机号池,每行格式:手机号----查询URL。"""
|
||||
"""解析手机号池,兼容手机号----查询URL、账号----密码----手机号----查询URL。"""
|
||||
rows: list[SmsLine] = []
|
||||
for raw_line in (text or "").splitlines():
|
||||
line = raw_line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
parts = [part.strip() for part in line.split("----", 1)]
|
||||
if len(parts) != 2 or not parts[0] or not parts[1]:
|
||||
parts = [part.strip() for part in line.split("----")]
|
||||
if len(parts) >= 4 and _looks_like_url("----".join(parts[3:])):
|
||||
phone, url = parts[2], "----".join(parts[3:]).strip()
|
||||
elif len(parts) >= 2 and _looks_like_url("----".join(parts[1:])):
|
||||
phone, url = parts[0], "----".join(parts[1:]).strip()
|
||||
else:
|
||||
continue
|
||||
if not phone or not url:
|
||||
continue
|
||||
rows.append(SmsLine(
|
||||
phone=parts[0],
|
||||
url=parts[1],
|
||||
provider=detect_provider(parts[1]),
|
||||
phone=phone,
|
||||
url=url,
|
||||
provider=detect_provider(url),
|
||||
raw=line,
|
||||
))
|
||||
return rows
|
||||
|
||||
|
||||
def _looks_like_url(value: str) -> bool:
|
||||
"""判断文本是否像 URL。"""
|
||||
parsed = urlparse(str(value or "").strip())
|
||||
return parsed.scheme in {"http", "https"} and bool(parsed.netloc)
|
||||
|
||||
|
||||
def detect_provider(url: str) -> str:
|
||||
"""根据 URL 判断接码平台类型。"""
|
||||
text = (url or "").lower()
|
||||
|
||||
Reference in New Issue
Block a user