Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add examples for process #46

Merged
merged 1 commit into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions examples/Ai.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* 又拍云 PHP-SDK 人工智能使用实例
* 测试与运行例子的时,用户需要根据自己的需求填写对应的配置(User-Profle.php),参数
*/

require __DIR__ . '/User-Profile.php';

use Upyun\Config;
use Upyun\Api\Pretreat;
use Upyun\Api\SyncVideo;

$config = new Config(SERVICE, USER_NAME, PWD);
$config->processNotifyUrl = NOTIFY_URL;

$client = new Pretreat($config);
$liveClient = new SyncVideo($config);

/**
* 异步内容识别通用接口
*/
function asyncAudit($tasks, $appName)
{
global $client;
$options = array('app_name' => $appName);
$resp = $client->process($tasks, $options);
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

/**
* 内容识别(有存储)-图片
* tasks参数与说明见:http://docs.upyun.com/ai/audit/
*/
function imageAsyncAudit()
{
// 使用时,按文档和个人需求填写tasks
$tasks = array(
array(
'source' => IMAGE_SAVE_KEY
));
asyncAudit($tasks, 'imgaudit');
}

/**
* 内容识别(有存储)-视频点播
* tasks参数与说明见:http://docs.upyun.com/ai/audit/
*/
function videoAsyncAudit()
{
// 使用时,按文档和个人需求填写tasks
$tasks = array(
array(
'source' => VIDEO_SAVE_KEY
));
asyncAudit($tasks, 'videoaudit');
}

/**
* 内容识别(有存储)-视频直播
* params参数与说明见:http://docs.upyun.com/ai/audit/
*/
function liveAudit()
{
global $liveClient;
// 使用时,按文档和个人需求填写params
$params = array(
'service' => SERVICE,
'source' => RTMP_SOURCE,
'save_as' => '/{year}/{mon}/{day}/{hour}_{min}_{sec}.jpg',
'notify_url' => NOTIFY_URL,
);
$resp = $liveClient->process($params, '/liveaudit/create');
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

/**
* 内容识别(有存储)-视频直播取消
* params参数与说明见:http://docs.upyun.com/ai/audit/
*/
function liveAuditCancel($taskID)
{
global $liveClient;
// 使用时,按文档和个人需求填写params
$params = array(
'service' => SERVICE,
'task_id' => $taskID,
);
$resp = $liveClient->process($params, '/liveaudit/cancel');
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}


/**
* 接口调用
*/
imageAsyncAudit();
videoAsyncAudit();
liveAudit();
liveAuditCancel('064ca517cb85e708796f33e378b9b4cd');
133 changes: 133 additions & 0 deletions examples/Async-Process.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* 又拍云 PHP-SDK 异步云处理使用实例
* 测试与运行例子的时,用户需要根据自己的需求填写对应的配置(User-Profle.php),参数
*/

require __DIR__ . '/User-Profile.php';

use Upyun\Config;
use Upyun\Upyun;

$config = new Config(SERVICE, USER_NAME, PWD);
$config->processNotifyUrl = NOTIFY_URL;
$client = new Upyun($config);

/**
* 异步音视频处理
* tasks参数与说明见:http://docs.upyun.com/cloud/av/
*/
function videoAsyncProcess()
{
global $client;
// 使用时,按文档和个人需求填写tasks
$tasks = array(
array(
'type' => 'video',
'avopts' => '/s/128x96',
'save_as' => VIDEO_SAVE_AS,
));
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_MEDIA, VIDEO_SAVE_KEY);
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

/**
* 压缩
* tasks参数与说明见:http://docs.upyun.com/cloud/unzip/
*/
function compress()
{
global $client;
// 使用时,按文档和个人需求填写tasks
$tasks = array(
array(
'sources' => array(IMAGE_SAVE_KEY, VIDEO_SAVE_KEY),
'save_as' => COMPRESS_SAVE,
));
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_ZIP);
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

/**
* 解压缩
* tasks参数与说明见:http://docs.upyun.com/cloud/unzip/
*/
function depress()
{
global $client;
// 使用时,按文档和个人需求填写tasks
$tasks = array(
array(
'sources' => COMPRESS_SAVE,
'save_as' => REMOTE_DIR,
));
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_UNZIP);
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

/**
* 文件拉取
* tasks参数与说明见:http://docs.upyun.com/cloud/spider/
*/
function spiderman()
{
global $client;
// 使用时,按文档和个人需求填写tasks
$tasks = array(
array(
'url' => URL,
'save_as' => SAVE_AS,
));
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_SYNC_FILE);
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

/**
* 文档转换
* tasks参数与说明见:http://docs.upyun.com/cloud/uconvert/
*/
function fileAsyncConvert()
{
global $client;
// 使用时,按文档和个人需求填写tasks
$tasks = array(
array(
'source' => DOC_SAVE_KEY,
'save_as' => DOC_SAVE_AS,
));
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_CONVERT);
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

/**
* 异步图片拼接
* tasks参数与说明见:http://docs.upyun.com/cloud/async_image/
*/
function imageAsyncJoint()
{
global $client;
// 使用时,按文档和个人需求填写tasks
$imageMatrix = array(
array(
'/12/6.jpg',
'/12/6.jpg'
));
$tasks = array(
array(
'image_matrix' => $imageMatrix,
'save_as' => IMAGE_SAVE_AS,
));
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_STITCH);
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}


/**
* 接口调用
*/
videoAsyncProcess();
compress();
depress();
spiderman();
fileAsyncConvert();
imageAsyncJoint();
140 changes: 140 additions & 0 deletions examples/Pre-Process.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
/**
* 又拍云 PHP-SDK 上传预处理使用实例
* 测试与运行例子的时,用户需要根据自己的需求填写对应的配置(User-Profle.php),参数
*/

require __DIR__ . '/User-Profile.php';

use Upyun\Config;
use Upyun\Upyun;

$config = new Config(SERVICE, USER_NAME, PWD);
$client = new Upyun($config);


/**
* 通用form上传预处理
*/
function formAsyncPreProcess($file, $key, $apps=array())
{
global $client;
$fd = fopen($file, 'r');
if ($fd != NULL)
{
// 使用时,按文档和个人需求填写params
$params = array(
'notify-url' => NOTIFY_URL,
'apps' => $apps
);
echo $client->write($key, $fd, $params, true);
}
else
{
echo 'cannt open file:' . $file;
}
}

/**
* 图片异步上传预处理
* http://docs.upyun.com/cloud/image/
*/
function formImageAsyncProcess()
{
// 使用时,按文档和个人需求填写apps
$apps = array(array(
'name' => 'thumb',
'x-gmkerl-thumb' => '/format/png',
'save_as' => IMAGE_SAVE_AS,
));
formAsyncPreProcess(IMAGE_FILE, IMAGE_SAVE_KEY, $apps);
}

/**
* 图片同步上传预处理
* http://docs.upyun.com/cloud/image/
*/
function formImageSyncProcess()
{
global $client;
$fd = fopen(IMAGE_FILE, 'r');
if ($fd != NULL)
{
// 使用时,按文档和个人需求填写params
$params = array(
'notify-url' => NOTIFY_URL,
'x-gmkerl-thumb' => '/format/png',
);
echo $client->write(IMAGE_SAVE_KEY, $fd, $params, true);
}
else
{
echo 'cannt open file:' . $file;
}
}

/**
* 异步音视频上传预处理
* http://docs.upyun.com/cloud/av/
*/
function formVideoAsyncProcess()
{
// 使用时,按文档和个人需求填写apps
$apps = array(array(
'name' => 'naga',
'type' => 'video',
'avopts' => '/s/128x96',
'save_as' => VIDEO_SAVE_AS
));
formAsyncPreProcess(VIDEO_FILE, VIDEO_SAVE_KEY, $apps);
}

/**
* 文档转换上传预处理
* http://docs.upyun.com/cloud/uconvert/
*/
function formDocAsyncConvert()
{
// 使用时,按文档和个人需求填写apps
$apps = array(array(
'name' => 'uconvert',
'save_as' => DOC_SAVE_AS
));
formAsyncPreProcess(DOC_FILE, DOC_SAVE_KEY, $apps);
}

/**
* 图片内容识别上传预处理
* http://docs.upyun.com/ai/audit/
*/
function formImageAsyncAudit()
{
// 使用时,按文档和个人需求填写apps
$apps = array(array(
'name' => 'imgaudit',
));
formAsyncPreProcess(IMAGE_FILE, IMAGE_SAVE_KEY, $apps);
}

/**
* 视频内容识别上传预处理
* http://docs.upyun.com/ai/audit/
*/
function formVideoAsyncAudit()
{
// 使用时,按文档和个人需求填写apps
$apps = array(array(
'name' => 'videoaudit',
));
formAsyncPreProcess(VIDEO_FILE, VIDEO_SAVE_KEY, $apps);
}

/**
* 接口调用
*/
formImageAsyncProcess();
formImageSyncProcess();
formVideoAsyncProcess();
formDocAsyncConvert();
formImageAsyncAudit();
formVideoAsyncAudit();
Loading