tencentyun / qcloud-cos-sts-sdk

QCloud COS STS SDK for Backend Server
MIT License
200 stars 188 forks source link

获取临时KEY报签名错误 #45

Closed chuxiangqaz closed 4 years ago

chuxiangqaz commented 4 years ago

class CosUploadController extends Controller {

/**
 * 获取 COS 临时KEY
 *
 * @return \Illuminate\Http\JsonResponse
 * @throws \Exception
 *
 * @desc https://cloud.tencent.com/document/product/436/14048
 */
public function tempKey()
{
    $sts = new Sts();
    $config = [
        'url' => 'https://sts.tencentcloudapi.com/',
        'domain' => 'sts.tencentcloudapi.com',
        'proxy' => '',
        // 固定密钥
        'secretId' => config('cos.credentials.secretId'),
        // 固定密钥
        'secretKey' => config('cos.credentials.secretKey'),
        // 换成你的 bucket
        'bucket' => config('cos.credentials.bucket'),
        // 换成 bucket 所在园区
        'region' => config('cos.credentials.region'),
        // 密钥有效期
        'durationSeconds' => 1800,
        // 这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的具体路径,例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用)
        'allowPrefix' => '*',
        // 密钥的权限列表。简单上传和分片需要以下的权限,其他权限列表请看 https://cloud.tencent.com/document/product/436/31923
        'allowActions' => [
            // 简单上传
            'name/cos:PutObject',
            'name/cos:PostObject',
            // 分片上传
            'name/cos:InitiateMultipartUpload',
            'name/cos:ListMultipartUploads',
            'name/cos:ListParts',
            'name/cos:UploadPart',
            'name/cos:CompleteMultipartUpload'
        ]
    ];

    $tempKeys = $sts->getTempKeys(array_filter($config));

    $tempKeys['bucket'] = config('cos.credentials.bucket');
    $tempKeys['region'] = config('cos.credentials.region');

    return $this->success($tempKeys);
}

}


- 响应内容
```json
{
    "Error": {
        "Code": "AuthFailure.SignatureFailure",
        "Message": "The provided credentials could not be validated. Please check your signature is correct."
    },
    "RequestId": "af83286b-9c13-4c73-a62e-ba151b60ca5b"
}
chuxiangqaz commented 4 years ago

由于配置导致错误

youngda commented 4 years ago

同样的错误,请问一下是什么配置错误