如何调用 Telegram MTProto 协议 api?

How does one make a Telegram MTProto protocol api call?

例如 call/wrap auth.sentCode 方法(link 下面):

https://core.telegram.org/method/auth.sendCode

我试过:

var url = "https://149.154.167.40";  
var data = "(auth.sendCode \"PHONE_CODE+NO\" 0 APP_ID \"SECRET_HASH\" \"en\")";  
using (var wc = new WebClient())  
{  
var result = wc.UploadData(url, GetBytes(data));  
}  

我得到这个异常(和内部异常)

The underlying connection was closed: An unexpected error occurred on a send. (Authentication failed because the remote party has closed the transport stream.)

如果您尝试通过 Web 浏览器访问 https://149.154.167.40,您会看到 https 协议未启用。如果你看here, there are a list of subdomains that implements https, you could try one of those to make your api request. I'm not really sure that telegram blocks your request due to the CROSS-ORIGIN policy, because the access-control-allow-origin:* header is present in the response. If that doesn't work, you could implement your own handshake like the android application does in here。希望对你有帮助。

您开始使用

您需要先了解如何生成 AuthKey

Telegram-API 文档写得不是很好,但如果你继续研究它......你最终会掌握它。

通过生成 AuthKey 的工作将帮助您建立一个模式和函数,然后您可以使用它们来处理其余的 API

干杯。

使用TLSharp。要验证用户身份,只需 运行 此代码

   var hash = await client.SendCodeRequest(phoneNumber);

   var code = "1234"; //code that you receive from Telegram 

   var user = await client.MakeAuth(phoneNumber, hash, code);