为 Telegram API 创建授权密钥后的步骤 [英] Steps after creating Authorization Key for Telegram API

查看:340
本文介绍了为 Telegram API 创建授权密钥后的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在忙于实现 Telegram API 的 C# 版本,但我被卡住了.我已经成功地想出了如何创建授权密钥,但我不知道从哪里开始.有谁知道创建授权密钥后的下一步?文档很难遵循.

I've been messing with implementing a C# version of the Telegram API, but I am stuck. I've successfully figured out how to create an Authorization Key, but I don't know where to go from here. Does anyone know the next step after creating an Authorization Key? The documentation is so difficult to follow.

参考:Telegram API

注意:我没有使用 Bot API.我正在尝试使用常规 API.

Note: I am not using the Bot API. I'm trying to use the regular API.

推荐答案

在创建您的 Auth_key 后,我发现在继续之前确保我已连接到最近的数据中心最容易.此外,您应该发送一个 InitConnection 命令以及您的代码将使用的当前层(API 版本).

After creating your Auth_key I find it easiest to ensure I am connected to my nearest DataCenter before I proceed. Also you should send an InitConnection command along with the current layer (API version) that your code will be working with.

这是我发送的示例:

msg = TL.invokewithlayer(@layer, TL.initconnection(@app_id, @device_model, @system_version, @app_version, @lang_code, TL.help_getnearestdc))

msg = TL.invokewithlayer(@layer, TL.initconnection(@app_id, @device_model, @system_version, @app_version, @lang_code, TL.help_getnearestdc))

在您发送此内容之前,请先了解更多背景信息:

Now before you send this here is some more background:

1) Telegram 服务器在 TL 中通信,它基本上是一种定制开发的编码方案,Telegram 使用它来表达一切:从命令到所有类型.您需要自己构建一个解码器和编码器,用于将原始字节转换为 TL,反之亦然.

1) Telegram Servers communicate in TL, what it is basically is a custom developed encoding scheme that Telegram uses to express everything: from commands to all it's types. You would need to build yourself a decoder and encoder for converting raw bytes into TL and vice-versa.

2) Telegram 不时更新他们的 API 版本,但他们网站上的版本已经过时.您可以轻松获取他们官方开源项目的最新 API 规范.特别是 this 和 <来自 Webogram 的 href="https://github.com/zhukov/webogram/blob/master/app/js/lib/schema.tl.txt" rel="noreferrer">this 对于生成你自己的 TL 解析器.当前图层版本为45

2) Telegram updates their API versions from time to time, but the version on their site is outdated. You can easily get the latest API spec of their Official Open-source projects. In particular this and this from Webogram are quite useful for generating your own TL parser. The current layer version is 45

3) 因此,当您发送 init +nearestDc 请求时,这很可能是您的第一条 MTproto 加密消息,因此您需要创建一个新的随机 64 位数字作为您的会话密钥,但您还需要一个有效的 server_salt...

3) So when you send your init + nearestDc request, this is most likely your first MTproto Encrypted message, so you would need to create a new random 64-bit number as your session key, but also you need a valid server_salt...

4) 您可能在创建 Auth_Key 时跳过了此步骤,但您可以从中创建一个有效的初始 server_salt:

4) You might have skipped this while creating your Auth_Key, but you can create a valid initial server_salt from this:

server_salt = substr(new_nonce, 0, 8) XOR substr(server_nonce, 0, 8)

你可以在这里查看:STEP 9) DH 密钥交换完成

5) 您现在有了 server_salt,一个新的随机 64 位 session_id,并且您想发送以下内容:

5) You now have your server_salt, a new random 64-bit session_id and you want to send the following:

msg = TL.invokewithlayer(@layer, TL.initconnection(@app_id, @device_model, @system_version, @app_version, @lang_code, TL.help_getnearestdc))

msg = TL.invokewithlayer(@layer, TL.initconnection(@app_id, @device_model, @system_version, @app_version, @lang_code, TL.help_getnearestdc))

MTProto 格式为:auth_id + msg_key + enc_payload

MTProto format is: auth_id + msg_key + enc_payload

enc_payload = AES_IGE_enc(payload)

enc_payload = AES_IGE_enc(payload)

payload = salt + session_id + msg_id + seq_no + len(msg) + msg + padding

payload = salt + session_id + msg_id + seq_no + len(msg) + msg + padding

您可以从这里

6) 现在你期望一个结果告诉你离你最近的 dc_id,如果这与 dc_id = 2 不同(通常 dc_id = 2 是你开始时的默认值)那么你需要断开连接并启动一个新的连接到您的新 dc_id 并重新生成连接到这个新 dc 的 auth_key.您的 dc_ids 指向 Telegram 数据中心 IP 地址列表 ['149.154.175.50', '149.154.167.51', '149.154.175.100', '149.154.167.91', 17.5.191'.17.5.11'>

6) now you expect a result that tells you your nearest dc_id, if this is different from dc_id = 2 (usually dc_id = 2 is the default you start with) then you need to disconnect and start up a new connection to the your new dc_id and re-generate your auth_key connected to this new dc. Your dc_ids point to a list of Telegram Data-center IP addresses ['149.154.175.50', '149.154.167.51', '149.154.175.100', '149.154.167.91', '149.154.171.5']

7) 一旦连接到正确的最近的直流",您现在可以执行用户授权, 授权一个(您的)手机号码使用您的新 Telegram 客户端访问 Telegram

7) once connected to the correct "nearest dc" you can now carry out the User Authorization, to authorize a (your) mobile number to access telegram using your new Telegram client

8) 您发送到 Telegram 的所有后续消息都将使用相同的 session_id 和 salt 发送,并遵循之前的 MTProto 加密步骤

8) all subsequent messages you send to Telegram will be sent using the same session_id and salt, and following the MTProto encryption steps like before

9) 请注意,盐通常只能保存 24 小时.服务器会向您发送一个新的盐,您可以用它来替换过期的盐.session_id 通常是长期存在的.

9) note that salt is usually good for just 24 hours. The server will send you a new salt, which you can use to replace expired salts. session_id is usually long lived.

10) 一旦掌握了这几个步骤,您就可以尝试发送消息或获取联系人列表和消息历史记录

10) once you get the hang of these few steps you can then try sending messages or getting your list of contacts and message history

干杯.

这篇关于为 Telegram API 创建授权密钥后的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆