七牛云存储视频教程-凭证算法-异步处理-文件管理

widuu 2013-12-21 PHP技术 3,712 4 喜欢 (0)

qiniu

今天我们主要讲了七牛的安全机制和凭证算法,还有简单的API介绍,通过构建方法自己定制化开发,解决了朋友们不懂七牛APi的烦恼,譬如七牛POST\n如何去构建凭证,为什么会出现{error:bad token},讲解了异步处理的触发和查询,还有就是文件管理等等,详细看视频!视频存储在七牛云储存是公开的大家可以随意下载,http://widuu.u.qiniudn.com/qiniusafe.flv


附带实验代码
[php]
$accessKey = 'KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR';
$secretKey = 'D-K57TE5hPe3krexftxLWFKmL2xbQEKA-mtkrUfB';

$time = time()+3600;
$data = array(
"scope"=>"gitwiduu",
"deadline"=>$time
);
$data = json_encode($data);
$find = array('+', '/');
$replace = array('-', '_');
$data = str_replace($find, $replace, base64_encode($data));
$sign = hash_hmac('sha1', $data, $secretKey, true);
$result = $accessKey . ':' . str_replace($find, $replace, base64_encode($sign)).':'.$data ;
var_dump($result);echo "<br>";
[/php]

//管理凭证demo 异步处理pfop 图片缩放
[php]
$accessKey = 'KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR';
$secretKey = 'D-K57TE5hPe3krexftxLWFKmL2xbQEKA-mtkrUfB';
$data = "/pfop/\nbucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200&notifyURL=http://yun.widuu.com/";
$find = array('+', '/');
$replace = array('-', '_');
$sign = hash_hmac('sha1', $data, $secretKey, true);
$result = $accessKey . ':' . str_replace($find, $replace, base64_encode($sign));
var_dump($result);echo "<br>";
[/php]

//demo 查看文件状态
[php]
$data = "gitwiduu:weidu.png"; //bucket:key EncodedEntryURI的加密方法
$find = array('+', '/');
$replace = array('-', '_');
$data = str_replace($find, $replace, base64_encode($data));
var_dump($data); //输出EncodedEntryURI的加密方法Z2l0d2lkdXU6d2VpZHUucG5n
$data = "/stat/Z2l0d2lkdXU6d2VpZHUucG5n\n";
$find = array('+', '/');
$replace = array('-', '_');
$sign = hash_hmac('sha1', $data, $secretKey, true);
$result = $accessKey . ':' . str_replace($find, $replace, base64_encode($sign)); //输出所需要token
[/php]

saves保存的url
[php]
function makeUrl($url,$bucket,$savekey,$ak="KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR",$sk="D-K57TE5hPe3krexftxLWFKmL2xbQEKA-mtkrUfB"){
$find = array('+', '/');
$replace = array('-', '_');
$encode = str_replace($find,$replace,base64_encode("$bucket:$savekey"));
$url = $url."|saveas/".$encode;
$sha1 = hash_hmac('sha1',$url,$sk,true);
$sign = $ak.":".(str_replace($find,$replace,base64_encode($sha1)));
$data = $url."/sign/".$sign;
return $data;
}

echo makeUrl("gitwiduu.u.qiniudn.com/weidu.png?imageView/2/w/200/h/200","gitwiduu","widuu.png");
[/php]

有问题联系我 QQ23169450

转载请注明来自微度网络,本文标题:《七牛云存储视频教程-凭证算法-异步处理-文件管理》

喜欢 0 发布评论
  1. 非常感谢楼主解开了我这几天调试七牛上传,流媒体处理经常遇到的凭证报错的问题, 实在受不鸟七牛的SDK了, 由于公司要做一个流媒体的系统,现在终于能看懂那些文档了, 赞一个

Top