WhatsApp 与 Telegram 号码查询:查一边还是两边?
| 手里有什么 | 该买哪一次签发 | 别买、别混 |
|---|---|---|
| 手机号,发送通道已经定成 WhatsApp | check-exist-by-phone | Telegram;isExist 还不是 True 就去拉资料 |
只有 @some_username,没有号码 | check-exists | WhatsApp,它不收用户名 |
| 同一个联系人,两条网络都可能用 | 两边都查,两张 userHash | 一个缓存键、一个「已注册」布尔值 |
| 要商家名片、最后在线或 WhatsApp 签名 | 用 WhatsApp 的 hash 打资料口 | Telegram 的 hash;那边没有名片口 |
| 要 Telegram 简介或头像 | 用 Telegram 的 hash | WhatsApp 的 hash,那边会拒 |
这张表就是选择本身。客服队列已经只走 WhatsApp,就不要为 Telegram 再付一次存在性;运营手里只有 handle、名单来自频道,就不要把 @用户名 硬塞进 WhatsApp。通道还没定、或者两条都要发,才两边都查。本文不是第三篇存在性教程。WhatsApp 号码查询写签发,Telegram 号码检测写签发。这里只决定:为同一个联系人付哪一次签发,以及两张 hash 为什么不能共用。
从控制台取一把授权 key 就够打两个 project(没有账户先登录)。服务器读 OPENDATA_API_KEY。key 走查询字符串,不要进工单、截图和仓库。打开本页或复制示例不会发查询;跑脚本才会,每个 project 各自扣点。
一个号码是两个独立答案
+15551234567 是一个号码、两道题。WhatsApp 只回答「这号有没有 WhatsApp 账户」。Telegram 只回答「这个 peer 在不在 Telegram」。两边互不查阅。WhatsApp 命中不是 Telegram 的证据,Telegram 未命中也不是 WhatsApp 的证据。把一个国家的「主流 App」印象当成覆盖率,会在真正的名单上失手:命中率随市场变,抽样自己的名单,不要默认 WhatsApp 永远赢。
只跑 WhatsApp 的典型情况:下一步就是 get-biz-profile、get-avatar、get-about 或 get-presence——商家入驻、客服排队、只往 WhatsApp 发的名单。只跑 Telegram 的典型情况:你只有用户名、user:<id>,或者受众就在频道和群里。WhatsApp 没有用户名入口,不能把 @some_username 塞进 check-exist-by-phone。两边都跑 的典型情况:同一号码可能在任一网络可达,用结果选通道,而不是先赌一边再拿另一边当「确认」。多渠道打分见线索核验工作流;本页只裁这两边。
不要因为一边命中就省掉另一边。覆盖率不是传递性。WhatsApp 上有人,Telegram 上可以没有;handle 社区里反过来也很常见。真要两个答案,就付两次存在性读取。发送通道已经定了,只买那一边。
两边的检查各自返回什么
两边都是便宜的存在性读取,只在账户存在时签发 24 小时 userHash,缺失、未知或过期的 hash 在重接口上会被拒。相似到此为止。hash 不能互换。把 WhatsApp 的 hash 交给 Telegram get-about,只是一张废票,不会「顺便」拿到简介。
WhatsApp check-exist-by-phone 吃 phoneNumber:完整国际号数字,+、空格、短横、00 前缀都能过。15551234567 是形态示例,不保证是活号。isExist 三态:true、false、null(不确定——重试检查,不要补资料)。true 时才有 userHash 和 hasExtra。batch-check-10 一次最多十个号,不签发 hash。check-active 给活跃标记,也不签发。下一步要资料,仍然得走 check-exist。国家码和国内号已分列时,用 check-exist-by-cc-phone,不必自己拼接。
Telegram check-exists 吃 peer:+手机号(必须带 +;requests 会编码,手写 URL 写成 %2B)、@用户名 / 裸用户名、user:<id>。exists 为 true 或 false,干净未占用时 reason 例如 PHONE_NOT_OCCUPIED。命中还给数字用户 id、用户名、显示名和 userHash。没有批量,没有商家名片。get-picture 返回 base64 data 和 pictureSet;get-about 返回简介。peer 是群或频道是业务失败,不是个人。选型时记住这条差异:要店铺名片和受隐私限制的在线状态,只有 WhatsApp;要解析用户名,只有 Telegram。
HTTP 成功不是注册标记。先看 HTTP 状态,再看网关信封 {code, message, data}。code=200 表示检查送达,这之后才读 isExist 或 exists。缺 key、校验失败、传输失败是 4xx/5xx 或 code 非 200——没有裁决,不要写成 false。data 可能包不止一层,拆到内层字段为止。送达的 WhatsApp null 仍是不确定,不是崩溃。送达的 Telegram exists=false 带 reason 是干净未命中,不要当传输失败重试。完整消耗路径回各自指南;本页只卡住一件事:不要把消耗调用指到另一张网络的 hash。
一份脚本、两张 hash、不要混缓存
下面这份脚本就是选择器:按 channels 决定打哪一边,两次 GET 也是两份记录。它不会把两个旗标做或运算,也不会只存一张 userHash。安装 requests,导出 OPENDATA_API_KEY,在服务器上跑。号码和用户名是文档形态,不保证命中。
import os
from datetime import datetime, timedelta, timezone
import requests
ROOT = "https://api.opendata-api.com/api/project"
KEY = os.environ["OPENDATA_API_KEY"].strip()
TTL = timedelta(hours=24)
# Separate caches. A WhatsApp hash is not a Telegram hash.
WA_CACHE = {} # digits -> record
TG_CACHE = {} # peer -> record
def unwrap(body):
while isinstance(body, dict) and "code" in body and isinstance(
body.get("data"), (dict, list)
):
body = body["data"]
return body
def call(project, operation, **params):
try:
response = requests.get(
f"{ROOT}/{project}/{operation}",
params={"key": KEY, **params},
timeout=30,
)
except requests.RequestException:
raise RuntimeError("Transport failure; inspect redacted logs") from None
if not 200 <= response.status_code < 300:
raise RuntimeError(f"HTTP failure: {response.status_code}")
try:
envelope = response.json()
except ValueError:
raise RuntimeError("Expected JSON") from None
if not isinstance(envelope, dict) or envelope.get("code") != 200:
raise RuntimeError("Gateway business failure; no registration verdict")
data = unwrap(envelope)
return data if isinstance(data, dict) else {}
def check_whatsapp(number):
digits = number.lstrip("+")
now = datetime.now(timezone.utc)
cached = WA_CACHE.get(digits)
if cached and cached["expires_at"] > now:
return cached
wa = call("whatsapp", "check-exist-by-phone", phoneNumber=digits)
record = {
"isExist": wa.get("isExist"), # True, False, or None
"userHash": wa.get("userHash"),
"checked_at": now,
"expires_at": now + TTL,
}
WA_CACHE[digits] = record
return record
def check_telegram(peer):
now = datetime.now(timezone.utc)
cached = TG_CACHE.get(peer)
if cached and cached["expires_at"] > now:
return cached
tg = call("telegram", "check-exists", peer=peer)
record = {
"exists": tg.get("exists"),
"reason": tg.get("reason"),
"userHash": tg.get("userHash"),
"checked_at": now,
"expires_at": now + TTL,
}
TG_CACHE[peer] = record
return record
def lookup(number=None, handle=None, channels=("whatsapp", "telegram")):
"""Call only the networks you will actually use. Never merge the flags."""
out = {}
if number and "whatsapp" in channels:
out["whatsapp"] = check_whatsapp(number)
if "telegram" in channels:
peer = handle or (("+" + number.lstrip("+")) if number else None)
if not peer:
raise ValueError("Telegram needs a phone peer or a handle")
out["telegram"] = check_telegram(peer)
return out
# Documented shapes, not guaranteed hits.
print(lookup(number="+15551234567", channels=("whatsapp",)))
print(lookup(handle="@some_username", channels=("telegram",)))
print(lookup(number="+15551234567")) # both, two hashes
每张 hash 只在自己的 24 小时窗口、自己的 project 上复用。为了「刷新」Telegram 票去重打 WhatsApp,既浪费点数,也拿不到 Telegram hash。干净未命中按网络分别缓存,避免同一边把 false 买两遍。WhatsApp 用 is True / is False / is None 分类——Python 真值会把 null 和未命中混在一起,线索表就会把「还没查清」写成「没注册」。后面若要发消息,WhatsApp 发送指南和 Telegram 发送指南都从该网络已经通过的收件人开始。
不要把两个注册标记合成一个
下面这些是反目标。踩上去,选择器就会变成一张撒谎的线索表:发送方看不出该走哪条网,补资料时还会拿错票。
- 不要写
registered = wa_isExist or tg_exists。这个布尔值告诉不了发送方该走哪条网,还会用 Telegram 命中盖住 WhatsApp 的null。 - 不要把
wa_hash塞进 Telegramget-about/get-picture,或把tg_hash塞进 WhatsAppget-avatar/get-about/get-biz-profile。消耗接口只认自己检查签发的 hash。 - 不要把 WhatsApp
isExist is None当成 Telegramexists is False,或当成可以跳过 Telegram 的许可。 - 不要因为第一次命中就跳过第二次。独立网络不会互相暗示。
- 不要用一个 E.164 键缓存一张 hash。WhatsApp 用数字做键,Telegram 用
peer,每行自带checked_at。 - 不要把 HTTP 2xx 或网关
code=200当成「两边都注册了」。送达不是存在。 - 不要把用户名硬塞进 WhatsApp,也不要给 Telegram 的手机
peer丢掉加号。 - 任何一边都不要在旗标还不是真正命中时去补资料。命中之后简介为空、没有头像仍是正常结果,不是传输错误。
这一行只需要一条通道,就只付一次检查。这一行两条通道都要,就付两次、留两张 hash。不要付一次,却假装已经认识了两张网络。