1. 程式人生 > 其它 >telegram判斷手機號是否註冊(2020.12.24)

telegram判斷手機號是否註冊(2020.12.24)

技術標籤:Pythonpython

說明:
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