七牛整合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);
}
七牛整合php上传从微信下载接口下载下来的文件的更多相关文章
- 七牛整合PHP上传文件
七牛支持抓取远程图片 API,用 access_key + secret_key + url 生成 access_token, 把 access_token 加在 header 里,然后向 post ...
- 七牛--关于图片上传方向不统一的问题--主要关于图片EXIF信息中旋转参数Orientation的理解
[图片引用方向纠正]直接在图片后面添加 ?imageMogr/auto-orient eg:http://data.upfitapp.com/data/2016/10/18/1629114767606 ...
- iOS 七牛多张图片上传
-(void)uploadImages:(NSArray *)images atIndex:(NSInteger)index token:(NSString *)token uploadManager ...
- SpringBoot系列——附件管理:整合业务表单实现上传、回显、下载
前言 日常开发中,大多数项目都会涉及到附件上传.回显.下载等功能,本文记录封装通用附件管理模块,并与业务模块进行整合实现上传.回显.下载 我们之前已经对文件上传下载有过记录,传送门:基于"f ...
- 个人信息——头像更换(拍照或相册上传)~ 微信小程序
微信小程序中 在用户信息中关于用户头像更换(拍照或相册上传)功能实现. 图像点击触发事件: <image src='{{personImage}}' bindtap='changeAvatar' ...
- 如何将ppt演示文稿上传到微信公众号?
如何将ppt演示文稿上传到微信公众号? 我们都知道创建一个微信公众号,在公众号中发布一些文章是非常简单的,但公众号添加附件下载的功能却被限制,如今可以使用小程序“微附件”进行在公众号中添加附件. 以下 ...
- 【UEditor】 UEditor整合项目上传资源到阿里云服务器
目录 关于此文 下载源码 JSP代码 Java代码 阿里云jar包引入配置 成功啦! 回到顶部 关于此文 项目中要实现编辑器生成带格式的html文档,存入模板,最后生成html的URL,所以选择了UE ...
- Git操作指南(2) —— Git Gui for Windows的建库、克隆(clone)、上传(push)、下载(pull)、合并(转)
关于linux上建库等操作请看文章: http://hi.baidu.com/mvp_xuan/blog/item/30f5b700a832f0261d9583ad.html http://hi.ba ...
- (转)Git Gui for Windows的建库、克隆(clone)、上传(push)、下载(pull)、合并
原文地址: http://blog.csdn.net/fym0512/article/details/7713006 本教程将讲述:gitk的Git Gui的部分常用功能和使用方法,包括:建库.克隆( ...
随机推荐
- HTML5 WEB SQL
var database = openDatabase("student1", "1.0", "学生表", 1024 * 1024, fun ...
- JavaScript之数组方法整理
Array概述 除了Object类型,最常用的类型: 实质:有序的数据列表, 特性:可以动态的调整数组的大小 创建数组的两种方式 构造函数创建方式 var arr = ...
- WPF整理--动态绑定到Logical Resource
“What happens if we replace aspecific resource? Would that be reflected in all objects using the res ...
- Oracle Function
Oracle Sql 中常用函数 小写字母转大写字母:upper(); 大写字母转小写字母:lower(); 字符串截取函数:substr(str,a,b); a,b为整数,str为字符串, 截取字符 ...
- oauth基本流程和原理
组装loginurl->去第三方登录验证->回调callbackurl+code(票据)->本地根据code+appid+appkey组装url隐式curl获取用户信息->完成 ...
- maven settings.xml 阿里云
<?xml version="1.0" encoding="UTF-8"?> <!--Licensed to the Apache Softw ...
- Libgdx 循环绘制图片时间隔的问题
在libgdx中使用循环绘制一张图片铺满某个区域时,有可能会遇到像素计算没有问题时,图块中间还是有约1像素的间隔,或者是本来没有间隔,做了缩放处理之后发现中间有间隔. 解法 当使用Texture加载图 ...
- node-webkit 使用requirejs 小结
1. node-webkit 启动页使用requrejs 将webapp中的require改为requirejs,因为requirejs本来就应该用requirejs的,require只是requir ...
- 浅析py-faster-rcnn中不同版本caffe的安装及其对应不同版本cudnn的解决方案
浅析py-faster-rcnn中不同版本caffe的安装及其对应不同版本cudnn的解决方案 本文是截止目前为止最强攻略,按照本文方法基本可以无压力应对caffe和Ross B. Girshick的 ...
- CentOS7.2 编译安装SVN1.9.5客户端
背景 原来想在Linux机上开Samba共享,在Windows机上把工作目录映射到网络驱动器,用Source Insight编辑代码后就不用来回同步文件了. 然而在使用中发现,Windows机用的SV ...