别人点击个人用户后会出现,用户的ID、名称、余额、创建时间想求解各位程序员为我讲解一下
这个你可以用模拟点击的方式,比如说“按键精灵”脚本实现。
不知道你这个问题是否已经解决, 如果还没有解决的话:解决方案: 1. 首先需要在Telegram上创建一个机器人,获取机器人的token。若不清楚如何创建Telegram机器人,请参考Telegram官方文档。
代码:
import requests
import json
def get_updates(token):
url = "https://api.telegram.org/bot" + token + "/getUpdates"
response = requests.get(url)
content = json.loads(response.content.decode("utf8"))
return content["result"]
代码:
def get_user_info(token, chat_id):
url = "https://api.telegram.org/bot" + token + "/getUserProfilePhotos"
params = {
"user_id": chat_id
}
response = requests.get(url, params=params)
content = json.loads(response.content.decode("utf8"))
photos = content["result"]["photos"]
photo = photos[0][-1]
user_photo_path = download_file(token, photo["file_id"]) # 先下载用户头像
url = "https://api.telegram.org/bot" + token + "/getChat"
params = {
"chat_id": chat_id
}
response = requests.get(url, params=params)
content = json.loads(response.content.decode("utf8"))
username = content["result"]["username"]
first_name = content["result"]["first_name"]
last_name = content["result"].get("last_name", "")
full_name = first_name + " " + last_name
creation_date = content["result"]["date"]
user_info = {
"user_photo_path": user_photo_path,
"username": username,
"full_name": full_name,
"creation_date": creation_date,
}
return user_info
代码:
def download_file(token, file_id):
url = "https://api.telegram.org/bot" + token + "/getFile"
params = {
"file_id": file_id
}
response = requests.get(url, params=params)
content = json.loads(response.content.decode("utf8"))
file_path = content["result"]["file_path"]
file_url = "https://api.telegram.org/file/bot" + token + "/" + file_path
response = requests.get(url)
with open(file_path, "wb") as f:
f.write(response.content)
return file_path
以上是获取Telegram机器人中个人用户的信息的实现步骤,具体的实现还需要根据具体的业务逻辑进行处理。