Я реализовал для создания цели потока через php с помощью curl.
<?php
$service_url = 'http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/liveSource';
$curl = curl_init($service_url);
$curl_post_data ='
{
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive""stream_target": {
"name": “defaultTarget”,
"provider": "rtmp",
"username": "liveSource",
"password": "Welcomehere",
"stream_name": “customTarget”,
"primary_url": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/liveSource",
} "https://api.cloud.wowza.com/api/v1/stream_targets"}';
$headers = array(
'Content-Type: application/json; charset=utf-8',
'Accept: application/json; charset=utf-8'
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$curl_response = curl_exec($curl);
curl_close($curl);
echo $curl_response;
?>
Но это показывает ошибку как успех как ложь с кодом 401
{"message":"The request requires user authentication","success":false,"wowzaServer":"4.4.0","code":"401"}
Если вы пытаетесь создать потоковую цель в движке Wowza Streaming, я бы начал с простого примера:
<?php
// Modify values here
$entryName = "ppSource";
$appName = "live";
$streamName = "myStream";
$userName = "user";
$password = "pass";
$profile = "rtmp";
$server = "localhost";
// End modification
$url = "http://{$server}:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/{$appName}/pushpublish/mapentries/{$entryName}";
$json = "{
\"restURI\": \"http://{$server}:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/{$appName}/pushpublish/mapentries/{$entryName}\",
\"serverName\":\"_defaultServer_\",
\"sourceStreamName\": \"{$streamName}\",
\"entryName\": \"{$entryName}\",
\"profile\": \"{$profile}\",
\"host\": \"{$server}\",
\"application\":\"{$appName}\",
\"userName\":\"{$userName}\",
\"password\":\"{$password}\",
\"streamName\":\"{$streamName}\"}'";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HEADER ,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
// curl_setopt($ch, CURLOPT_USERPWD, "user:pass");
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept:application/json; charset=utf-8',
'Content-type:application/json; charset=utf-8',
'Content-Length: '.strlen($json)));
$contents = curl_exec($ch);
curl_close($ch);
$obj = json_decode($contents);
var_dump($obj);
Однако, если вы пытаетесь инициировать живой поток через наш облачный API, вот небольшой пример (только) того, как может выглядеть ваш запрос:
// Modify values here
$cloudApiKey = "xxxxxxxxxxx";
$cloudApiAccessKey="xxxxxxxxxx";
// End modification
$url = "https://api.cloud.wowza.com/api/v1/live_streams";
$json = "{
\"live_stream\": {
\"id\": \"1234abcd\",
\"name\": \"MyLiveStream\",
\"transcoder_type\": \"transcoded\",
\"billing_mode\": \"pay_as_you_go\",
\"broadcast_location\": \"us_west_california\",
\"recording\": false,
\"encoder\": \"wowza_gocoder\",
\"delivery_method\": \"push\",
\"use_stream_source\": false,
\"aspect_ratio_width\": 1280,
\"aspect_ratio_height\": 720,
\"connection_code\": \"033334\",
\"connection_code_expires_at\": \"2015-11-25T12:06:38.453-08:00\",
\"source_connection_information\": {
\"primary_server\": \"6022e9.entrypoint.cloud.wowza.com\",
\"host_port\": 1935,
\"application\": \"app-464b\",
\"stream_name\": \"32a5814b\",
\"disable_authentication\": false,
\"username\": \"client2\",
\"password\": \"1234abcd\"},
\"player_responsive\": true,
\"player_countdown\": false,
\"player_embed_code\": \"in_progress\",
\"player_hds_playback_url\": \"http://wowzadev-f.akamaihd.net/z/32a5814b_1@7217/manifest.f4m\",
\"player_hls_playback_url\": \"http://wowzadev-f.akamaihd.net/i/32a5814b_1@7217/master.m3u8\",
\"hosted_page\": true,
\"hosted_page_title\": \"MyLiveStream\",
\"hosted_page_url\": \"in_progress\",
\"hosted_page_sharing_icons\": true
}
}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HEADER ,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept:application/json; charset=utf-8',
'Content-type:application/json; charset=utf-8',
'wsc-api-key: '.$cloudApiKey,
'wsc-access-key: '.$cloudApiAccessKey,
);
$contents = curl_exec($ch);
curl_close($ch);
Это получается из страница примеров и модифицировано, чтобы соответствовать запросу, связанному с PHP.
Спасибо,
Matt
Других решений пока нет …