Files
telegram-customer-bot/create_session_correct.py
2025-11-01 21:58:31 +08:00

73 lines
1.9 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
创建 Pyrogram Session - 使用代理
执行此脚本后,按照提示输入手机号码和验证码
"""
import sys
from pyrogram import Client
API_ID = 24660516
API_HASH = "eae564578880a59c9963916ff1bbbd3a"
# 使用代理配置
proxy = {
"scheme": "socks5",
"hostname": "127.0.0.1",
"port": 1080
}
print("=" * 60)
print("Pyrogram Session 创建工具")
print("=" * 60)
print(f"API ID: {API_ID}")
print(f"代理: SOCKS5://127.0.0.1:1080")
print("Session 文件: user_session.session")
print("=" * 60)
print("\n准备连接到 Telegram...")
print("请准备好您的:")
print(" 1. 手机号码(国际格式,例如:+66621394851")
print(" 2. Telegram 验证码(将发送到您的手机)")
print("=" * 60)
print()
try:
app = Client(
"user_session",
api_id=API_ID,
api_hash=API_HASH,
proxy=proxy
)
print("正在启动客户端...")
app.start()
print("\n正在获取账户信息...")
me = app.get_me()
print("\n" + "=" * 60)
print("✅ Session 创建成功!")
print("=" * 60)
print(f"账户名称: {me.first_name} {me.last_name or ''}")
print(f"用户名: @{me.username or 'N/A'}")
print(f"用户 ID: {me.id}")
print(f"手机号: {me.phone_number or 'N/A'}")
print("=" * 60)
print(f"\nSession 文件已创建: user_session.session")
print("可以开始使用镜像功能了!")
print("=" * 60)
app.stop()
print("\n客户端已关闭")
except KeyboardInterrupt:
print("\n\n操作已取消")
sys.exit(1)
except Exception as e:
print(f"\n❌ 错误: {e}")
print("\n可能的原因:")
print(" 1. 代理不可用 - 请检查 SOCKS5 代理是否运行")
print(" 2. 网络连接问题")
print(" 3. API 凭证无效")
print(" 4. 手机号或验证码错误")
sys.exit(1)