fabiang/xmpp如何接收消息

公司决定使用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就行。

阅读 2.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进