tel 修复 API

This commit is contained in:
Ricky8955555 2023-06-19 16:58:14 +08:00 committed by GitHub
parent df0f55f73a
commit 36b0ad7627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,42 +1,26 @@
import json from pagermaid.enums import AsyncClient
import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
from requests import get
from pyrogram import Client
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import Message from pagermaid.utils import Message
@listener(command="tel", @listener(command="tel", description="手机号码归属地等信息查询。")
description="手机号码归属地等信息查询。") async def tel(message: Message, request: AsyncClient):
async def tel(_: Client, context: Message): if not (phone := message.arguments.strip()).isnumeric():
await context.edit("获取中 . . .") return await message.edit("出错了呜呜呜 ~ 无效的参数。")
try: message = await message.edit("获取中 . . .") # type: ignore
message = context.arguments res = await request.post("https://tenapi.cn/v2/phone", params={"tel": phone})
except ValueError: data = None
await context.edit("出错了呜呜呜 ~ 无效的参数。") if res.is_success and (data := res.json())["code"] == 200:
return data = data["data"]
req = get(f"https://tenapi.cn/tel?tel={message}") await message.edit(
if req.status_code == 200: f"查询目标: {phone}\n"
data = json.loads(req.text) f"地区: {data['local']}\n"
res = ( f"号段: {data['num']}\n"
data['msg'] f"卡类型: {data['type']}\n"
if 'msg' in data f"运营商: {data['isp']}\n"
else '电话号码:' f"通信标准: {data['std']}"
+ str(data['tel'])
+ '\n'
+ str(data['local'])
+ '\n'
+ str(data['duan'])
+ '\n'
+ str(data['type'])
+ '\n'
+ str(data['yys'])
+ '\n'
+ str(data['bz'])
) )
await context.edit(res)
else: else:
await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。") await message.edit(
"出错了呜呜呜 ~ API 服务器返回了错误。" + ("\n" + data.get("msg") if data else "")
)