First commit
This commit is contained in:
10
app/Common/extend/qiniu/examples/README.md
Executable file
10
app/Common/extend/qiniu/examples/README.md
Executable file
@@ -0,0 +1,10 @@
|
||||
# examples
|
||||
|
||||
这些 examples 旨在帮助你快速了解使用七牛的sdk。这些demo都是可以直接运行的, 但是在运行之前需要填上您自己的参数。
|
||||
|
||||
比如:
|
||||
|
||||
* `$bucket` 需要填上您想操作的 [bucket名字](http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket)。
|
||||
* `$accessKey` 和 `$secretKey` 可以在我们的[管理后台](https://portal.qiniu.com/setting/key)找到。
|
||||
* 在进行`视频转码`, `压缩文件`等异步操作时 需要使用到的队列名称也可以在我们[管理后台](https://portal.qiniu.com/mps/pipeline)新建。
|
||||
|
||||
40
app/Common/extend/qiniu/examples/cdn_get_bandwidth.php
Executable file
40
app/Common/extend/qiniu/examples/cdn_get_bandwidth.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Cdn\CdnManager;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
|
||||
$auth = new Qiniu\Auth($accessKey, $secretKey);
|
||||
$cdnManager = new CdnManager($auth);
|
||||
|
||||
//获取流量和带宽数据
|
||||
//参考文档:http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html
|
||||
|
||||
$domains = array(
|
||||
"javasdk.qiniudn.com",
|
||||
"phpsdk.qiniudn.com"
|
||||
);
|
||||
|
||||
$startDate = "2017-08-20";
|
||||
$endDate = "2017-08-21";
|
||||
|
||||
//5min or hour or day
|
||||
$granularity = "day";
|
||||
|
||||
//获取带宽数据
|
||||
list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData(
|
||||
$domains,
|
||||
$startDate,
|
||||
$endDate,
|
||||
$granularity
|
||||
);
|
||||
|
||||
if ($getBandwidthErr != null) {
|
||||
var_dump($getBandwidthErr);
|
||||
} else {
|
||||
echo "get bandwidth data success\n";
|
||||
print_r($bandwidthData);
|
||||
}
|
||||
34
app/Common/extend/qiniu/examples/cdn_get_flux.php
Executable file
34
app/Common/extend/qiniu/examples/cdn_get_flux.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Cdn\CdnManager;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
|
||||
$auth = new Qiniu\Auth($accessKey, $secretKey);
|
||||
$cdnManager = new CdnManager($auth);
|
||||
|
||||
//获取流量和带宽数据
|
||||
//参考文档:http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html
|
||||
|
||||
$domains = array(
|
||||
"javasdk.qiniudn.com",
|
||||
"phpsdk.qiniudn.com"
|
||||
);
|
||||
|
||||
$startDate = "2017-08-20";
|
||||
$endDate = "2017-08-21";
|
||||
|
||||
//5min or hour or day
|
||||
$granularity = "day";
|
||||
|
||||
//获取流量数据
|
||||
list($fluxData, $getFluxErr) = $cdnManager->getFluxData($domains, $startDate, $endDate, $granularity);
|
||||
if ($getFluxErr != null) {
|
||||
var_dump($getFluxErr);
|
||||
} else {
|
||||
echo "get flux data success\n";
|
||||
print_r($fluxData);
|
||||
}
|
||||
29
app/Common/extend/qiniu/examples/cdn_get_log_list.php
Executable file
29
app/Common/extend/qiniu/examples/cdn_get_log_list.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Cdn\CdnManager;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
|
||||
$auth = new Qiniu\Auth($accessKey, $secretKey);
|
||||
$cdnManager = new CdnManager($auth);
|
||||
|
||||
$domains = array(
|
||||
"javasdk.qiniudn.com",
|
||||
"phpsdk.qiniudn.com"
|
||||
);
|
||||
|
||||
$logDate = '2017-08-20';
|
||||
|
||||
//获取日志下载链接
|
||||
//参考文档:http://developer.qiniu.com/article/fusion/api/log.html
|
||||
|
||||
list($logListData, $getLogErr) = $cdnManager->getCdnLogList($domains, $logDate);
|
||||
if ($getLogErr != null) {
|
||||
var_dump($getLogErr);
|
||||
} else {
|
||||
echo "get cdn log list success\n";
|
||||
print_r($logListData);
|
||||
}
|
||||
52
app/Common/extend/qiniu/examples/cdn_refresh_urls_dirs.php
Executable file
52
app/Common/extend/qiniu/examples/cdn_refresh_urls_dirs.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Cdn\CdnManager;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
|
||||
$auth = new Qiniu\Auth($accessKey, $secretKey);
|
||||
|
||||
//待刷新的文件列表和目录,文件列表最多一次100个,目录最多一次10个
|
||||
//参考文档:http://developer.qiniu.com/article/fusion/api/refresh.html
|
||||
$urls = array(
|
||||
"http://phpsdk.qiniudn.com/qiniu.jpg",
|
||||
"http://phpsdk.qiniudn.com/qiniu2.jpg",
|
||||
);
|
||||
|
||||
//刷新目录需要联系七牛技术支持开通账户权限
|
||||
$dirs = array(
|
||||
"http://phpsdk.qiniudn.com/test/"
|
||||
);
|
||||
|
||||
$cdnManager = new CdnManager($auth);
|
||||
|
||||
// 目前客户默认没有目录刷新权限,刷新会有400038报错,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh
|
||||
// 需要刷新目录请工单联系技术支持 https://support.qiniu.com/tickets/category
|
||||
list($refreshResult, $refreshErr) = $cdnManager->refreshUrlsAndDirs($urls, $dirs);
|
||||
if ($refreshErr != null) {
|
||||
var_dump($refreshErr);
|
||||
} else {
|
||||
echo "refresh request sent\n";
|
||||
print_r($refreshResult);
|
||||
}
|
||||
|
||||
//如果只有刷新链接或者目录的需求,可以分布使用
|
||||
|
||||
list($refreshResult, $refreshErr) = $cdnManager->refreshUrls($urls);
|
||||
if ($refreshErr != null) {
|
||||
var_dump($refreshErr);
|
||||
} else {
|
||||
echo "refresh request sent\n";
|
||||
print_r($refreshResult);
|
||||
}
|
||||
|
||||
list($refreshResult, $refreshErr) = $cdnManager->refreshDirs($dirs);
|
||||
if ($refreshErr != null) {
|
||||
var_dump($refreshErr);
|
||||
} else {
|
||||
echo "refresh request sent\n";
|
||||
print_r($refreshResult);
|
||||
}
|
||||
19
app/Common/extend/qiniu/examples/cdn_timestamp_antileech.php
Executable file
19
app/Common/extend/qiniu/examples/cdn_timestamp_antileech.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Cdn\CdnManager;
|
||||
|
||||
//创建时间戳防盗链
|
||||
//时间戳防盗链密钥,后台获取
|
||||
$encryptKey = 'your_domain_timestamp_antileech_encryptkey';
|
||||
|
||||
//带访问协议的域名
|
||||
$url1 = 'http://phpsdk.qiniuts.com/24.jpg?avinfo';
|
||||
$url2 = 'http://phpsdk.qiniuts.com/24.jpg';
|
||||
|
||||
//有效期时间(单位秒)
|
||||
$durationInSeconds = 3600;
|
||||
|
||||
$signedUrl = CdnManager::createTimestampAntiLeechUrl($url1, $encryptKey, $durationInSeconds);
|
||||
print($signedUrl);
|
||||
74
app/Common/extend/qiniu/examples/image_url_builder.php
Executable file
74
app/Common/extend/qiniu/examples/image_url_builder.php
Executable file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
// 引入图片处理类
|
||||
use Qiniu\Processing\ImageUrlBuilder;
|
||||
|
||||
$imageUrlBuilder = new ImageUrlBuilder();
|
||||
|
||||
// 要处理图片
|
||||
$url = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg';
|
||||
$url2 = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg?watermark/1/gravity/SouthEast/dx/0/dy/0/image/'
|
||||
. 'aHR0cDovL2Fkcy1jZG4uY2h1Y2h1amllLmNvbS9Ga1R6bnpIY2RLdmRBUFc5cHZZZ3pTc21UY0tB';
|
||||
$waterImage = 'http://developer.qiniu.com/resource/logo-2.jpg';
|
||||
|
||||
/**
|
||||
* 缩略图链接拼接
|
||||
*
|
||||
* @param string $url 图片链接
|
||||
* @param int $mode 缩略模式
|
||||
* @param int $width 宽度
|
||||
* @param int $height 长度
|
||||
* @param string $format 输出类型 [可选]
|
||||
* @param int $quality 图片质量 [可选]
|
||||
* @param int $interlace 是否支持渐进显示 [可选]
|
||||
* @param int $ignoreError 忽略结果 [可选]
|
||||
* @return string
|
||||
* @link http://developer.qiniu.com/code/v6/api/kodo-api/image/imageview2.html
|
||||
* @author Sherlock Ren <sherlock_ren@icloud.com>
|
||||
*/
|
||||
$thumbLink = $imageUrlBuilder->thumbnail($url, 1, 100, 100);
|
||||
|
||||
// 函数方式调用 也可拼接多个操作参数 图片+水印
|
||||
$thumbLink2 = \Qiniu\thumbnail($url2, 1, 100, 100);
|
||||
var_dump($thumbLink, $thumbLink2);
|
||||
|
||||
/**
|
||||
* 图片水印
|
||||
*
|
||||
* @param string $url 图片链接
|
||||
* @param string $image 水印图片链接
|
||||
* @param numeric $dissolve 透明度 [可选]
|
||||
* @param string $gravity 水印位置 [可选]
|
||||
* @param numeric $dx 横轴边距 [可选]
|
||||
* @param numeric $dy 纵轴边距 [可选]
|
||||
* @param numeric $watermarkScale 自适应原图的短边比例 [可选]
|
||||
* @link http://developer.qiniu.com/code/v6/api/kodo-api/image/watermark.html
|
||||
* @return string
|
||||
* @author Sherlock Ren <sherlock_ren@icloud.com>
|
||||
*/
|
||||
$waterLink = $imageUrlBuilder->waterImg($url, $waterImage);
|
||||
// 函数调用方法
|
||||
//$waterLink = \Qiniu\waterImg($url, $waterImage);
|
||||
var_dump($waterLink);
|
||||
|
||||
/**
|
||||
* 文字水印
|
||||
*
|
||||
* @param string $url 图片链接
|
||||
* @param string $text 文字
|
||||
* @param string $font 文字字体
|
||||
* @param string $fontSize 文字字号
|
||||
* @param string $fontColor 文字颜色 [可选]
|
||||
* @param numeric $dissolve 透明度 [可选]
|
||||
* @param string $gravity 水印位置 [可选]
|
||||
* @param numeric $dx 横轴边距 [可选]
|
||||
* @param numeric $dy 纵轴边距 [可选]
|
||||
* @link http://developer.qiniu.com/code/v6/api/kodo-api/image/watermark.html#text-watermark
|
||||
* @return string
|
||||
* @author Sherlock Ren <sherlock_ren@icloud.com>
|
||||
*/
|
||||
$textLink = $imageUrlBuilder->waterText($url, '你瞅啥', '微软雅黑', 300);
|
||||
// 函数调用方法
|
||||
// $textLink = \Qiniu\waterText($url, '你瞅啥', '微软雅黑', 300);
|
||||
var_dump($textLink);
|
||||
19
app/Common/extend/qiniu/examples/persistent_fop_init.php
Executable file
19
app/Common/extend/qiniu/examples/persistent_fop_init.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
$accessKey = 'Access_Key';
|
||||
$secretKey = 'Secret_Key';
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
// 要转码的文件所在的空间。
|
||||
$bucket = 'Bucket_Name';
|
||||
|
||||
// 转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
|
||||
$pipeline = 'pipeline_name';
|
||||
|
||||
// 初始化
|
||||
$pfop = new PersistentFop($auth, $bucket, $pipeline);
|
||||
18
app/Common/extend/qiniu/examples/persistent_fop_status.php
Executable file
18
app/Common/extend/qiniu/examples/persistent_fop_status.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
$pfop = new Qiniu\Processing\PersistentFop(null, null);
|
||||
|
||||
// 触发持久化处理后返回的 Id
|
||||
$persistentId = 'z1.5b8a48e5856db843bc24cfc3';
|
||||
|
||||
// 通过persistentId查询该 触发持久化处理的状态
|
||||
list($ret, $err) = $pfop->status($persistentId);
|
||||
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
43
app/Common/extend/qiniu/examples/pfop_mkzip.php
Executable file
43
app/Common/extend/qiniu/examples/pfop_mkzip.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
// 去我们的portal 后台来获取AK, SK
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$key = 'qiniu.png';
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
// 异步任务的队列, 去后台新建: https://portal.qiniu.com/mps/pipeline
|
||||
$pipeline = 'sdktest';
|
||||
|
||||
$pfop = new PersistentFop($auth, null);
|
||||
|
||||
// 进行zip压缩的url
|
||||
$url1 = 'http://phpsdk.qiniudn.com/php-logo.png';
|
||||
$url2 = 'http://phpsdk.qiniudn.com/1.png';
|
||||
|
||||
//压缩后的key
|
||||
$zipKey = 'test.zip';
|
||||
|
||||
$fops = 'mkzip/2/url/' . \Qiniu\base64_urlSafeEncode($url1);
|
||||
$fops .= '/url/' . \Qiniu\base64_urlSafeEncode($url2);
|
||||
$fops .= '|saveas/' . \Qiniu\base64_urlSafeEncode("$bucket:$zipKey");
|
||||
|
||||
$notify_url = null;
|
||||
$force = false;
|
||||
|
||||
list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notify_url, $force);
|
||||
|
||||
echo "\n====> pfop mkzip result: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
echo "PersistentFop Id: $id\n";
|
||||
|
||||
$res = "http://api.qiniu.com/status/get/prefop?id=$id";
|
||||
echo "Processing result: $res";
|
||||
}
|
||||
46
app/Common/extend/qiniu/examples/pfop_vframe.php
Executable file
46
app/Common/extend/qiniu/examples/pfop_vframe.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
//对已经上传到七牛的视频发起异步转码操作
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
//要转码的文件所在的空间和文件名。
|
||||
$key = 'qiniu.mp4';
|
||||
|
||||
//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
|
||||
$pipeline = 'sdktest';
|
||||
|
||||
//转码完成后通知到你的业务服务器。
|
||||
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
|
||||
$force = false;
|
||||
|
||||
$config = new \Qiniu\Config();
|
||||
$config->useHTTPS = true;
|
||||
$pfop = new PersistentFop($auth, $config);
|
||||
|
||||
//要进行视频截图操作
|
||||
$fops = "vframe/jpg/offset/1/w/480/h/360/rotate/90|saveas/" .
|
||||
\Qiniu\base64_urlSafeEncode($bucket . ":qiniu_480x360.jpg");
|
||||
|
||||
list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
|
||||
echo "\n====> pfop avthumb result: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
echo "PersistentFop Id: $id\n";
|
||||
}
|
||||
|
||||
//查询转码的进度和状态
|
||||
list($ret, $err) = $pfop->status($id);
|
||||
echo "\n====> pfop avthumb status: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
47
app/Common/extend/qiniu/examples/pfop_video_avthumb.php
Executable file
47
app/Common/extend/qiniu/examples/pfop_video_avthumb.php
Executable file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
//对已经上传到七牛的视频发起异步转码操作
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
//要转码的文件所在的空间和文件名。
|
||||
$key = 'qiniu.mp4';
|
||||
|
||||
//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
|
||||
$pipeline = 'sdktest';
|
||||
$force = false;
|
||||
|
||||
//转码完成后通知到你的业务服务器。
|
||||
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
|
||||
$config = new \Qiniu\Config();
|
||||
//$config->useHTTPS=true;
|
||||
|
||||
$pfop = new PersistentFop($auth, $config);
|
||||
|
||||
//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
|
||||
$fops = "avthumb/mp4/s/640x360/vb/1.4m|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_640x360.mp4");
|
||||
|
||||
list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
|
||||
echo "\n====> pfop avthumb result: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
echo "PersistentFop Id: $id\n";
|
||||
}
|
||||
|
||||
//查询转码的进度和状态
|
||||
list($ret, $err) = $pfop->status($id);
|
||||
echo "\n====> pfop avthumb status: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
52
app/Common/extend/qiniu/examples/pfop_watermark.php
Executable file
52
app/Common/extend/qiniu/examples/pfop_watermark.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
//对已经上传到七牛的视频发起异步转码操作
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
//要转码的文件所在的空间和文件名。
|
||||
$key = 'qiniu.mp4';
|
||||
|
||||
//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
|
||||
$pipeline = 'sdktest';
|
||||
|
||||
//转码完成后通知到你的业务服务器。
|
||||
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
|
||||
$force = false;
|
||||
|
||||
$config = new \Qiniu\Config();
|
||||
//$config->useHTTPS=true;
|
||||
$pfop = new PersistentFop($auth, $config);
|
||||
|
||||
//需要添加水印的图片UrlSafeBase64
|
||||
//可以参考http://developer.qiniu.com/code/v6/api/dora-api/av/video-watermark.html
|
||||
$base64URL = Qiniu\base64_urlSafeEncode('http://devtools.qiniu.com/qiniu.png');
|
||||
|
||||
//水印参数
|
||||
$fops = "avthumb/mp4/s/640x360/vb/1.4m/image/" . $base64URL . "|saveas/"
|
||||
. \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_wm.mp4");
|
||||
|
||||
list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
|
||||
echo "\n====> pfop avthumb result: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
echo "PersistentFop Id: $id\n";
|
||||
}
|
||||
|
||||
//查询转码的进度和状态
|
||||
list($ret, $err) = $pfop->status($id);
|
||||
echo "\n====> pfop avthumb status: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
BIN
app/Common/extend/qiniu/examples/php-logo.png
Executable file
BIN
app/Common/extend/qiniu/examples/php-logo.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
29
app/Common/extend/qiniu/examples/prefop.php
Executable file
29
app/Common/extend/qiniu/examples/prefop.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
$accessKey = 'Access_Key';
|
||||
$secretKey = 'Secret_Key';
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
//要持久化处理的文件所在的空间和文件名。
|
||||
$bucket = 'Bucket_Name';
|
||||
|
||||
//持久化处理使用的队列名称。 https://portal.qiniu.com/mps/pipeline
|
||||
$pipeline = 'pipeline_name';
|
||||
|
||||
//持久化处理完成后通知到你的业务服务器。
|
||||
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
|
||||
$pfop = new PersistentFop($auth, $bucket, $pipeline, $notifyUrl);
|
||||
|
||||
$id = "z2.5955c739e3d0041bf80c9baa";
|
||||
//查询持久化处理的进度和状态
|
||||
list($ret, $err) = $pfop->status($id);
|
||||
echo "\n====> pfop avthumb status: \n";
|
||||
if ($err != null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
55
app/Common/extend/qiniu/examples/pulpvideo.php
Executable file
55
app/Common/extend/qiniu/examples/pulpvideo.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Http\Client;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$argusManager = new \Qiniu\Storage\ArgusManager($auth, $config);
|
||||
|
||||
$reqBody = array();
|
||||
$reqBody['uri'] = "xxxx";
|
||||
|
||||
$ops = array();
|
||||
$ops = array(
|
||||
array(
|
||||
'op' => 'pulp',
|
||||
'params' => array(
|
||||
'labels' => array(
|
||||
array(
|
||||
'label' => "1",
|
||||
'select' => 1,
|
||||
'score' => 2,
|
||||
),
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
$params = array();
|
||||
$params = array(
|
||||
'async' => false,
|
||||
'vframe' => array(
|
||||
'mode' => 1,
|
||||
'interval' => 8,
|
||||
)
|
||||
);
|
||||
|
||||
$req = array();
|
||||
$req['data'] = $reqBody;
|
||||
$req['ops'] = $ops;
|
||||
$req['params'] = $params;
|
||||
$body = json_encode($req);
|
||||
|
||||
$vid = "xxxx";
|
||||
list($ret, $err) = $argusManager->pulpVideo($body, $vid);
|
||||
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
11
app/Common/extend/qiniu/examples/qetag.php
Executable file
11
app/Common/extend/qiniu/examples/qetag.php
Executable file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
use Qiniu\Etag;
|
||||
|
||||
$localFile = "/Users/jemy/Documents/qiniu.mp4";
|
||||
list($etag, $err) = Etag::sum($localFile);
|
||||
if ($err == null) {
|
||||
echo "Etag: $etag";
|
||||
} else {
|
||||
var_dump($err);
|
||||
}
|
||||
28
app/Common/extend/qiniu/examples/rs_batch_change_mime.php
Executable file
28
app/Common/extend/qiniu/examples/rs_batch_change_mime.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
//每次最多不能超过1000个
|
||||
$keyMimePairs = array(
|
||||
'qiniu.mp4' => 'video/x-mp4',
|
||||
'qiniu.png' => 'image/x-png',
|
||||
'qiniu.jpg' => 'image/x-jpg'
|
||||
);
|
||||
|
||||
$ops = $bucketManager->buildBatchChangeMime($bucket, $keyMimePairs);
|
||||
list($ret, $err) = $bucketManager->batch($ops);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
34
app/Common/extend/qiniu/examples/rs_batch_change_type.php
Executable file
34
app/Common/extend/qiniu/examples/rs_batch_change_type.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
//每次最多不能超过1000个
|
||||
$keys = array(
|
||||
'qiniu.mp4',
|
||||
'qiniu.png',
|
||||
'qiniu.jpg'
|
||||
);
|
||||
|
||||
$keyTypePairs = array();
|
||||
//type=0表示普通存储,type=1表示低频存储
|
||||
foreach ($keys as $key) {
|
||||
$keyTypePairs[$key] = 1;
|
||||
}
|
||||
|
||||
$ops = $bucketManager->buildBatchChangeType($bucket, $keyTypePairs);
|
||||
list($ret, $err) = $bucketManager->batch($ops);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
36
app/Common/extend/qiniu/examples/rs_batch_copy.php
Executable file
36
app/Common/extend/qiniu/examples/rs_batch_copy.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
//每次最多不能超过1000个
|
||||
$keys = array(
|
||||
'qiniu.mp4',
|
||||
'qiniu.png',
|
||||
'qiniu.jpg'
|
||||
);
|
||||
|
||||
$keyPairs = array();
|
||||
foreach ($keys as $key) {
|
||||
$keyPairs[$key] = $key . "_copy";
|
||||
}
|
||||
|
||||
$srcBucket = $bucket;
|
||||
$destBucket = $bucket;
|
||||
|
||||
$ops = $bucketManager->buildBatchCopy($srcBucket, $keyPairs, $destBucket, true);
|
||||
list($ret, $err) = $bucketManager->batch($ops);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
28
app/Common/extend/qiniu/examples/rs_batch_delete.php
Executable file
28
app/Common/extend/qiniu/examples/rs_batch_delete.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
//每次最多不能超过1000个
|
||||
$keys = array(
|
||||
'qiniu.mp4',
|
||||
'qiniu.png',
|
||||
'qiniu.jpg'
|
||||
);
|
||||
|
||||
$ops = $bucketManager->buildBatchDelete($bucket, $keys);
|
||||
list($ret, $err) = $bucketManager->batch($ops);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
34
app/Common/extend/qiniu/examples/rs_batch_delete_after_days.php
Executable file
34
app/Common/extend/qiniu/examples/rs_batch_delete_after_days.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
//每次最多不能超过1000个
|
||||
$keys = array(
|
||||
'qiniu.mp4',
|
||||
'qiniu.png',
|
||||
'qiniu.jpg'
|
||||
);
|
||||
|
||||
$keyDayPairs = array();
|
||||
//day=0表示永久存储
|
||||
foreach ($keys as $key) {
|
||||
$keyDayPairs[$key] = 0;
|
||||
}
|
||||
|
||||
$ops = $bucketManager->buildBatchDeleteAfterDays($bucket, $keyDayPairs);
|
||||
list($ret, $err) = $bucketManager->batch($ops);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
36
app/Common/extend/qiniu/examples/rs_batch_move.php
Executable file
36
app/Common/extend/qiniu/examples/rs_batch_move.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
//每次最多不能超过1000个
|
||||
$keys = array(
|
||||
'qiniu.mp4',
|
||||
'qiniu.png',
|
||||
'qiniu.jpg'
|
||||
);
|
||||
|
||||
$keyPairs = array();
|
||||
foreach ($keys as $key) {
|
||||
$keyPairs[$key . "_copy"] = $key . "_move";
|
||||
}
|
||||
|
||||
$srcBucket = $bucket;
|
||||
$destBucket = $bucket;
|
||||
|
||||
$ops = $bucketManager->buildBatchMove($srcBucket, $keyPairs, $destBucket, true);
|
||||
list($ret, $err) = $bucketManager->batch($ops);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
28
app/Common/extend/qiniu/examples/rs_batch_stat.php
Executable file
28
app/Common/extend/qiniu/examples/rs_batch_stat.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
//每次最多不能超过1000个
|
||||
$keys = array(
|
||||
'qiniu.mp4',
|
||||
'qiniu.png',
|
||||
'qiniu.jpg'
|
||||
);
|
||||
|
||||
$ops = $bucketManager->buildBatchStat($bucket, $keys);
|
||||
list($ret, $err) = $bucketManager->batch($ops);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
19
app/Common/extend/qiniu/examples/rs_bucket_domains.php
Executable file
19
app/Common/extend/qiniu/examples/rs_bucket_domains.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
list($domains, $err) = $bucketManager->domains($bucket);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($domains);
|
||||
}
|
||||
19
app/Common/extend/qiniu/examples/rs_buckets.php
Executable file
19
app/Common/extend/qiniu/examples/rs_buckets.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
list($buckets, $err) = $bucketManager->buckets(true);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($buckets);
|
||||
}
|
||||
20
app/Common/extend/qiniu/examples/rs_change_mime.php
Executable file
20
app/Common/extend/qiniu/examples/rs_change_mime.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = 'qiniu.mp4';
|
||||
$newMime = 'video/x-mp4';
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
$err = $bucketManager->changeMime($bucket, $key, $newMime);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
20
app/Common/extend/qiniu/examples/rs_change_status.php
Executable file
20
app/Common/extend/qiniu/examples/rs_change_status.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = "qiniu.jpg";
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
$status = 1;//0表示启用;1表示禁用
|
||||
|
||||
$err = $bucketManager->changeStatus($bucket, $key, $status);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
20
app/Common/extend/qiniu/examples/rs_change_type.php
Executable file
20
app/Common/extend/qiniu/examples/rs_change_type.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = "qiniu.mp4";
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
$fileType = 1;//0 表示普通存储,1表示低频存储
|
||||
|
||||
$err = $bucketManager->changeType($bucket, $key, $fileType);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
22
app/Common/extend/qiniu/examples/rs_copy.php
Executable file
22
app/Common/extend/qiniu/examples/rs_copy.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = "qiniu.mp4";
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
$srcBucket = $bucket;
|
||||
$destBucket = $bucket;
|
||||
$srcKey = $key;
|
||||
$destKey = $key . "_copy";
|
||||
$err = $bucketManager->copy($srcBucket, $srcKey, $destBucket, $destKey, true);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
17
app/Common/extend/qiniu/examples/rs_delete.php
Executable file
17
app/Common/extend/qiniu/examples/rs_delete.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = "qiniu.mp4_copy";
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
$err = $bucketManager->delete($bucket, $key);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
20
app/Common/extend/qiniu/examples/rs_delete_after_days.php
Executable file
20
app/Common/extend/qiniu/examples/rs_delete_after_days.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = 'qiniu.mp4';
|
||||
$days = 10;
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
$err = $bucketManager->deleteAfterDays($bucket, $key, $days);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
17
app/Common/extend/qiniu/examples/rs_download_urls.php
Executable file
17
app/Common/extend/qiniu/examples/rs_download_urls.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
|
||||
// 构建Auth对象
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
// 私有空间中的外链 http://<domain>/<file_key>
|
||||
$baseUrl = 'http://if-pri.qiniudn.com/qiniu.png?imageView2/1/h/500';
|
||||
// 对链接进行签名
|
||||
$signedUrl = $auth->privateDownloadUrl($baseUrl);
|
||||
|
||||
echo $signedUrl;
|
||||
34
app/Common/extend/qiniu/examples/rs_fetch.php
Executable file
34
app/Common/extend/qiniu/examples/rs_fetch.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\BucketManager;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$bucketManager = new BucketManager($auth);
|
||||
|
||||
$url = 'http://devtools.qiniu.com/qiniu.png';
|
||||
$key = time() . '.png';
|
||||
|
||||
// 指定抓取的文件保存名称
|
||||
list($ret, $err) = $bucketManager->fetch($url, $bucket, $key);
|
||||
echo "=====> fetch $url to bucket: $bucket key: $key\n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
|
||||
// 不指定key时,以文件内容的hash作为文件名
|
||||
$key = null;
|
||||
list($ret, $err) = $bucketManager->fetch($url, $bucket, $key);
|
||||
echo "=====> fetch $url to bucket: $bucket key: $(etag)\n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
print_r($ret);
|
||||
}
|
||||
22
app/Common/extend/qiniu/examples/rs_move.php
Executable file
22
app/Common/extend/qiniu/examples/rs_move.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = "qiniu.mp4";
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
|
||||
$srcBucket = $bucket;
|
||||
$destBucket = $bucket;
|
||||
$srcKey = $key . "_copy";
|
||||
$destKey = $key . "_move";
|
||||
$err = $bucketManager->move($srcBucket, $srcKey, $destBucket, $destKey, true);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
17
app/Common/extend/qiniu/examples/rs_prefetch.php
Executable file
17
app/Common/extend/qiniu/examples/rs_prefetch.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = "qiniu.mp4";
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
$err = $bucketManager->prefetch($bucket, $key);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
}
|
||||
19
app/Common/extend/qiniu/examples/rs_stat.php
Executable file
19
app/Common/extend/qiniu/examples/rs_stat.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$key = "qiniu.mp4";
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$config = new \Qiniu\Config();
|
||||
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
|
||||
list($fileInfo, $err) = $bucketManager->stat($bucket, $key);
|
||||
if ($err) {
|
||||
print_r($err);
|
||||
} else {
|
||||
print_r($fileInfo);
|
||||
}
|
||||
46
app/Common/extend/qiniu/examples/rsf_list_bucket.php
Executable file
46
app/Common/extend/qiniu/examples/rsf_list_bucket.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\BucketManager;
|
||||
|
||||
// http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$bucketManager = new BucketManager($auth);
|
||||
|
||||
|
||||
// 要列取文件的公共前缀
|
||||
$prefix = '';
|
||||
|
||||
// 上次列举返回的位置标记,作为本次列举的起点信息。
|
||||
$marker = '';
|
||||
|
||||
// 本次列举的条目数
|
||||
$limit = 200;
|
||||
|
||||
$delimiter = '/';
|
||||
|
||||
// 列举文件
|
||||
do {
|
||||
list($ret, $err) = $bucketManager->listFiles($bucket, $prefix, $marker, $limit, $delimiter);
|
||||
if ($err !== null) {
|
||||
echo "\n====> list file err: \n";
|
||||
var_dump($err);
|
||||
} else {
|
||||
$marker = null;
|
||||
if (array_key_exists('marker', $ret)) {
|
||||
$marker = $ret['marker'];
|
||||
}
|
||||
echo "Marker: $marker\n";
|
||||
echo "\nList Items====>\n";
|
||||
//var_dump($ret['items']);
|
||||
print('items count:' . count($ret['items']) . "\n");
|
||||
if (array_key_exists('commonPrefixes', $ret)) {
|
||||
print_r($ret['commonPrefixes']);
|
||||
}
|
||||
}
|
||||
} while (!empty($marker));
|
||||
38
app/Common/extend/qiniu/examples/rsf_list_files.php
Executable file
38
app/Common/extend/qiniu/examples/rsf_list_files.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\BucketManager;
|
||||
|
||||
// http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$bucketManager = new BucketManager($auth);
|
||||
|
||||
|
||||
// 要列取文件的公共前缀
|
||||
$prefix = '';
|
||||
|
||||
// 上次列举返回的位置标记,作为本次列举的起点信息。
|
||||
$marker = '';
|
||||
|
||||
// 本次列举的条目数
|
||||
$limit = 100;
|
||||
|
||||
$delimiter = '/';
|
||||
|
||||
// 列举文件
|
||||
list($ret, $err) = $bucketManager->listFiles($bucket, $prefix, $marker, $limit, $delimiter);
|
||||
if ($err !== null) {
|
||||
echo "\n====> list file err: \n";
|
||||
var_dump($err);
|
||||
} else {
|
||||
if (array_key_exists('marker', $ret)) {
|
||||
echo "Marker:" . $ret["marker"] . "\n";
|
||||
}
|
||||
echo "\nList Iterms====>\n";
|
||||
//var_dump($ret['items']);
|
||||
}
|
||||
28
app/Common/extend/qiniu/examples/saveas.php
Executable file
28
app/Common/extend/qiniu/examples/saveas.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Processing\PersistentFop;
|
||||
|
||||
// 后台来获取AK, SK
|
||||
$accessKey = 'Access_Key';
|
||||
$secretKey = 'Secret_Key';
|
||||
|
||||
//生成EncodedEntryURI的值
|
||||
$entry = '<bucket>:<Key>';//<Key>为生成缩略图的文件名
|
||||
//生成的值
|
||||
$encodedEntryURI = \Qiniu\base64_urlSafeEncode($entry);
|
||||
|
||||
//使用SecretKey对新的下载URL进行HMAC1-SHA1签名
|
||||
$newurl = "78re52.com1.z0.glb.clouddn.com/resource/Ship.jpg?imageView2/2/w/200/h/200|saveas/" . $encodedEntryURI;
|
||||
|
||||
$sign = hash_hmac("sha1", $newurl, $secretKey, true);
|
||||
|
||||
//对签名进行URL安全的Base64编码
|
||||
$encodedSign = \Qiniu\base64_urlSafeEncode($sign);
|
||||
//最终得到的完整下载URL
|
||||
$finalURL = "http://" . $newurl . "/sign/" . $accessKey . ":" . $encodedSign;
|
||||
|
||||
$callbackBody = file_get_contents("$finalURL");
|
||||
|
||||
echo $callbackBody;
|
||||
40
app/Common/extend/qiniu/examples/upload_and_callback.php
Executable file
40
app/Common/extend/qiniu/examples/upload_and_callback.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
|
||||
// use Qiniu\Config;
|
||||
// use Qiniu\Zone;
|
||||
|
||||
// 指定zone上传
|
||||
// $zone = Zone::zoneZ0(); //华东QVM内网上传指定host
|
||||
// $config = new Config($zone);
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器.
|
||||
// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
|
||||
$policy = array(
|
||||
'callbackUrl' => 'http://your.domain.com/upload_verify_callback.php',
|
||||
'callbackBody' => 'filename=$(fname)&filesize=$(fsize)'
|
||||
);
|
||||
$uptoken = $auth->uploadToken($bucket, null, 3600, $policy);
|
||||
|
||||
//上传文件的本地路径
|
||||
$filePath = './php-logo.png';
|
||||
|
||||
//指定 config
|
||||
// $uploadMgr = new UploadManager($config);
|
||||
$uploadMgr = new UploadManager();
|
||||
|
||||
list($ret, $err) = $uploadMgr->putFile($uptoken, null, $filePath);
|
||||
echo "\n====> putFile result: \n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
38
app/Common/extend/qiniu/examples/upload_and_pfop.php
Executable file
38
app/Common/extend/qiniu/examples/upload_and_pfop.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
|
||||
// 在七牛保存的文件名
|
||||
$key = 'php-logo.png';
|
||||
$uploadMgr = new UploadManager();
|
||||
|
||||
$pfop = "imageMogr2/rotate/90|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":php-logo-rotate.png");
|
||||
|
||||
//转码完成后通知到你的业务服务器。(公网可以访问,并相应200 OK)
|
||||
$notifyUrl = 'http://notify.fake.com';
|
||||
|
||||
//独立的转码队列:https://portal.qiniu.com/mps/pipeline
|
||||
$pipeline = 'sdktest';
|
||||
|
||||
$policy = array(
|
||||
'persistentOps' => $pfop,
|
||||
'persistentNotifyUrl' => $notifyUrl,
|
||||
'persistentPipeline' => $pipeline
|
||||
);
|
||||
$token = $auth->uploadToken($bucket, null, 3600, $policy);
|
||||
|
||||
list($ret, $err) = $uploadMgr->putFile($token, null, $key);
|
||||
echo "\n====> putFile result: \n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
18
app/Common/extend/qiniu/examples/upload_mgr_init.php
Executable file
18
app/Common/extend/qiniu/examples/upload_mgr_init.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
|
||||
$accessKey = 'Access_Key';
|
||||
$secretKey = 'Secret_Key';
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
// 空间名 http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket
|
||||
$bucket = 'Bucket_Name';
|
||||
|
||||
// 生成上传Token
|
||||
$token = $auth->uploadToken($bucket);
|
||||
|
||||
// 构建 UploadManager 对象
|
||||
$uploadMgr = new UploadManager();
|
||||
85
app/Common/extend/qiniu/examples/upload_multi_demos.php
Executable file
85
app/Common/extend/qiniu/examples/upload_multi_demos.php
Executable file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$pipeline = 'sdktest';
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$token = $auth->uploadToken($bucket);
|
||||
$uploadMgr = new UploadManager();
|
||||
|
||||
//----------------------------------------upload demo1 ----------------------------------------
|
||||
// 上传字符串到七牛
|
||||
list($ret, $err) = $uploadMgr->put($token, null, 'content string');
|
||||
echo "\n====> put result: \n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------upload demo2 ----------------------------------------
|
||||
// 上传文件到七牛
|
||||
$filePath = './php-logo.png';
|
||||
$key = 'php-logo.png';
|
||||
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
|
||||
echo "\n====> putFile result: \n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------upload demo3 ----------------------------------------
|
||||
// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器.
|
||||
// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
|
||||
$policy = array(
|
||||
'callbackUrl' => 'http://172.30.251.210/upload_verify_callback.php',
|
||||
'callbackBody' => 'filename=$(fname)&filesize=$(fsize)'
|
||||
// 'callbackBodyType' => 'application/json',
|
||||
// 'callbackBody' => '{"filename":$(fname), "filesize": $(fsize)}' //设置application/json格式回调
|
||||
);
|
||||
$token = $auth->uploadToken($bucket, null, 3600, $policy);
|
||||
|
||||
|
||||
list($ret, $err) = $uploadMgr->putFile($token, null, $key);
|
||||
echo "\n====> putFile result: \n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------upload demo4 ----------------------------------------
|
||||
//上传视频,上传完成后进行m3u8的转码, 并给视频打水印
|
||||
$wmImg = Qiniu\base64_urlSafeEncode('http://devtools.qiniudn.com/qiniu.png');
|
||||
$pfop = "avthumb/m3u8/wmImage/$wmImg";
|
||||
|
||||
//转码完成后回调到业务服务器。(公网可以访问,并相应200 OK)
|
||||
$notifyUrl = 'http://notify.fake.com';
|
||||
|
||||
//独立的转码队列:https://portal.qiniu.com/mps/pipeline
|
||||
|
||||
|
||||
$policy = array(
|
||||
'persistentOps' => $pfop,
|
||||
'persistentNotifyUrl' => $notifyUrl,
|
||||
'persistentPipeline' => $pipeline
|
||||
);
|
||||
$token = $auth->uploadToken($bucket, null, 3600, $policy);
|
||||
print($token);
|
||||
list($ret, $err) = $uploadMgr->putFile($token, null, $key);
|
||||
echo "\n====> putFile result: \n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
37
app/Common/extend/qiniu/examples/upload_simple_file.php
Executable file
37
app/Common/extend/qiniu/examples/upload_simple_file.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
// 引入鉴权类
|
||||
use Qiniu\Auth;
|
||||
|
||||
// 引入上传类
|
||||
use Qiniu\Storage\UploadManager;
|
||||
|
||||
// 需要填写你的 Access Key 和 Secret Key
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
// 构建鉴权对象
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
// 生成上传 Token
|
||||
$token = $auth->uploadToken($bucket);
|
||||
|
||||
// 要上传文件的本地路径
|
||||
$filePath = './php-logo.png';
|
||||
|
||||
// 上传到七牛后保存的文件名
|
||||
$key = 'my-php-logo.png';
|
||||
|
||||
// 初始化 UploadManager 对象并进行文件的上传。
|
||||
$uploadMgr = new UploadManager();
|
||||
|
||||
// 调用 UploadManager 的 putFile 方法进行文件的上传。
|
||||
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
|
||||
echo "\n====> putFile result: \n";
|
||||
if ($err !== null) {
|
||||
var_dump($err);
|
||||
} else {
|
||||
var_dump($ret);
|
||||
}
|
||||
68
app/Common/extend/qiniu/examples/upload_tokens.php
Executable file
68
app/Common/extend/qiniu/examples/upload_tokens.php
Executable file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use \Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
// 初始化Auth状态
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
// 简单上传凭证
|
||||
$expires = 3600;
|
||||
|
||||
$policy = null;
|
||||
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
|
||||
print($upToken . "\n");
|
||||
|
||||
// 自定义凭证有效期(示例2小时)
|
||||
$expires = 7200;
|
||||
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
|
||||
print($upToken . "\n");
|
||||
|
||||
// 覆盖上传凭证
|
||||
$expires = 3600;
|
||||
$keyToOverwrite = 'qiniu.mp4';
|
||||
$upToken = $auth->uploadToken($bucket, $keyToOverwrite, $expires, $policy, true);
|
||||
print($upToken . "\n");
|
||||
|
||||
//自定义上传回复(非callback模式)凭证
|
||||
$returnBody = '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}';
|
||||
$policy = array(
|
||||
'returnBody' => $returnBody
|
||||
);
|
||||
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
|
||||
print($upToken . "\n");
|
||||
|
||||
//带回调业务服务器的凭证(application/json)
|
||||
$policy = array(
|
||||
'callbackUrl' => 'http://api.example.com/qiniu/upload/callback',
|
||||
'callbackBody' => '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}',
|
||||
'callbackBodyType' => 'application/json'
|
||||
);
|
||||
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
|
||||
print($upToken . "\n");
|
||||
|
||||
|
||||
//带回调业务服务器的凭证(application/x-www-form-urlencoded)
|
||||
$policy = array(
|
||||
'callbackUrl' => 'http://api.example.com/qiniu/upload/callback',
|
||||
'callbackBody' => 'key=$(key)&hash=$(etag)&bucket=$(bucket)&fsize=$(fsize)&name=$(x:name)'
|
||||
);
|
||||
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
|
||||
print($upToken . "\n");
|
||||
|
||||
//带数据处理的凭证
|
||||
$saveMp4Entry = \Qiniu\base64_urlSafeEncode($bucket . ":avthumb_test_target.mp4");
|
||||
$saveJpgEntry = \Qiniu\base64_urlSafeEncode($bucket . ":vframe_test_target.jpg");
|
||||
$avthumbMp4Fop = "avthumb/mp4|saveas/" . $saveMp4Entry;
|
||||
$vframeJpgFop = "vframe/jpg/offset/1|saveas/" . $saveJpgEntry;
|
||||
$policy = array(
|
||||
'persistentOps' => $avthumbMp4Fop . ";" . $vframeJpgFop,
|
||||
'persistentPipeline' => "video-pipe",
|
||||
'persistentNotifyUrl' => "http://api.example.com/qiniu/pfop/notify",
|
||||
);
|
||||
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
|
||||
print($upToken . "\n");
|
||||
32
app/Common/extend/qiniu/examples/upload_verify_callback.php
Executable file
32
app/Common/extend/qiniu/examples/upload_verify_callback.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
//获取回调的body信息
|
||||
$callbackBody = file_get_contents('php://input');
|
||||
|
||||
//回调的contentType
|
||||
$contentType = 'application/x-www-form-urlencoded';
|
||||
|
||||
//回调的签名信息,可以验证该回调是否来自七牛
|
||||
$authorization = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
|
||||
//七牛回调的url,具体可以参考:http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
|
||||
$url = 'http://172.30.251.210/upload_verify_callback.php';
|
||||
|
||||
$isQiniuCallback = $auth->verifyCallback($contentType, $authorization, $url, $callbackBody);
|
||||
|
||||
if ($isQiniuCallback) {
|
||||
$resp = array('ret' => 'success');
|
||||
} else {
|
||||
$resp = array('ret' => 'failed');
|
||||
}
|
||||
|
||||
echo json_encode($resp);
|
||||
Reference in New Issue
Block a user