telegram判断手机号是否注册(2020.12.24)

说明:
1、api_id,api_hash,需要注册开发者,非常容易获取
2、Telethon (0.19),版本需要安装0.19,新版本不支持添加好友方法
3、可以直接放在境外服务器运行,如在本地运行,需要加socket代理,详见代码

# -*- coding:utf-8 -*-
# !/usr/bin/env python3

from telethon import TelegramClient
from telethon.tl.types import InputPhoneContact
from telethon.tl.functions.contacts import ImportContactsRequest
import random
import time

name_list = [i for i in range(100)]# 用于构造每次加好友的备注
phone_list = [
    '130********',
    '130********'
]# 待验证的手机号列表

api_id = ******
api_hash = ******
phone_number = ******
# 添加好友的手机号的开发者信息

client = TelegramClient('session_name', api_id, api_hash)
# client = TelegramClient('session_name', api_id, api_hash, proxy=(socks.SOCKS5, 'localhost', *****))

assert client.connect()# 客户端登录状态
if not client.is_user_authorized():
    client.send_code_request(phone_number)
    me = client.sign_in(phone_number, input('Enter code: '))
    
for phone in phone_list:# 验证处理
    phone_num = '+86' + phone
    print('-'*50)
    print(phone_num)
    contact = InputPhoneContact(client_id=0, phone=phone_num, first_name="zhang{}".format(random.choice(name_list)), last_name="san{}".format(random.choice(name_list)))
    result = client.invoke(ImportContactsRequest([contact]))
    print(result)
    print()
    time.sleep(5)

参考:https://blog.csdn.net/weixin_42156283/article/details/103075212

猜你喜欢

转载自blog.csdn.net/msq16021/article/details/111625736