wowza rest api to php script


wowza rest api to php script

我是php和wowza的新手,想知道是否有人能给我介绍一下如何将这个wowza curl api与php一起使用的教程?我试着找了一下,但在任何地方都找不到答案,所以我来到了这里。我想实现的是通过php从远程计算机运行这个curl

这是一个类似curl id的转换为php脚本的例子,但是我似乎找不到应该在哪里或如何启动

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
}

您可以找到其他几个cURL示例,您可以简单地操作随动词类型一起发送的JSON(在本例中为POST),以进一步利用RESTneneneba API。

作为检索现有应用程序的GET请求示例,您可以删除CURLOPT_POSTFIELDS cURL选项并修改以下行:

$ch = curl_init("http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");