腾讯晕-云点播资源接口
官方文档
https://cloud.tencent.com/document/product/266/31813
代码案例
// 你的 API 密钥
$secretId = 'AKIDmVK******PUTK8i4B4BSV';
$secretKey = 'If1A5m**************W9YzNUBZr13sVD';
// API endpoint URL
$url = 'https://vod.tencentcloudapi.com/';
// 构造请求参数
$payload = [
'Action' => 'SearchMedia',
'Version' => '2018-07-17',
'Region' => 'ap-guangzhou',
// 'PageNumber' => 1,
// 'PageSize' => 10,
'Timestamp' => time(),
'Nonce' => rand(),
'SecretId' => $secretId,
'SubAppId' => '1500031236',
];
// 参数排序
ksort($payload);
// 构建查询字符串并对其进行编码
$queryString = http_build_query($payload);
// 创建用于签名的字符串
$stringToSign = "GET" . "vod.tencentcloudapi.com" . "/?" . $queryString;
// 生成签名
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $secretKey, true));
$payload['Signature'] = $signature;
// 再次构建查询字符串以包括签名
$signedQuery = http_build_query($payload);
// 完整的 URL
$finalUrl = $url . '?' . $signedQuery;
// 初始化 cURL
$ch = curl_init();
// 设置 cURL 选项
curl_setopt($ch, CURLOPT_URL, $finalUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 执行 cURL 请求
$response = curl_exec($ch);
// 检查是否有错误发生
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
// 关闭 cURL 资源
curl_close($ch);
// 输出响应
echo $response;