Skip to content

Commit 0af6cb2

Browse files
authored
Merge pull request #341 from qiniu/hbw
bug fix and add demo
2 parents b4c21f6 + 2fe9de0 commit 0af6cb2

File tree

83 files changed

+1425
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1425
-416
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
## 安装
1414

15-
* 通过composer,这是推荐的方式,可以使用composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 [`qiniu/php-sdk`][install-packagist]
15+
* 推荐使用 `composer` 进行安装。可以使用 composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 [`qiniu/php-sdk`][install-packagist]
1616
```bash
1717
$ composer require qiniu/php-sdk
1818
```
19-
* 直接下载安装,SDK 没有依赖其他第三方库,但需要参照 composer的autoloader,增加一个自己的autoloader程序
19+
* 直接下载安装,SDK 没有依赖其他第三方库,但需要参照 composer 的 autoloader,增加一个自己的 autoloader 程序
2020

2121
## 运行环境
2222

@@ -32,10 +32,10 @@ $ composer require qiniu/php-sdk
3232
use Qiniu\Storage\UploadManager;
3333
use Qiniu\Auth;
3434
...
35-
$upManager = new UploadManager();
35+
$uploadMgr = new UploadManager();
3636
$auth = new Auth($accessKey, $secretKey);
37-
$token = $auth->uploadToken($bucketName);
38-
list($ret, $error) = $upManager->put($token, 'formput', 'hello world');
37+
$token = $auth->uploadToken($bucket);
38+
list($ret, $error) = $uploadMgr->putFile($token, 'key', 'filePath');
3939
...
4040
```
4141

@@ -47,8 +47,8 @@ $ ./vendor/bin/phpunit tests/Qiniu/Tests/
4747

4848
## 常见问题
4949

50-
- $error保留了请求响应的信息,失败情况下ret 为none, 将$error可以打印出来,提交给我们。
51-
- API 的使用 demo 可以参考 [单元测试](https://github.com/qiniu/php-sdk/blob/master/tests)
50+
- `$error` 保留了请求响应的信息,失败情况下 `ret``none`, 将 `$error` 可以打印出来,提交给我们。
51+
- API 的使用 demo 可以参考 [examples](https://github.com/qiniu/php-sdk/tree/master/examples)
5252

5353
## 代码贡献
5454

@@ -61,12 +61,12 @@ $ ./vendor/bin/phpunit tests/Qiniu/Tests/
6161
## 联系我们
6262

6363
- 如果需要帮助,请提交工单(在portal右侧点击咨询和建议提交工单,或者直接向 [email protected] 发送邮件)
64-
- 如果有什么问题,可以到问答社区提问,[问答社区](http://qiniu.segmentfault.com/)
65-
- 更详细的文档,见[官方文档站](http://developer.qiniu.com/)
66-
- 如果发现了bug, 欢迎提交 [issue](https://github.com/qiniu/php-sdk/issues)
64+
- 如果有什么问题,可以到问答社区提问,[问答社区](https://qiniu.segmentfault.com/)
65+
- 更详细的文档,见[官方文档站](https://developer.qiniu.com/)
66+
- 如果发现了 bug, 欢迎提交 [issue](https://github.com/qiniu/php-sdk/issues)
6767
- 如果有功能需求,欢迎提交 [issue](https://github.com/qiniu/php-sdk/issues)
6868
- 如果要提交代码,欢迎提交 pull request
69-
- 欢迎关注我们的[微信](http://www.qiniu.com/#weixin) [微博](http://weibo.com/qiniutek),及时获取动态信息。
69+
- 欢迎关注我们的[微信](https://www.qiniu.com/#weixin) [微博](https://weibo.com/qiniutek),及时获取动态信息。
7070

7171
## 代码许可
7272

examples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# examples
22

3-
这些 examples 旨在帮助你快速了解使用七牛的sdk。这些demo都是可以直接运行的, 但是在运行之前需要填上您自己的参数。
3+
这些 examples 旨在帮助你快速了解使用七牛的 SDK。这些 demo 都是可以直接运行的, 但是在运行之前需要填上您自己的参数。
44

55
比如:
66

7-
* `$bucket` 需要填上您想操作的 [bucket名字](http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket)
8-
* `$accessKey``$secretKey` 可以在我们的[管理后台](https://portal.qiniu.com/setting/key)找到。
9-
* 在进行`视频转码``压缩文件`等异步操作时 需要使用到的队列名称也可以在我们[管理后台](https://portal.qiniu.com/mps/pipeline)新建。
7+
* `$bucket` 需要填上您想操作的 [bucket名字](https://portal.qiniu.com/kodo/bucket)
8+
* `$accessKey``$secretKey` 可以在我们的[管理后台](https://portal.qiniu.com/user/key)找到。
9+
* 在进行`视频转码``压缩文件`等异步操作时 需要使用到的队列名称也可以在我们[管理后台](https://portal.qiniu.com/dora/media-gate/pipeline)新建。
1010

examples/bucket_lifecycleRule.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
require_once __DIR__ . '/../autoload.php';
33

44
use Qiniu\Auth;
5+
use Qiniu\Config;
6+
use Qiniu\Storage\BucketManager;
57

8+
// 控制台获取密钥:https://portal.qiniu.com/user/key
69
$accessKey = getenv('QINIU_ACCESS_KEY');
710
$secretKey = getenv('QINIU_SECRET_KEY');
811

912
$auth = new Auth($accessKey, $secretKey);
10-
$config = new \Qiniu\Config();
11-
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
13+
$config = new Config();
14+
$bucketManager = new BucketManager($auth, $config);
1215

13-
$bucket = 'xxxx';
14-
$name = 'demo';
15-
$prefix = 'test';
16-
$delete_after_days = 80;
17-
$to_line_after_days =70;
16+
// 存储空间 - 新增生命周期规则
17+
// 参考文档:https://developer.qiniu.com/kodo/manual/3699/life-cycle-management
18+
19+
$bucket = 'xxxx'; // 存储空间名称
20+
$name = 'demo'; // 生命周期规则名称
21+
$prefix = 'test'; // 规则策略中的前缀
22+
$delete_after_days = 80; // 用户新创建的文件将在该设定时间之后自动删除
23+
$to_line_after_days = 70; // 用户新创建的文件将在该设定的时间之后自动转为低频存储
1824

1925
list($Info, $err) = $bucketManager->bucketLifecycleRule(
2026
$bucket,

examples/cdn_get_bandwidth.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22

33
require_once __DIR__ . '/../autoload.php';
44

5-
use \Qiniu\Cdn\CdnManager;
5+
use Qiniu\Auth;
6+
use Qiniu\Cdn\CdnManager;
67

8+
// 控制台获取密钥:https://portal.qiniu.com/user/key
79
$accessKey = getenv('QINIU_ACCESS_KEY');
810
$secretKey = getenv('QINIU_SECRET_KEY');
911

10-
$auth = new Qiniu\Auth($accessKey, $secretKey);
12+
$auth = new Auth($accessKey, $secretKey);
1113
$cdnManager = new CdnManager($auth);
1214

13-
//获取流量和带宽数据
14-
//参考文档:http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html
15+
// 获取流量和带宽数据
16+
// 参考文档:https://developer.qiniu.com/fusion/api/1230/traffic-bandwidth
1517

1618
$domains = array(
1719
"javasdk.qiniudn.com",
1820
"phpsdk.qiniudn.com"
1921
);
2022

21-
$startDate = "2017-08-20";
22-
$endDate = "2017-08-21";
23+
$startDate = "2020-08-03";
24+
$endDate = "2020-08-05";
2325

24-
//5min or hour or day
26+
// 5min or hour or day
2527
$granularity = "day";
2628

27-
//获取带宽数据
2829
list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData(
2930
$domains,
3031
$startDate,

examples/cdn_get_flux.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22

33
require_once __DIR__ . '/../autoload.php';
44

5+
use Qiniu\Auth;
56
use \Qiniu\Cdn\CdnManager;
67

8+
// 控制台获取密钥:https://portal.qiniu.com/user/key
79
$accessKey = getenv('QINIU_ACCESS_KEY');
810
$secretKey = getenv('QINIU_SECRET_KEY');
911

10-
$auth = new Qiniu\Auth($accessKey, $secretKey);
12+
$auth = new Auth($accessKey, $secretKey);
1113
$cdnManager = new CdnManager($auth);
1214

13-
//获取流量和带宽数据
14-
//参考文档:http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html
15+
// 获取流量和带宽数据
16+
// 参考文档:https://developer.qiniu.com/fusion/api/1230/traffic-bandwidth
1517

1618
$domains = array(
1719
"javasdk.qiniudn.com",
1820
"phpsdk.qiniudn.com"
1921
);
2022

21-
$startDate = "2017-08-20";
22-
$endDate = "2017-08-21";
23+
$startDate = "2020-08-03";
24+
$endDate = "2020-08-05";
2325

2426
//5min or hour or day
2527
$granularity = "day";
2628

27-
//获取流量数据
2829
list($fluxData, $getFluxErr) = $cdnManager->getFluxData($domains, $startDate, $endDate, $granularity);
2930
if ($getFluxErr != null) {
3031
var_dump($getFluxErr);

examples/cdn_get_log_list.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22

33
require_once __DIR__ . '/../autoload.php';
44

5-
use \Qiniu\Cdn\CdnManager;
5+
use Qiniu\Auth;
6+
use Qiniu\Cdn\CdnManager;
67

8+
// 控制台获取密钥:https://portal.qiniu.com/user/key
79
$accessKey = getenv('QINIU_ACCESS_KEY');
810
$secretKey = getenv('QINIU_SECRET_KEY');
911

10-
$auth = new Qiniu\Auth($accessKey, $secretKey);
12+
$auth = new Auth($accessKey, $secretKey);
1113
$cdnManager = new CdnManager($auth);
1214

15+
// 获取日志下载链接
16+
// 参考文档:https://developer.qiniu.com/fusion/api/1226/download-the-log
17+
1318
$domains = array(
1419
"javasdk.qiniudn.com",
1520
"phpsdk.qiniudn.com"
1621
);
1722

18-
$logDate = '2017-08-20';
19-
20-
//获取日志下载链接
21-
//参考文档:http://developer.qiniu.com/article/fusion/api/log.html
23+
$logDate = '2020-08-05';
2224

2325
list($logListData, $getLogErr) = $cdnManager->getCdnLogList($domains, $logDate);
2426
if ($getLogErr != null) {

examples/cdn_refresh_urls_dirs.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@
22

33
require_once __DIR__ . '/../autoload.php';
44

5-
use \Qiniu\Cdn\CdnManager;
5+
use Qiniu\Auth;
6+
use Qiniu\Cdn\CdnManager;
67

8+
// 控制台获取密钥:https://portal.qiniu.com/user/key
79
$accessKey = getenv('QINIU_ACCESS_KEY');
810
$secretKey = getenv('QINIU_SECRET_KEY');
911

10-
$auth = new Qiniu\Auth($accessKey, $secretKey);
12+
$auth = new Auth($accessKey, $secretKey);
13+
14+
//---------------------------------------- demo1 ----------------------------------------
15+
// 刷新文件和目录
16+
// 文件列表一次最多提交 60 个,目录一次最多提交 10 个
17+
// 参考文档:https://developer.qiniu.com/fusion/api/1229/cache-refresh
1118

12-
//待刷新的文件列表和目录,文件列表最多一次100个,目录最多一次10个
13-
//参考文档:http://developer.qiniu.com/article/fusion/api/refresh.html
1419
$urls = array(
1520
"http://phpsdk.qiniudn.com/qiniu.jpg",
1621
"http://phpsdk.qiniudn.com/qiniu2.jpg",
1722
);
1823

19-
//刷新目录需要联系七牛技术支持开通账户权限
2024
$dirs = array(
2125
"http://phpsdk.qiniudn.com/test/"
2226
);
2327

2428
$cdnManager = new CdnManager($auth);
2529

26-
// 目前客户默认没有目录刷新权限,刷新会有400038报错,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh
27-
// 需要刷新目录请工单联系技术支持 https://support.qiniu.com/tickets/category
30+
// 如果刷新返回 400038 报错,则需要联系七牛技术支持开通刷新目录权限,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh,
2831
list($refreshResult, $refreshErr) = $cdnManager->refreshUrlsAndDirs($urls, $dirs);
2932
if ($refreshErr != null) {
3033
var_dump($refreshErr);
@@ -33,20 +36,24 @@
3336
print_r($refreshResult);
3437
}
3538

36-
//如果只有刷新链接或者目录的需求,可以分布使用
39+
//---------------------------------------- demo2 ----------------------------------------
40+
// 刷新文件
3741

3842
list($refreshResult, $refreshErr) = $cdnManager->refreshUrls($urls);
3943
if ($refreshErr != null) {
4044
var_dump($refreshErr);
4145
} else {
42-
echo "refresh request sent\n";
46+
echo "refresh urls request sent\n";
4347
print_r($refreshResult);
4448
}
4549

50+
//---------------------------------------- demo3 ----------------------------------------
51+
// 刷新目录
52+
4653
list($refreshResult, $refreshErr) = $cdnManager->refreshDirs($dirs);
4754
if ($refreshErr != null) {
4855
var_dump($refreshErr);
4956
} else {
50-
echo "refresh request sent\n";
57+
echo "refresh dirs request sent\n";
5158
print_r($refreshResult);
5259
}

examples/cdn_timestamp_antileech.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
require_once __DIR__ . '/../autoload.php';
44

5-
use \Qiniu\Cdn\CdnManager;
5+
use Qiniu\Cdn\CdnManager;
6+
7+
// 创建带时间戳防盗链的 URL
8+
// 参考文档:https://developer.qiniu.com/fusion/manual/3841/timestamp-hotlinking-prevention-fusion
69

7-
//创建时间戳防盗链
8-
//时间戳防盗链密钥,后台获取
910
$encryptKey = 'your_domain_timestamp_antileech_encryptkey';
1011

11-
//带访问协议的域名
12-
$url1 = 'http://phpsdk.qiniuts.com/24.jpg?avinfo';
12+
// 一定要带访问协议,也就是 http:// 或者 https://
13+
$url1 = 'http://phpsdk.qiniuts.com/24.jpg?imageInfo';
1314
$url2 = 'http://phpsdk.qiniuts.com/24.jpg';
1415

15-
//有效期时间(单位秒)
16+
// 有效期时间(单位秒)
1617
$durationInSeconds = 3600;
1718

1819
$signedUrl = CdnManager::createTimestampAntiLeechUrl($url1, $encryptKey, $durationInSeconds);

examples/censor_image.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use Qiniu\Auth;
6+
use Qiniu\Config;
7+
use Qiniu\Storage\ArgusManager;
8+
9+
// 控制台获取密钥:https://portal.qiniu.com/user/key
10+
$accessKey = getenv('QINIU_ACCESS_KEY');
11+
$secretKey = getenv('QINIU_SECRET_KEY');
12+
13+
14+
$auth = new Auth($accessKey, $secretKey);
15+
16+
$config = new Config();
17+
$argusManager = new ArgusManager($auth, $config);
18+
19+
// 图片内容审核
20+
// 参考文档:https://developer.qiniu.com/censor/api/5588/image-censor
21+
22+
$body = '{
23+
"data":{
24+
"uri":"https://www-static.qbox.me/_next/static/media/pic01.c8b5db2cc5fcb6fc4e6349c9e37c8e6b.png"
25+
},
26+
"params":{
27+
"scenes":[
28+
"pulp",
29+
"terror",
30+
"politician",
31+
"ads"
32+
]
33+
}
34+
}';
35+
36+
list($ret, $err) = $argusManager->censorImage($body);
37+
echo "\n====> Result is: \n";
38+
if ($err !== null) {
39+
var_dump($err);
40+
} else {
41+
var_dump($ret);
42+
}

0 commit comments

Comments
 (0)