我已经编写了一个PHP脚本,用于生成一个用于RTMP的签名CloudFront URL,并且可以在Flowplayer中正常工作,但是当我使用相同的签名生成方法创建下载URL时,我从Amazon获得一个AccessDenied XML文件。我已经尝试过所有的事情,而且我正在努力完成任务。任何人都知道为什么这个签名可以用于RTMP流式传输,但是相同的签名生成方法会导致下载失败?CloudFront URL签名适用于RTMP,为什么它不适用于下载URL?
所有的$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;
}
这可能会也可能不会有帮助:我认为在键“”条件“'和它的值之间的'$ json = ...'开始的行中缺少':'。 –