腾讯云接口测试
<?php
$appkey = "";
$AccessToken = "";
$baseUrl = "https://gw.tvs.qq.com/v2/ivh/videomaker/broadcastservice/tts?";
//当前时间戳
$timestamp = time();
//signature 签名原文
$signature = 'appkey=' . $appkey . '×tamp=' . strval($timestamp);
// 将访问令牌转换为字节串
$access_token_bytes = utf8_encode($AccessToken);
// 使用HmacSha256算法计算签名
$signature_sha256 = hash_hmac('sha256', $signature, $access_token_bytes, true);
$signature_digest = $signature_sha256;
// 对签名进行Base64编码
$signature_base64 = base64_encode($signature_digest);
// 对签名值进行URL编码
$signature_encoded = urlencode($signature_base64);
$url = $baseUrl . $signature .'&signature='.$signature_encoded;
// echo $url;
$postdata = [
"TimbreKey" => "female_1",
"InputSsml" => "你好虚拟主播",
"Speed" => 1
];
$jsonData = json_encode([
'Header' => ['a'=>'1'],
'Payload' => $postdata
],JSON_UNESCAPED_UNICODE);
// echo $jsonData;die;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=utf-8"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 关闭SSL验证
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo 'Response:' . $response;
}
curl_close($ch);
?>