Skip to content

Commit 5896270

Browse files
committed
update php sdk examples
1 parent 7e3c139 commit 5896270

29 files changed

+688
-222
lines changed

examples/bucket_mgr.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

examples/bucket_mgr_init.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/cdn_get_bandwidth.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use \Qiniu\Cdn\CdnManager;
6+
7+
$accessKey = getenv('QINIU_ACCESS_KEY');
8+
$secretKey = getenv('QINIU_SECRET_KEY');
9+
10+
$auth = new Qiniu\Auth($accessKey, $secretKey);
11+
$cdnManager = new CdnManager($auth);
12+
13+
//获取流量和带宽数据
14+
//参考文档:http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html
15+
16+
$domains = array(
17+
"javasdk.qiniudn.com",
18+
"phpsdk.qiniudn.com"
19+
);
20+
21+
$startDate = "2017-08-20";
22+
$endDate = "2017-08-21";
23+
24+
//5min or hour or day
25+
$granularity = "day";
26+
27+
//获取带宽数据
28+
list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData($domains, $startDate, $endDate, $granularity);
29+
if ($getBandwidthErr != null) {
30+
var_dump($getBandwidthErr);
31+
} else {
32+
echo "get bandwidth data success\n";
33+
print_r($bandwidthData);
34+
}

examples/cdn_get_flux.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use \Qiniu\Cdn\CdnManager;
6+
7+
$accessKey = getenv('QINIU_ACCESS_KEY');
8+
$secretKey = getenv('QINIU_SECRET_KEY');
9+
10+
$auth = new Qiniu\Auth($accessKey, $secretKey);
11+
$cdnManager = new CdnManager($auth);
12+
13+
//获取流量和带宽数据
14+
//参考文档:http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html
15+
16+
$domains = array(
17+
"javasdk.qiniudn.com",
18+
"phpsdk.qiniudn.com"
19+
);
20+
21+
$startDate = "2017-08-20";
22+
$endDate = "2017-08-21";
23+
24+
//5min or hour or day
25+
$granularity = "day";
26+
27+
//获取流量数据
28+
list($fluxData, $getFluxErr) = $cdnManager->getFluxData($domains, $startDate, $endDate, $granularity);
29+
if ($getFluxErr != null) {
30+
var_dump($getFluxErr);
31+
} else {
32+
echo "get flux data success\n";
33+
print_r($fluxData);
34+
}

examples/cdn_get_log_list.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use \Qiniu\Cdn\CdnManager;
6+
7+
$accessKey = getenv('QINIU_ACCESS_KEY');
8+
$secretKey = getenv('QINIU_SECRET_KEY');
9+
10+
$auth = new Qiniu\Auth($accessKey, $secretKey);
11+
$cdnManager = new CdnManager($auth);
12+
13+
$domains = array(
14+
"javasdk.qiniudn.com",
15+
"phpsdk.qiniudn.com"
16+
);
17+
18+
$logDate='2017-08-20';
19+
20+
//获取日志下载链接
21+
//参考文档:http://developer.qiniu.com/article/fusion/api/log.html
22+
23+
list($logListData, $getLogErr) = $cdnManager->getCdnLogList($domains, $logDate);
24+
if ($getLogErr != null) {
25+
var_dump($getLogErr);
26+
} else {
27+
echo "get cdn log list success\n";
28+
print_r($logListData);
29+
}

examples/cdn_manager.php

Lines changed: 0 additions & 89 deletions
This file was deleted.

examples/cdn_refresh_urls_dirs.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use \Qiniu\Cdn\CdnManager;
6+
7+
$accessKey = getenv('QINIU_ACCESS_KEY');
8+
$secretKey = getenv('QINIU_SECRET_KEY');
9+
10+
$auth = new Qiniu\Auth($accessKey, $secretKey);
11+
12+
//待刷新的文件列表和目录,文件列表最多一次100个,目录最多一次10个
13+
//参考文档:http://developer.qiniu.com/article/fusion/api/refresh.html
14+
$urls = array(
15+
"http://phpsdk.qiniudn.com/qiniu.jpg",
16+
"http://phpsdk.qiniudn.com/qiniu2.jpg",
17+
);
18+
19+
//刷新目录需要联系七牛技术支持开通账户权限
20+
$dirs = array(
21+
"http://phpsdk.qiniudn.com/test/"
22+
);
23+
24+
$cdnManager = new CdnManager($auth);
25+
26+
// 目前客户默认没有目录刷新权限,刷新会有400038报错,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh
27+
// 需要刷新目录请工单联系技术支持 https://support.qiniu.com/tickets/category
28+
list($refreshResult, $refreshErr) = $cdnManager->refreshUrlsAndDirs($urls, $dirs);
29+
if ($refreshErr != null) {
30+
var_dump($refreshErr);
31+
} else {
32+
echo "refresh request sent\n";
33+
print_r($refreshResult);
34+
}
35+
36+
//如果只有刷新链接或者目录的需求,可以分布使用
37+
38+
list($refreshResult, $refreshErr) = $cdnManager->refreshUrls($urls);
39+
if ($refreshErr != null) {
40+
var_dump($refreshErr);
41+
} else {
42+
echo "refresh request sent\n";
43+
print_r($refreshResult);
44+
}
45+
46+
list($refreshResult, $refreshErr) = $cdnManager->refreshDirs($dirs);
47+
if ($refreshErr != null) {
48+
var_dump($refreshErr);
49+
} else {
50+
echo "refresh request sent\n";
51+
print_r($refreshResult);
52+
}
53+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use \Qiniu\Cdn\CdnManager;
6+
7+
//创建时间戳防盗链
8+
//时间戳防盗链密钥,后台获取
9+
$encryptKey = 'your_domain_timestamp_antileech_encryptkey';
10+
11+
//带访问协议的域名
12+
$url1 = 'http://phpsdk.qiniuts.com/24.jpg?avinfo';
13+
$url2 = 'http://phpsdk.qiniuts.com/24.jpg';
14+
15+
//有效期时间(单位秒)
16+
$durationInSeconds = 3600;
17+
18+
$signedUrl = CdnManager::createTimestampAntiLeechUrl($url1, $encryptKey, $durationInSeconds);
19+
print($signedUrl);

examples/notify.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/pfop_mkzip.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Processing\PersistentFop;
6+
7+
// 去我们的portal 后台来获取AK, SK
8+
$accessKey = getenv('QINIU_ACCESS_KEY');
9+
$secretKey = getenv('QINIU_SECRET_KEY');
10+
$bucket = getenv('QINIU_TEST_BUCKET');
11+
$key = 'qiniu.png';
12+
13+
$auth = new Auth($accessKey, $secretKey);
14+
// 异步任务的队列, 去后台新建: https://portal.qiniu.com/mps/pipeline
15+
$pipeline = 'sdktest';
16+
17+
$pfop = new PersistentFop($auth, null);
18+
19+
// 进行zip压缩的url
20+
$url1 = 'http://phpsdk.qiniudn.com/php-logo.png';
21+
$url2 = 'http://phpsdk.qiniudn.com/1.png';
22+
23+
//压缩后的key
24+
$zipKey = 'test.zip';
25+
26+
$fops = 'mkzip/2/url/' . \Qiniu\base64_urlSafeEncode($url1);
27+
$fops .= '/url/' . \Qiniu\base64_urlSafeEncode($url2);
28+
$fops .= '|saveas/' . \Qiniu\base64_urlSafeEncode("$bucket:$zipKey");
29+
30+
$notify_url = null;
31+
$force = false;
32+
33+
list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notify_url, $force);
34+
35+
echo "\n====> pfop mkzip result: \n";
36+
if ($err != null) {
37+
var_dump($err);
38+
} else {
39+
echo "PersistentFop Id: $id\n";
40+
41+
$res = "http://api.qiniu.com/status/get/prefop?id=$id";
42+
echo "Processing result: $res";
43+
}

0 commit comments

Comments
 (0)