时间:2019-05-03 来源:小程序工厂
$file = $_FILES['file'];//上传的mp3文件
$fileKey = $fileFolder . md5(mt_rand()) . '-' . $file['name'];
$body = file_get_contents($file['tmp_name']);
//以下是调用"微信AI开放接口-提交语音"
$access_token = $this->get_accessToken();
$url = 'http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?access_token=' . $access_token . '&format=&voice_id=' . $fileKey . '&lang=zh_CN';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, base64_encode($body));
$data = json_decode(curl_exec($ch));
curl_close($ch);
return $data->errmsg;