简体   繁体   English

在基于PHP的网站上基于电报的聊天:如何?

[英]Telegram-based chat on a PHP-based site: HOWTO?

I can't figure out what exactly to use for interaction between my site and the Telegram service (first of all - how to get the authentication process done using PHP and other stuff like chat among users). 我无法弄清楚在网站和Telegram服务之间进行交互时到底要使用什么(首先-如何使用PHP和用户之间的聊天之类的东西来完成身份验证过程)。

On this page: https://core.telegram.org/api I haven't got an idea how to use those functions in PHP. 在此页面上: https : //core.telegram.org/api我不知道如何在PHP中使用这些功能。

According to this page: https://telegram.org/apps I have two choices: 根据此页面: https : //telegram.org/apps我有两个选择:

1) The CLI-interface (unofficial, by the way): https://github.com/vysheng/tg and it doesn't have an autentification function among others. 1)CLI界面(顺便说一下,是非官方的): https : //github.com/vysheng/tg ,它不具有增强功能。 In order to authenticate yourself, you need to run: 为了验证您的身份,您需要运行:

bin/telegram-cli -k tg-server.pub 

and inside of the application you have to enter your cell phone and the secret code sent by SMS - after that you're authorized. 在应用程序内部,您必须输入手机和SMS发送的密码-在获得授权之后。 Then you install https://github.com/zyberspace/php-telegram-cli-client and run telegram-cli as a daemon: 然后安装https://github.com/zyberspace/php-telegram-cli-client并运行telegram-cli作为守护程序:

./bin/telegram-cli -dWS /tmp/tg.sck -k tg-server.pub &  

Does it mean that I have to create tg-server.pub manually using PHP for each user which is trying to login? 这是否意味着我必须为尝试登录的每个用户使用PHP手动创建tg-server.pub?

2) Webogram: https://github.com/zhukov/webogram - but it's written on JavaScript and has very complicated code. 2)Webogram: https : //github.com/zhukov/webogram-但它是用JavaScript编写的,具有非常复杂的代码。

Dear Stackoverflow gurus, maybe you're more attentive than I am and could help me to recognize the right solution (or example, I don't know, the PHP snippet or anything else) for the user's chat based on the Telegram and PHP? 亲爱的Stackoverflow专家,也许您比我更专心,可以帮助我为基于Telegram和PHP的用户聊天识别正确的解决方案(或示例,我不知道,PHP代码段或其他内容)?

I would greatly appreciate it! 我将不胜感激!

Thank you! 谢谢!

I have posted a step by step guide on getting your AuthKey (VB.net) here 我已经发布了有关在此处获取您的AuthKey(VB.net)的逐步指南

The main challenge with Telegram API is the documentation... but if you can work through the first part - getting an AuthKey then i believe the rest should fall in place ... with some more effort. Telegram API的主要挑战是文档...但是,如果您可以完成第一部分的工作-获取AuthKey,那么我相信其余的应该就位了...付出更多的努力。

Working through some GitHub src might be time consuming, it might be best to get a handle on the documentation and then work your way to building your own code for TelegramAPI from scratch 通过某些GitHub src进行工作可能很耗时,可能最好先获得文档的句柄,然后以自己的方式从头开始为TelegramAPI构建自己的代码

Most likely, PHP wrapper for Telegram API doesn't exist. 最有可能的是,Telegram API的PHP包装器不存在。 I'd wager it's because communicating with Telegram servers from your server-side PHP code defeats both of the core features of Telegram: speed and security. 我敢打赌,这是因为从您的服务器端PHP代码与Telegram服务器进行通信会破坏Telegram的两个核心功能:速度和安全性。

  • no speed - a message has to hop through one additional loop (your server) before it reaches the recipient. 没有速度-一条消息在到达接收者之前必须跳过另一个循环(您的服务器)。
  • no security - browser page will communicate with your server via AJAX or forms, I assume. 没有安全性-我认为浏览器页面将通过AJAX或表单与您的服务器通信。 This means sending data as plain text (unless you're on https), open to the whole world to see (if you were to sit on a public wifi, or something like that). 这意味着以纯文本格式发送数据(除非您使用https),向全世界开放(如果您要坐在公共wifi上,诸如此类)。

You can implement the Telegram API, it's a bit involved, but doable. 您可以实现Telegram API,虽然有点复杂,但是可行。 But it's totally pointless, in my opinion. 但是我认为这完全没有意义。

As an alternative, just embed the webogram in an <iframe> or something :) 作为替代方案,只需将网络图嵌入到<iframe>东西中即可:)

现在,您可以使用MadelineProto https://github.com/danog/MadelineProto-适用于MTProto Telegram的功能强大的PHP客户端!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM