【发布时间】:2016-10-15 17:51:06
【问题描述】:
有人可以推荐将 Twilio 录音嵌入网站的最佳方式吗?
我说的是托管在 Twilio 服务器上的 Twilio 录制。
目前我只是使用我编写的以下 PHP 函数来下载文件,然后找出嵌入在我身边,但可能有更简单的方法吗?
function download_recording_from_twilio($url) {
// the file_name is everything after the twilio.com/ with an added .mp3 at the end
$word_after_which_we_extract = "twilio.com/";
// what is the beginning position of this word?
$begPos = strpos($url, $word_after_which_we_extract);
// beginning position is the beginning of the word plus the word length
$begPos += strlen($word_after_which_we_extract);
// everything after twilio.com/
$everything_after = substr($url, $begPos, strlen($url));
// position of the last / in $everything_after
$last_slash = strrpos($url, "/");
// everything after the last slash
$everything_after_last_slash = substr($url, $last_slash, strlen($url));
// full filepath
$full_path = $everything_after.".mp3";
// create final filename
$file_name = $everything_after_last_slash.".mp3";
$source = "https://api.twilio.com/".$full_path;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'ecdhe_rsa_aes_128_gcm_sha_256');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE,true);
$data = curl_exec ($ch);
$error = curl_error($ch);
curl_close ($ch);
$destination = ".".$file_name;
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
}
谢谢
【问题讨论】:
标签: twilio twilio-php twilio-api