wormling/phparia

PHP 的 Asterisk REST 接口 (ARI) 客户端。

v3.1.1 2017-09-10 13:25 UTC

README

Latest Stable Version Build Status Code Coverage Scrutinizer Quality Score License

新服务器准备就绪之前,功能测试将失败!

用于创建 ARI (Asterisk REST Interface) 应用程序的框架。 (https://wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI)

功能特性

  • 首个支持 wss 的 PHP ARI 客户端
  • 全面支持 Asterisk REST 接口(已测试 12 和 13 版本)
  • 客户端和资源级别的事件系统
  • 可选的基本 AMI 事件/动作支持
  • 详细的输出,便于使用
  • 部分功能测试待办事项!

通过 Composer 提供

只需添加包 "wormling/phparia" 即可

composer require wormling/phparia

创建 Stasis 应用程序

    $ariAddress = 'ws://:8088/ari/events?api_key=username:password&app=stasis_app_name';

    $logger = new \Zend\Log\Logger();
    $logWriter = new \Zend\Log\Writer\Stream("php://output");
    $logger->addWriter($logWriter);
    //$filter = new \Zend\Log\Filter\SuppressFilter(true);
    $filter = new \Zend\Log\Filter\Priority(\Zend\Log\Logger::NOTICE);
    $logWriter->addFilter($filter);
        
    $this->client = new \phparia\Client\Phparia($logger);
    $this->client->connect($ariAddress);
    $this->client->onStasisStart(function(StasisStart $event) {
        $channel = $event->getChannel();
        $bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'bridgename');
        $this->client->bridges()->addChannel($bridge->getId(), $channel->getId(), null);

        ...
    });

    $this->client->run();

创建 Stasis 应用程序并监听 AMI 事件

    $ariAddress = 'ws://:8088/ari/events?api_key=username:password&app=stasis_app_name';
    $amiAddress = 'username:password@localhost:5038';

    $logger = new \Zend\Log\Logger();
    $logWriter = new \Zend\Log\Writer\Stream("php://output");
    $logger->addWriter($logWriter);
    //$filter = new \Zend\Log\Filter\SuppressFilter(true);
    $filter = new \Zend\Log\Filter\Priority(\Zend\Log\Logger::NOTICE);
    $logWriter->addFilter($filter);
        
    $this->client = new \phparia\Client\Phparia($logger);
    $this->client->connect($ariAddress, $amiAddress);
    $this->client->onStasisStart(function(StasisStart $event) {
        $channel = $event->getChannel();
        $bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'bridgename');
        $this->client->bridges()->addChannel($bridge->getId(), $channel->getId(), null);

        $this->client->getWsClient()->on('SomeAMIEventName', function($event) {
            ...
        });

        ...
    });

    $this->client->run();

文档

在 Api 文件夹中可以找到 (https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ARI) 的封装。

在 Resources 和 Events 文件夹中可以找到 (https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+REST+Data+Models) 的封装。

示例

(https://github.com/wormling/phparia/tree/master/src/wormling/phparia/Examples)

(https://github.com/wormling/phparia/tree/master/src/wormling/phparia/Tests/Functional)

扩展

phparia-lyra Sangoma Lyra 答录机检测功能。

许可证

Apache 2.0 (https://apache.ac.cn/licenses/LICENSE2.0)