按照官网提供的接口,最后是bad token ??
qiniu/nodejs-sdk
const qiniu = require('qiniu');
const mac = new qiniu.auth.digest.Mac(ak, sk);
const accessToken = qiniu.util.generateAccessTokenV2(
mac,
'http://api.qiniu.com/v6/domain/list?tbl=空间名称',
'GET',
'application/x-www-form-urlencoded');
console.log(accessToken);
Nodejs
const crypto = require('crypto');
const ak = 'xxxx';
const sk = 'xxx';
const data = 'GET /v6/domain/list?tbl=空间名称\nHost: api.qiniu.com\nContent-Type: application/x-www-form-urlencoded\n\n';
const hmac = crypto.createHmac('sha1', sk);
hmac.update(data);
const key = hmac.digest('base64');
const accessToken = ak
+ ':'
+ key
.replace(/+/g, '-') // /\+/g
.replace(///g, '_'); // /\//g
console.log('Qiniu ' + accessToken);
看起来是 token 签算有问题,所以报错了 bad token,如下提供一个 PHP 的 demo 供楼主参考