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

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

问题描述

我已经搞乱贯彻电报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.

有关参考:电报API

请注意:我不使用机器人API。我试图使用常规的API。

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

推荐答案

创建AUTH_KEY后,我发现最简单的方法,以确保我连接到我的数据中心最近我再继续。你也应该用你的code将与合作当前层(API版本)一起发送InitConnection命令。

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.

下面的是我送一个例子:

Here an example of what I send:

味精= 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)电报服务器在TL沟通,它基本上是一个电报用来EX preSS一切定制开发的编码方案:从指令给它的所有类型。您将需要建立自己一个去codeR和连接codeR转换原始字节为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)电报更新他们的API版本不时,但在其网站上的版本已经过时。你可以很容易地得到了正式的开源项目的最新API SPEC。特别和< A HREF =htt​​ps://github.com/zhukov/webogram/blob/master/app/js/lib/schema.tl.txt相对=nofollow>从Webogram这个是产生相当有用你自己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)

你可以看看那个在这里:步骤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:

味精= 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(负载)

enc_payload = AES_IGE_enc(payload)

有效载荷= +盐+ SESSION_ID + MSG_ID + seq_no LEN(MSG)+味精+填充

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

您可以从得到上面这里

6)现在你期望的结果,告诉你离你最近的dc_id,如果这是不同于dc_id = 2(通常dc_id = 2是你开始),那么你需要断开连接并启动到一个新的连接的缺省新dc_id并重新生成你AUTH_KEY连接到这个新的DC。您的dc_ids指向电报数据中心的IP地址的列表 ['149.154.175.50,149.154.167.51,149.154.175.100,149.154.167.91,149.154.171.5']

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)一旦连接到正确的最接近DC你现在可以进行用户授权,以授权(你的)手机号码用来访问电报新电报的客户端

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)您发送到电报的所有后续消息将使用相同​​的session_id和盐,并按照像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

干杯。

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

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