fabiang/xmpp如何接收消息

发布于 2022-09-05 06:19:03 字数 1574 浏览 24 评论 0

公司决定使用php开发一个客服系统,由于对laravel比较熟,最终决定使用laravel swoole xmpp + openfire开发服务端和客户端。

对于swoole,有laravel-swoole package.
对于xmpp,最终决定使用fabiang/xmpp,原因

  • 下载量大

  • 最近有更新

demo中只有发送消息的示例,调试OK。

use Fabiang\Xmpp\Options;
$options = new Options($address);
$options->setUsername($username)
    ->setPassword($password);

The server address must be in the format tcp://myjabber.com:5222.
If the server supports TLS the connection will automatically be encrypted.

You can also pass a PSR-2-compatible object to the options object:

$options->setLogger($logger)

The client manages the connection to the Jabber server and requires the options object:

use Fabiang\Xmpp\Client;
$client = new Client($options);
// optional connect manually
$client->connect();

For sending data you just need to pass a object that implements FabiangXmppProtocolProtocolImplementationInterface:

use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;

// fetch roster list; users and their groups
$client->send(new Roster);
// set status to online
$client->send(new Presence);

// send a message to another user
$message = new Message;
$message->setMessage('test')
    ->setTo('nickname@myjabber.com')
$client->send($message);

现在的问题是找不到接收消息的代码,请教各位大神,有没有这方面的资料或者链接,给一个demo就行。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文