使用 PHP REST API 从 Wowza Streaming Engine 创建、更新和检索数据时出现问题?

Issues creating, updating and retrieving data from Wowza Streaming Engine using PHP REST API?

我正在开始使用 Wowza PHP 库,但是我无法连接到我在本地安装的流媒体引擎。按照 https://github.com/WowzaMediaSystems/wse-rest-library-php 的指示,我安装了 composer,使用我的服务器主机和身份验证设置创建了配置文件

wowza_config.php

define("WOWZA_HOST","http://localhost:8087/v2");
define("WOWZA_SERVER_INSTANCE", "_defaultServer_");
define("WOWZA_VHOST_INSTANCE", "_defaultVHost_");
define("WOWZA_USERNAME", "admin");
define("WOWZA_PASSWORD", "admin");

然后当尝试测试从服务器检索数据时,例如:

index.php

<?php


require_once ('vendor/autoload.php');
require_once("config/wowza_config.php");


// It is simple to create a setup object for transporting our settings
$setup = new Com\Wowza\Entities\Application\Helpers\Settings();
$setup->setHost(WOWZA_HOST);
$setup->setUsername(WOWZA_USERNAME);
$setup->setPassword(WOWZA_PASSWORD);

$sf = new Com\Wowza\Statistics($setup);
// get stats per application
$wowzaApplication = new Com\Wowza\Application($setup, 'vod');
// get total server stats
$server = new Com\Wowza\Server($setup, 'http://localhost:8087/v2');
$response = $sf->getServerStatistics($server);
// get stats historical for given application
// $response = $sf->getApplicationStatisticsHistory($wowzaApplication);
// $response = $sf->getApplicationStatistics($wowzaApplication);
// get incoming stream stats for given application


var_dump($response);
?>

我收到错误

object(stdClass)#8 (4) { ["message"]=> string(40) "The request requires user authentication" ["code"]=> string(3) "401" ["wowzaServer"]=> string(5) "4.7.7" ["success"]=> bool(false) } 

我已经三重检查以确认我使用的凭据与服务器的凭据相匹配,但无法弄清楚我做错了什么

我注意到一件事:在您的设置中,您没有为 "useDigest" 设置值。所以它默认为 false(参见 https://github.com/WowzaMediaSystems/wse-rest-library-php/blob/master/src/Entities/Application/Helpers/Settings.php). Then when you call getServerStatistics() eventually it calls "sendRequest()" in the Wowza class (see https://github.com/WowzaMediaSystems/wse-rest-library-php/blob/master/src/Wowza.php)。在这个 class 中,如果 "useDigest" 在设置中设置为 true,它只会将用户名和密码添加到请求中:

if ($this->settings->isUseDigest()) {
   curl_setopt($ch, CURLOPT_USERPWD, $this->settings->getUsername() . ':' . $this->settings->getPassword());
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
}

所以我认为它根本没有将用户名和密码附加到您的请求中。

因此我建议您添加

$setup->setUseDigest(true);

在您配置设置对象时添加到您的代码中,这应该会有所帮助。