关于触发异步处理{"error":"bad token"}

WBOY
Lepaskan: 2016-06-06 20:47:58
asal
2300 orang telah melayarinya

<code>//代码是这样的,我要异步处理图片持久化 
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>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");
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//输出url是
</code>
Salin selepas log masuk
Salin selepas log masuk

gitwiduu.u.qiniudn.com/weidu.png?imageView/2/w/200/h/200|saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=

<code>//然后拼接params
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//bucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=&notifyURL=http://localhost/
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>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);
}
</code>
Salin selepas log masuk
Salin selepas log masuk

//根据官方文档path?query\nbody 加密输出结果

<code>echo sign1("/pfop\nbucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=&notifyURL=http://localhost/");
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//获取Authorization token
//输出 token 是 KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:8nodNoJ7A8QE59UNrlMXSs-2ATY=
然后php curl 实验不行 然后在linux下实验
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>curl -d "bucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=&notifyURL=http://localhost/" -H  "Content-Type: application/x-www-form-urlencoded" -H "Authorization: QBox KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:8nodNoJ7A8QE59UNrlMXSs-2ATY=" http://api.qiniu.com/pfop
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//或者到 http://api.qiniu.com/pfop/ 都是返回json出现{"error":"bad token"}" 请问一下哪里出的错误呀 
</code>
Salin selepas log masuk
Salin selepas log masuk

回复内容:

<code>//代码是这样的,我要异步处理图片持久化 
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>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");
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//输出url是
</code>
Salin selepas log masuk
Salin selepas log masuk

gitwiduu.u.qiniudn.com/weidu.png?imageView/2/w/200/h/200|saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=

<code>//然后拼接params
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//bucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=&notifyURL=http://localhost/
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>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);
}
</code>
Salin selepas log masuk
Salin selepas log masuk

//根据官方文档path?query\nbody 加密输出结果

<code>echo sign1("/pfop\nbucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=&notifyURL=http://localhost/");
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//获取Authorization token
//输出 token 是 KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:8nodNoJ7A8QE59UNrlMXSs-2ATY=
然后php curl 实验不行 然后在linux下实验
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>curl -d "bucket=gitwiduu&key=weidu.png&fops=imageView/2/w/200/h/200;saveas/Z2l0d2lkdXU6d2lkdXUucG5n/sign/KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:oLnyNAFkj7gs6a0LyLJ581bCS_Q=&notifyURL=http://localhost/" -H  "Content-Type: application/x-www-form-urlencoded" -H "Authorization: QBox KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR:8nodNoJ7A8QE59UNrlMXSs-2ATY=" http://api.qiniu.com/pfop
</code>
Salin selepas log masuk
Salin selepas log masuk
<code>//或者到 http://api.qiniu.com/pfop/ 都是返回json出现{"error":"bad token"}" 请问一下哪里出的错误呀 
</code>
Salin selepas log masuk
Salin selepas log masuk

1、手动触发的persistentOps持久化可以参考: http://segmentfault.com/q/1010000000331820
2、实际你的需求不需要用到持久化,saveas就可以了。看了一下,得到的saveas的url是正确的

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!