├── README.md └── user.py /README.md: -------------------------------------------------------------------------------- 1 | # Telegram-QRCode 2 | 此py文件可以获取TG登录后的session信息 3 | 4 | 使用方法: 5 | 6 | 通过 https://my.telegram.org 申请ID和HASH,将Py文件中的TELEGRAM_API_ID和TELEGRAM_API_HASH修改为自己的 7 | 8 | pip install telethon 9 | 10 | pip install qrcode 11 | 12 | python3 user.py 13 | 14 | 35行的SessionName,可以修改成想要的session文件名 15 | -------------------------------------------------------------------------------- /user.py: -------------------------------------------------------------------------------- 1 | import telethon 2 | from telethon import TelegramClient 3 | from qrcode import QRCode 4 | from base64 import urlsafe_b64encode as base64url 5 | 6 | qr = QRCode() 7 | 8 | def gen_qr(token:str): 9 | qr.clear() 10 | qr.add_data(token) 11 | qr.print_ascii() 12 | 13 | def display_url_as_qr(url): 14 | print(url) # do whatever to show url as a qr to the user 15 | gen_qr(url) 16 | 17 | async def main(client: telethon.TelegramClient): 18 | if(not client.is_connected()): 19 | await client.connect() 20 | client.connect() 21 | qr_login = await client.qr_login() 22 | print(client.is_connected()) 23 | r = False 24 | while not r: 25 | display_url_as_qr(qr_login.url) 26 | # Important! You need to wait for the login to complete! 27 | try: 28 | r = await qr_login.wait(10) 29 | except: 30 | await qr_login.recreate() 31 | 32 | TELEGRAM_API_ID=XXXX 33 | TELEGRAM_API_HASH=XXXX 34 | 35 | client = TelegramClient("SessionName", TELEGRAM_API_ID, TELEGRAM_API_HASH) 36 | client.loop.run_until_complete(main(client)) 37 | --------------------------------------------------------------------------------