php 音频文件上传,七牛整合php上传从微信下载接口下载下来的文件

public function doMobileUploadToQiniu() {

global $_GPC,$_W;

$hd=$_GPC[‘hd‘];

$weid=$_W[‘weid‘];

$from_user = $_GPC[‘from_user‘];

$media_id = $_GPC[‘voiceServerId‘];

$access_key = ‘xxxxxxxxxxxxxxxxxxxxx‘;

$secret_key = ‘xxxxxxxxxxxxxxxxxxxxx‘;

$access_token_json = $_W[‘account‘][‘access_token‘][‘token‘];

$downloadurl = ‘http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=‘.$access_token_json.‘&media_id=‘.$media_id;

$fetch = $this->urlsafe_base64_encode($downloadurl);

$target = $media_id.".amr";

$to = $this->urlsafe_base64_encode($target);

$url = ‘http://iovip.qbox.me/fetch/‘. $fetch .‘/to/‘ . $to;

$access_token = $this->generate_access_token($access_key, $secret_key, $url);

$header[] = ‘Content-Type: application/json‘;

$header[] = ‘Authorization: QBox ‘. $access_token;

$con = $this->send(‘iovip.qbox.me/fetch/‘.$fetch.‘/to/‘.$to, $header);

$id = $this -> dataTransfer($access_key, $secret_key, $media_id);

return $id;

}

/**

*将音频格式转码成amr格式

*/

public function dataTransfer($access_key, $secret_key, $media_id) {

$auth = new Auth($access_key, $secret_key);

$bucket = ‘chuangyi-file-01‘;

$key = "".$media_id.".amr";

$pfop = New PersistentFop($auth, $bucket);

$fops=‘avthumb/mp3/ab/128k/ar/44100/acodec/libmp3lame‘;

list($id, $err, $r) = $pfop->execute($key, $fops);

if ($err != null) {

message("系统错误,请稍后再试");

} else {

return $id;

}

}

public function send($url, $header = ‘‘) {

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL,$url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HEADER,1);

curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

curl_setopt($curl, CURLOPT_POST, 1);

$con = curl_exec($curl);

if ($con === false) {

return $error;

} else {

return $con;

}

}

/**

* generate_access_token

*

* @desc 签名运算

* @param string $access_key

* @param string $secret_key

* @param string $url

* @param array $params

* @return string

*/

public function generate_access_token($access_key, $secret_key, $url, $params = ‘‘){

$parsed_url = parse_url($url);

$path = $parsed_url[‘path‘];

$access = $path;

if (isset($parsed_url[‘query‘])) {

$access .= "?" . $parsed_url[‘query‘];

}

$access .= "\n";

if($params){

if (is_array($params)){

$params = http_build_query($params);

}

$access .= $params;

}

$digest = hash_hmac(‘sha1‘, $access, $secret_key, true);

return $access_key.‘:‘.$this->urlsafe_base64_encode($digest);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值