//代码是这样的,我要异步处理图片持久化
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");
输出url是
gitwiduu.u.qiniudn.com/weidu.png?imageView/2/w/200/h/200|saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=
//然后拼接params
//bucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=¬ifyURL=http://localhost/
function url_safe_baseencode($str) // URLSafeBase64Encode
{
$find = array('+', '/');
$replace = array('-', '_');
return str_replace($find, $replace, base64_encode($str));
}
function sign1($data,$ak="KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR",$sk="D-K57TE5hPe3krexftxLWFKmL2xbQEKA-mtkrUfB"){
$sign = hash_hmac('sha1', $data, $sk, true);
return $ak.':'.url_safe_baseencode($sign);
}
//根据官方文档path?querynbody 加密输出结果
sign1("/pfop\nbucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=¬ifyURL=http://localhost/");
//获取Authorization token
//输出 token 是 KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:8nodNoJ7A8QE59UNrlMXSs-2ATY=
然后php curl 实验不行 然后在linux下实验
curl -d "bucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=¬ifyURL=http://localhost/" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: QBox KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:8nodNoJ7A8QE59UNrlMXSs-2ATY=" http://api.qiniu.com/pfop
//或者到 http://api.qiniu.com/pfop/ 都是返回json出现{"error":"bad token"}" 请问一下哪里出的错误呀
1、手动触发的persistentOps持久化可以上网查询,好多例子
2、实际你的需求不需要用到持久化,saveas就可以了。看了一下,得到的saveas的url是正确的
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。