七牛整合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的部分常用功能和使用方法,包括:建库.克隆( ...
随机推荐
- hibernate 异常:Unexpected Exception caught setting
异常信息:Unexpected Exception caught setting 'outHeight' on 'class com.srpm.core.project.seismicFortific ...
- windows下读取磁盘扇区数据
在Windows下,磁盘可以看做是一个文件,其文件名为\\\\.\\PhysicalDriveX,其中X表示磁盘的编号,例如\\\\.\\PhysicalDrive0表示的是第0号磁盘,如果需要读取一 ...
- 将博客从jekyll迁移到了hexo
关于hexo和jekyll hexo和jekyll一样都是个静态网站生成工具,hexo是一个台湾小伙使用nodejs开发的,jekyll则是用ruby开发,github内置了jekyll,可以直接将j ...
- 使用 PHP 内置函数 get_browser() 判断是否是移动浏览器
get_browser — 获取浏览器具有的功能.该函数通过查找 browscap.ini 文件中的浏览器信息,尝试检测用户的浏览器所具有的功能. 由于许可证的问题,PHP 未提供浏览器功能文件,可以 ...
- Thinking in Java——笔记(18)
I/O The original byte-oriented library was supplemented with char-oriented, Unicode-based I/O classe ...
- mysql 创建索引和删除索引
索引的创建可以在CREATE TABLE语句中进行,也可以单独用CREATE INDEX或ALTER TABLE来给表增加索引.删除索引可以利用ALTER TABLE或DROP INDEX语句来实现. ...
- (TODO:)下载图片,报错:warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
想使用NSInvocationOperation下载图片,然而并没有下载下来, NSData为nil, 还有报错:(打断点就报错) warning: could not load any Object ...
- bahuanghou111
#include<stdio.h> int map[8][8]={0}; int count=0; int safe(int x,int y) { int i; int j; for(i= ...
- (。・・)ノ~个人java学习随笔记录
基本认识 1.编程思维 根据这几天的java学习,编写程序最重要的就是要有一个清晰的思路.语法上的错误可以跟随着不断的联系与学习来弥补,清晰的思维却只有自己来前期模仿,后面慢慢摸索形成一套属于自己的思 ...
- android模拟器没有键盘的解决方法
刚开始使用android模拟器的时候,发现自己创建的AVD启动后没有出现侧边的键盘,在网上搜索后,发现很多人都有这个问题,也有文章说直接使用PC上的键盘,因为有对应的快捷键.但是,没有键盘,始终不爽! ...