https://developer.aliyun.com/article/996910?
function getCDNAuthUrlA($filePath){
$fileDomain = "https://your.domain.com";
$timestamp = time();
$rand = uniqid(mt_rand(), true);
$privateKey = 'aliyuncdntest';
$md5hash = md5($filePath.'-'.$timestamp.'-'.$rand.'-0-'.$privateKey);
$fileUrl = $fileDomain.$filePath.'?auth_key='.$timestamp.'-'.$rand.'-0-'.$md5hash;
return $fileUrl;
}
//获取URL地址
$filePath = '/images/2022/05/07/_MG_0090.jpg';
$fileUrl = getCDNAuthUrlA($filePath);
function getCDNAuthUrlB($filePath,$minutes=0){
$fileDomain = "https://your.domain.com";
$timestamp = date('YmdHi',strtotime('+'.$minutes.' minutes'));
$privateKey = 'aliyuncdntest';
$md5hash = md5($privateKey.$timestamp.$filePath);
$fileUrl = $fileDomain.'/'.$timestamp.'/'.$md5hash.$filePath;
return $fileUrl;
}
//获取URL
$filePath = '/images/2022/05/07/_MG_0090.jpg';
$fileUrl = $this->getCDNAuthUrlB($filePath,3);
private function getCDNAuthUrlC($filePath,$minutes=0){
$fileDomain = "https://your.domain.com";
$timestamp = dechex(strtotime('+'.$minutes.' minutes'));
$privateKey = 'aliyuncdntest';
$md5hash = md5($privateKey.$filePath.$timestamp);
$fileUrl1 = $fileDomain.'/'.$md5hash.'/'.$timestamp.$filePath;
$fileUrl2 = $fileDomain.$filePath.'?key1='.$md5hash.'&key2='.$timestamp;
return [$fileUrl1,$fileUrl2];
}
//获取URL
$filePath = '/images/2022/05/07/_MG_0090.jpg';
$fileUrl = $this->getCDNAuthUrlC($filePath,3);