WOWZARESTAPI到php脚本
我是php和wowza新手,想知道是否有人能给我介绍如何在php中使用wowza curl api的教程?我试着寻找,但到处都找不到答案,所以我来到这里。我试图实现的是从远程计算机上通过php运行这个curl 这是curl-id想要转换成php脚本的一个例子,但是我似乎找不到应该从哪里开始,或者如何开始WOWZARESTAPI到php脚本,php,api,rest,wowza,Php,Api,Rest,Wowza,我是php和wowza新手,想知道是否有人能给我介绍如何在php中使用wowza curl api的教程?我试着寻找,但到处都找不到答案,所以我来到这里。我试图实现的是从远程计算机上通过php运行这个curl 这是curl-id想要转换成php脚本的一个例子,但是我似乎找不到应该从哪里开始,或者如何开始 curl -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application
curl -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive -d'
{
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive",
"name": "testlive",
"appType": "Live",
"description": "Testing our Rest Service",
"streamConfig": {
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/streamconfiguration",
"streamType": "live"
},
"securityConfig": {
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/security",
"secureTokenVersion": 0,
"clientStreamWriteAccess": "*",
"publishRequirePassword": true,
"publishPasswordFile": "",
"publishRTMPSecureURL": "",
"publishIPBlackList": "",
"publishIPWhiteList": "",
"publishBlockDuplicateStreamNames": false,
"publishValidEncoders": "",
"publishAuthenticationMethod": "digest",
"playMaximumConnections": 0,
"playRequireSecureConnection": false,
"secureTokenSharedSecret": "",
"secureTokenUseTEAForRTMP": false,
"secureTokenIncludeClientIPInHash": false,
"secureTokenHashAlgorithm": "",
"secureTokenQueryParametersPrefix": "",
"secureTokenOriginSharedSecret": "",
"playIPBlackList": "",
"playIPWhiteList": "",
"playAuthenticationMethod": "none"
},
"modules": {
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/modules",
"moduleList": [
{
"order": 0,
"name": "base",
"description": "Base",
"class": "com.wowza.wms.module.ModuleCore"
},
{
"order": 1,
"name": "logging",
"description": "Client Logging",
"class": "com.wowza.wms.module.ModuleClientLogging"
},
{
"order": 2,
"name": "flvplayback",
"description": "FLVPlayback",
"class": "com.wowza.wms.module.ModuleFLVPlayback"
},
{
"order": 3,
"name": "ModuleCoreSecurity",
"description": "Core Security Module for Applications",
"class": "com.wowza.wms.security.ModuleCoreSecurity"
}
]
}
}'
如上所述,看看php cURL扩展。然后查看以下示例脚本:
// If you have digest auth turned on, switch this to true.
$useDigest = false;
$username = "admin";
$password = "pass";
$json = '{
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow",
"name": "stackoverflow",
"appType": "Live",
"description": "Testing our Rest Service",
"streamConfig": {
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow/streamconfiguration",
"streamType": "live"
},
"securityConfig": {
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow/security",
"secureTokenVersion": 0,
"clientStreamWriteAccess": "*",
"publishRequirePassword": true,
"publishPasswordFile": "",
"publishRTMPSecureURL": "",
"publishIPBlackList": "",
"publishIPWhiteList": "",
"publishBlockDuplicateStreamNames": false,
"publishValidEncoders": "",
"publishAuthenticationMethod": "digest",
"playMaximumConnections": 0,
"playRequireSecureConnection": false,
"secureTokenSharedSecret": "",
"secureTokenUseTEAForRTMP": false,
"secureTokenIncludeClientIPInHash": false,
"secureTokenHashAlgorithm": "",
"secureTokenQueryParametersPrefix": "",
"secureTokenOriginSharedSecret": "",
"playIPBlackList": "",
"playIPWhiteList": "",
"playAuthenticationMethod": "none"
},
"modules": {
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow/modules",
"moduleList": [
{
"order": 0,
"name": "base",
"description": "Base",
"class": "com.wowza.wms.module.ModuleCore"
},
{
"order": 1,
"name": "logging",
"description": "Client Logging",
"class": "com.wowza.wms.module.ModuleClientLogging"
},
{
"order": 2,
"name": "flvplayback",
"description": "FLVPlayback",
"class": "com.wowza.wms.module.ModuleFLVPlayback"
},
{
"order": 3,
"name": "ModuleCoreSecurity",
"description": "Core Security Module for Applications",
"class": "com.wowza.wms.security.ModuleCoreSecurity"
}
]
}
}';
$ch = curl_init("http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
if($useDigest){
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
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);
$response = json_decode($contents);
var_dump($response);
这将产生与以下类似的输出:
object(stdClass)#1 (3) {
["success"]=>
bool(true)
["message"]=>
string(49) "Application (stackoverflow) created successfully."
["data"]=>
NULL
}
您可以找到其他几种方法,只需操作与本例POST中的动词类型一起发送的JSON,即可进一步利用RESTAPI
作为检索现有应用程序的GET请求示例,您可以删除CURLOPT_POSTFIELDS cURL选项并修改以下行:
$ch = curl_init("http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
PHP有一个cURL扩展。您可以按照中的说明安装和使用它。帖子示例: