qiniu

今天我们主要讲了七牛的安全机制和凭证算法,还有简单的API介绍,通过构建方法自己定制化开发,解决了朋友们不懂七牛APi的烦恼,譬如七牛POST\n如何去构建凭证,为什么会出现{error:bad token},讲解了异步处理的触发和查询,还有就是文件管理等等,详细看视频!视频存储在七牛云储存是公开的大家可以随意下载,https://yun.widuu.com/qiniusafe.flv
附带实验代码
$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>";
//管理凭证demo 异步处理pfop 图片缩放
$accessKey = 'KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR';
$secretKey = 'D-K57TE5hPe3krexftxLWFKmL2xbQEKA-mtkrUfB';
$data = "/pfop/\nbucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200&notifyURL=https://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>";
//demo 查看文件状态
$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
saves保存的url
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");
有问题联系我 QQ23169450

点赞(0) 打赏

Comment list 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部