|
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关于 MTProto。高级组件( API查询语言): 定义将API查询和响应转换为二进制消息的方法。 加密( 授权) 层:定义在通过传输协议传输消息之前对消息进行加密的方法。 传输组件:定义客户端和服务器通过其他现有的网络协议(。例如 http,https,tcp,udp ) 传输消息的方法。
电报mtproto简称。没有额外的库 telegram telegram-mtproto 库实现了收费 Mobile,并提供了与电报协议一起工作的所有功能: 安装复制代码
$ 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}如果你还可以阅读更多的其他方法,你可以阅读 官方文档。 存储复制代码
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 }})许可证
|
|