Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1526|回复: 0
打印 上一主题 下一主题

telegram-mtproto, 电报客户端 api ( MTProto ) 库

[复制链接]

1228

主题

1997

帖子

7580

积分

认证用户组

Rank: 5Rank: 5

积分
7580
跳转到指定楼层
楼主
发表于 2020-2-22 22:08:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
https://www.kutu66.com//GitHub/article_151192
源代码名称:telegram-mtproto源代码网址:http://www.github.com/zerobias/telegram-mtprototelegram-mtproto源代码文档telegram-mtproto源代码下载Git URL:复制代码
git://www.github.com/zerobias/telegram-mtproto.gitGit Clone代码到本地:复制代码
git clone http://www.github.com/zerobias/telegram-mtprotoSubversion代码到本地:复制代码
$ svn co --depth empty http://www.github.com/zerobias/telegram-mtprotoChecked out revision 1.$ cd repo$ svn up trunk

电报 mtproto
Telegram移动协议( MTProto ) 图书馆 es6
关于 MTProto。
移动协议分为三个组件( 来自官方网站的 。):
  • 高级组件( API查询语言): 定义将API查询和响应转换为二进制消息的方法。
  • 加密( 授权) 层:定义在通过传输协议传输消息之前对消息进行加密的方法。
  • 传输组件:定义客户端和服务器通过其他现有的网络协议(。例如 http,https,tcp,udp ) 传输消息的方法。

电报mtproto简称。
没有额外的库 telegram telegram-mtproto 库实现了收费 Mobile,并提供了与电报协议一起工作的所有功能:
  • 用于服务器连接的高级 api
  • 基于承诺的API
  • 在传输层中实现的连接
  • 网站工作人员支持快速加密数学工作
  • 安全层中位AES和RSA加密的密码实现
  • 与服务器通信的纯文本和加密消息
  • security diffie hellman密钥交换支持,它由安全层实现的英镑分解函数支持
  • 以英镑的javascript类和函数为代价的 MTProto模式编译
  • 自定义位异步存储支持在会话之间保存用户数据

安装复制代码
$ npm install --save telegram-mtproto@beta用法复制代码
import MTProto from 'telegram-mtproto'const phone = { num : '+9996620001', code: '22222'}const api = { layer : 57, initConnection : 0x69796de9, api_id : 49631}const server = { dev: true //We will connect to the test server.} //Any empty configurations fields can just not be specifiedconst client = MTProto({ server, api })async function connect(){ const { phone_code_hash } = await client('auth.sendCode', { phone_number : phone.num, current_number: false, api_id : 49631, api_hash : 'fb050b8f6771e15bfda5df2409931569' }) const { user } = await client('auth.signIn', { phone_number : phone.num, phone_code_hash: phone_code_hash, phone_code : phone.code }) console.log('signed as ', user)}connect()
上面我们从API中使用了两个函数。
复制代码
type auth.sendCode = (phone_number: string, sms_type: int, api_id: int, api_hash: string, lang_code: string) => { phone_registered: boolean, phone_code_hash: string, send_call_timeout: int, is_password: boolean }type auth.signIn = (phone_number: string, phone_code_hash: string, phone_code: string) => { expires: int, user: User}
如果你还可以阅读更多的其他方法,你可以阅读官方文档。
其他示例可以从示例文件夹获得。
存储
你可以使用自己的存储( 如 localForage 保存数据)。 模块接受以下接口
复制代码
interface AsyncStorage { get(key: string): Promise<any>; set(key: string, value: any): Promise<void>; remove(...keys: string[]): Promise<void>; clear(): Promise<void>;}复制代码
import { MTProto } from 'telegram-mtproto'import { api } from './config'import CustomStorage from './storage'const client = MTProto({ api, app: { storage: CustomStorage }})许可证


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-4-30 07:37 , Processed in 0.055620 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表