Compare commits

...

2 Commits

3 changed files with 58 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
}, },
"require": { "require": {
"php": ">=7.1.0", "php": ">=7.1.0",
"qcloud/cos-sdk-v5": ">=2.0",
"cloudflare/sdk": "^1.1", "cloudflare/sdk": "^1.1",
"guzzlehttp/guzzle": "~6.0" "guzzlehttp/guzzle": "~6.0"
} }

View File

@@ -10,3 +10,9 @@ $globalConfig['cloudflare'] = [
$globalConfig['dingtalk_token'] = 'your_token'; $globalConfig['dingtalk_token'] = 'your_token';
$globalConfig['COS'] = [
'bucket' => 'bucket', //存储桶名称 格式BucketName-APPID
'secretId' => 'secretId', //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
'secretKey' => 'secretKey', //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
'region' => 'region', //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
];

51
jobs/cos.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
require_once __DIR__ . '/../init.php';
global $globalConfig;
$bucket = $globalConfig['bucket'];
$secretId = $globalConfig['secretId'];
$secretKey = $globalConfig['secretKey'];
$region = $globalConfig['region'];
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https', //协议头部默认为http
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey,
)
)
);
try {
$result = $cosClient->listObjects(['Bucket' => $bucket]);
// 请求成功
if (isset($result['Contents'])) {
foreach ($result['Contents'] as $rt) {
if ($rt['StorageClass'] !== 'DEEP_ARCHIVE') {
$result = $cosClient->Copy(
$bucket,
$rt['Key'], //此处的 key 为对象键
[
'Region' => $region,
'Bucket' => $bucket,
'Key' => $rt['Key'],
],
[
'StorageClass' => 'DEEP_ARCHIVE'
]
);
var_dump(json_encode($result));
}
}
}
} catch (\Exception $e) {
var_dump($e);
}