七牛云第三方资源抓取报错 bad token

代码如下:

$v = "https://xxx.qbox.me/xxxxx.mp3";

 $encodedURL = str_replace(['+', '/'], ['-', '_'], base64_encode($v));
 $encodedEntryURI = str_replace(['+', '/'], ['-', '_'],base64_encode($qiniu_config['bucket']));
 $url = '/fetch/' . $encodedURL . '/to/' . $encodedEntryURI;
 $sign = hash_hmac('sha1', $url . "\n", $qiniu_config['secretKey'], true);
 $token = $qiniu_config['accessKey'] . ':' . str_replace(['+', '/'], ['-', '_'], base64_encode($sign));
 $header = ['Host: iovip.qbox.me', 'Content-Type:application/x-www-form-urlencoded', 'Authorization: QBox ' . $token];

 $curl = curl_init();
 curl_setopt($curl, CURLOPT_URL, trim('http://iovip.qbox.me' . $url, '\n'));
 curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($curl, CURLOPT_POSTFIELDS, "");
 $result = json_decode(curl_exec($curl), true);
 curl_close($curl);

 if (isset($result['error'])) {
    throw new Exception('文件上传失败: ' . $result['error'])
 }

抛出错误:

bad token

打印出来$token是有值的。。。。

请问是怎么回事啊??

阅读 3.7k
2 个回答

可以打印出来 token ,通过 support.qiniu.com 给七牛提交工单让他们帮排查下。

推荐问题
logo
七牛云问答
子站问答
访问
宣传栏