Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CloudFront URL签名适用于RTMP,为什么赢得&x27;下载URL不起作用吗?_Php_Amazon Web Services_Rtmp_Amazon Cloudfront - Fatal编程技术网

Php CloudFront URL签名适用于RTMP,为什么赢得&x27;下载URL不起作用吗?

Php CloudFront URL签名适用于RTMP,为什么赢得&x27;下载URL不起作用吗?,php,amazon-web-services,rtmp,amazon-cloudfront,Php,Amazon Web Services,Rtmp,Amazon Cloudfront,我编写了一个PHP脚本,为RTMP生成一个签名的CloudFront URL,并在Flowplayer中使用,效果很好,但是当我使用相同的签名生成方法创建下载URL时,我从Amazon获得了一个AccessDenied XML文件。我几乎什么都试过了,真是束手无策。有人知道为什么签名可以用于RTMP流,但同样的签名生成方法在下载时会失败吗 $keyPairId = 'APK...'; $privateKey = '/var/www/certs/pk-APK....pem'; $rtmp = fa

我编写了一个PHP脚本,为RTMP生成一个签名的CloudFront URL,并在Flowplayer中使用,效果很好,但是当我使用相同的签名生成方法创建下载URL时,我从Amazon获得了一个AccessDenied XML文件。我几乎什么都试过了,真是束手无策。有人知道为什么签名可以用于RTMP流,但同样的签名生成方法在下载时会失败吗

$keyPairId = 'APK...';
$privateKey = '/var/www/certs/pk-APK....pem';
$rtmp = false; 
$distribution = 'd2m...';

// Get extension.
$extension = substr($this->getFilename(), strrpos($this->getFilename(), '.') + 1);
$fileName = substr($this->getFilename(), 0, strrpos($this->getFilename(), '.'));

$expires = strtotime(gmdate('Y-m-d H:i:s', strtotime('+3 hours')));
$json = '{"Statement":[{"Resource":"' . $fileName . '","Condition"{"DateLessThan":{"AWS:EpochTime":' . $expires . '}}}]}';

// read cloudfront private key pair
$fp = fopen($privateKey, 'r');
$priv_key = fread($fp, 8192);
fclose($fp);

// create the private key
$key = openssl_get_privatekey($priv_key);

// sign the policy with the private key
// depending on your php version you might have to use
// openssl_sign($json, $signed_policy, $key, OPENSSL_ALGO_SHA1)
openssl_sign($json, $signed_policy, $key);

openssl_free_key($key);

// create url safe signed policy
$base64_signed_policy = base64_encode($signed_policy);
$signature = str_replace(array('+', '=', '/'), array('-', '_', '~'),                 $base64_signed_policy);

// construct the url
$urlParams = urlencode($this->getFilename()) . '?Expires=' . $expires .'&Signature=' . $signature . '&Key-Pair-Id=' . $keyPairId;
$keyPairId;
if ($rtmp) {
    $url = ( ($this->getExtension() != 'flv') ? $this->getExtension() . ':' : '' ) . $urlParams;
} else {
    $url = 'https://' . $distribution . '.cloudfront.net/' . $urlParams;
}

首先,签名RTMP URL比常规URL更安全

RTMP发行版:仅包括流名称。例如,如果 流式视频的完整URL为:

rtmp://s5c39gqb8ow64r.cloudfront.net/videos/mp3_name.mp3

然后对资源使用以下值:

视频/mp3_名称

常规签名URL包含整个路径

其次,cloudfront RTMP发行版仅通过RTMP分发流媒体。您说过您需要一个下载url,因此使用RTMP发行版将无法下载该文件


您可能希望创建一个cloudfront web发行版并将其链接到同一个bucket,然后使用web发行版生成一个签名url,并以这种方式访问它。

这可能有用,也可能没有帮助:我认为在键
“条件”之间以
$json=…
开头的行中缺少一个
及其值。