Skip to content

Commit 7c14ad6

Browse files
forthe2008sabakugaara
authored andcommitted
add examples for process
1 parent 465865d commit 7c14ad6

File tree

8 files changed

+493
-0
lines changed

8 files changed

+493
-0
lines changed

examples/Ai.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* 又拍云 PHP-SDK 人工智能使用实例
4+
* 测试与运行例子的时,用户需要根据自己的需求填写对应的配置(User-Profle.php),参数
5+
*/
6+
7+
require __DIR__ . '/User-Profile.php';
8+
9+
use Upyun\Config;
10+
use Upyun\Api\Pretreat;
11+
use Upyun\Api\SyncVideo;
12+
13+
$config = new Config(SERVICE, USER_NAME, PWD);
14+
$config->processNotifyUrl = NOTIFY_URL;
15+
16+
$client = new Pretreat($config);
17+
$liveClient = new SyncVideo($config);
18+
19+
/**
20+
* 异步内容识别通用接口
21+
*/
22+
function asyncAudit($tasks, $appName)
23+
{
24+
global $client;
25+
$options = array('app_name' => $appName);
26+
$resp = $client->process($tasks, $options);
27+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
28+
}
29+
30+
/**
31+
* 内容识别(有存储)-图片
32+
* tasks参数与说明见:http://docs.upyun.com/ai/audit/
33+
*/
34+
function imageAsyncAudit()
35+
{
36+
// 使用时,按文档和个人需求填写tasks
37+
$tasks = array(
38+
array(
39+
'source' => IMAGE_SAVE_KEY
40+
));
41+
asyncAudit($tasks, 'imgaudit');
42+
}
43+
44+
/**
45+
* 内容识别(有存储)-视频点播
46+
* tasks参数与说明见:http://docs.upyun.com/ai/audit/
47+
*/
48+
function videoAsyncAudit()
49+
{
50+
// 使用时,按文档和个人需求填写tasks
51+
$tasks = array(
52+
array(
53+
'source' => VIDEO_SAVE_KEY
54+
));
55+
asyncAudit($tasks, 'videoaudit');
56+
}
57+
58+
/**
59+
* 内容识别(有存储)-视频直播
60+
* params参数与说明见:http://docs.upyun.com/ai/audit/
61+
*/
62+
function liveAudit()
63+
{
64+
global $liveClient;
65+
// 使用时,按文档和个人需求填写params
66+
$params = array(
67+
'service' => SERVICE,
68+
'source' => RTMP_SOURCE,
69+
'save_as' => '/{year}/{mon}/{day}/{hour}_{min}_{sec}.jpg',
70+
'notify_url' => NOTIFY_URL,
71+
);
72+
$resp = $liveClient->process($params, '/liveaudit/create');
73+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
74+
}
75+
76+
/**
77+
* 内容识别(有存储)-视频直播取消
78+
* params参数与说明见:http://docs.upyun.com/ai/audit/
79+
*/
80+
function liveAuditCancel($taskID)
81+
{
82+
global $liveClient;
83+
// 使用时,按文档和个人需求填写params
84+
$params = array(
85+
'service' => SERVICE,
86+
'task_id' => $taskID,
87+
);
88+
$resp = $liveClient->process($params, '/liveaudit/cancel');
89+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
90+
}
91+
92+
93+
/**
94+
* 接口调用
95+
*/
96+
imageAsyncAudit();
97+
videoAsyncAudit();
98+
liveAudit();
99+
liveAuditCancel('064ca517cb85e708796f33e378b9b4cd');

examples/Async-Process.php

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
/**
3+
* 又拍云 PHP-SDK 异步云处理使用实例
4+
* 测试与运行例子的时,用户需要根据自己的需求填写对应的配置(User-Profle.php),参数
5+
*/
6+
7+
require __DIR__ . '/User-Profile.php';
8+
9+
use Upyun\Config;
10+
use Upyun\Upyun;
11+
12+
$config = new Config(SERVICE, USER_NAME, PWD);
13+
$config->processNotifyUrl = NOTIFY_URL;
14+
$client = new Upyun($config);
15+
16+
/**
17+
* 异步音视频处理
18+
* tasks参数与说明见:http://docs.upyun.com/cloud/av/
19+
*/
20+
function videoAsyncProcess()
21+
{
22+
global $client;
23+
// 使用时,按文档和个人需求填写tasks
24+
$tasks = array(
25+
array(
26+
'type' => 'video',
27+
'avopts' => '/s/128x96',
28+
'save_as' => VIDEO_SAVE_AS,
29+
));
30+
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_MEDIA, VIDEO_SAVE_KEY);
31+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
32+
}
33+
34+
/**
35+
* 压缩
36+
* tasks参数与说明见:http://docs.upyun.com/cloud/unzip/
37+
*/
38+
function compress()
39+
{
40+
global $client;
41+
// 使用时,按文档和个人需求填写tasks
42+
$tasks = array(
43+
array(
44+
'sources' => array(IMAGE_SAVE_KEY, VIDEO_SAVE_KEY),
45+
'save_as' => COMPRESS_SAVE,
46+
));
47+
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_ZIP);
48+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
49+
}
50+
51+
/**
52+
* 解压缩
53+
* tasks参数与说明见:http://docs.upyun.com/cloud/unzip/
54+
*/
55+
function depress()
56+
{
57+
global $client;
58+
// 使用时,按文档和个人需求填写tasks
59+
$tasks = array(
60+
array(
61+
'sources' => COMPRESS_SAVE,
62+
'save_as' => REMOTE_DIR,
63+
));
64+
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_UNZIP);
65+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
66+
}
67+
68+
/**
69+
* 文件拉取
70+
* tasks参数与说明见:http://docs.upyun.com/cloud/spider/
71+
*/
72+
function spiderman()
73+
{
74+
global $client;
75+
// 使用时,按文档和个人需求填写tasks
76+
$tasks = array(
77+
array(
78+
'url' => URL,
79+
'save_as' => SAVE_AS,
80+
));
81+
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_SYNC_FILE);
82+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
83+
}
84+
85+
/**
86+
* 文档转换
87+
* tasks参数与说明见:http://docs.upyun.com/cloud/uconvert/
88+
*/
89+
function fileAsyncConvert()
90+
{
91+
global $client;
92+
// 使用时,按文档和个人需求填写tasks
93+
$tasks = array(
94+
array(
95+
'source' => DOC_SAVE_KEY,
96+
'save_as' => DOC_SAVE_AS,
97+
));
98+
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_CONVERT);
99+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
100+
}
101+
102+
/**
103+
* 异步图片拼接
104+
* tasks参数与说明见:http://docs.upyun.com/cloud/async_image/
105+
*/
106+
function imageAsyncJoint()
107+
{
108+
global $client;
109+
// 使用时,按文档和个人需求填写tasks
110+
$imageMatrix = array(
111+
array(
112+
'/12/6.jpg',
113+
'/12/6.jpg'
114+
));
115+
$tasks = array(
116+
array(
117+
'image_matrix' => $imageMatrix,
118+
'save_as' => IMAGE_SAVE_AS,
119+
));
120+
$resp = $client->process($tasks, Upyun::$PROCESS_TYPE_STITCH);
121+
echo json_encode($resp, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
122+
}
123+
124+
125+
/**
126+
* 接口调用
127+
*/
128+
videoAsyncProcess();
129+
compress();
130+
depress();
131+
spiderman();
132+
fileAsyncConvert();
133+
imageAsyncJoint();

examples/Pre-Process.php

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
/**
3+
* 又拍云 PHP-SDK 上传预处理使用实例
4+
* 测试与运行例子的时,用户需要根据自己的需求填写对应的配置(User-Profle.php),参数
5+
*/
6+
7+
require __DIR__ . '/User-Profile.php';
8+
9+
use Upyun\Config;
10+
use Upyun\Upyun;
11+
12+
$config = new Config(SERVICE, USER_NAME, PWD);
13+
$client = new Upyun($config);
14+
15+
16+
/**
17+
* 通用form上传预处理
18+
*/
19+
function formAsyncPreProcess($file, $key, $apps=array())
20+
{
21+
global $client;
22+
$fd = fopen($file, 'r');
23+
if ($fd != NULL)
24+
{
25+
// 使用时,按文档和个人需求填写params
26+
$params = array(
27+
'notify-url' => NOTIFY_URL,
28+
'apps' => $apps
29+
);
30+
echo $client->write($key, $fd, $params, true);
31+
}
32+
else
33+
{
34+
echo 'cannt open file:' . $file;
35+
}
36+
}
37+
38+
/**
39+
* 图片异步上传预处理
40+
* http://docs.upyun.com/cloud/image/
41+
*/
42+
function formImageAsyncProcess()
43+
{
44+
// 使用时,按文档和个人需求填写apps
45+
$apps = array(array(
46+
'name' => 'thumb',
47+
'x-gmkerl-thumb' => '/format/png',
48+
'save_as' => IMAGE_SAVE_AS,
49+
));
50+
formAsyncPreProcess(IMAGE_FILE, IMAGE_SAVE_KEY, $apps);
51+
}
52+
53+
/**
54+
* 图片同步上传预处理
55+
* http://docs.upyun.com/cloud/image/
56+
*/
57+
function formImageSyncProcess()
58+
{
59+
global $client;
60+
$fd = fopen(IMAGE_FILE, 'r');
61+
if ($fd != NULL)
62+
{
63+
// 使用时,按文档和个人需求填写params
64+
$params = array(
65+
'notify-url' => NOTIFY_URL,
66+
'x-gmkerl-thumb' => '/format/png',
67+
);
68+
echo $client->write(IMAGE_SAVE_KEY, $fd, $params, true);
69+
}
70+
else
71+
{
72+
echo 'cannt open file:' . $file;
73+
}
74+
}
75+
76+
/**
77+
* 异步音视频上传预处理
78+
* http://docs.upyun.com/cloud/av/
79+
*/
80+
function formVideoAsyncProcess()
81+
{
82+
// 使用时,按文档和个人需求填写apps
83+
$apps = array(array(
84+
'name' => 'naga',
85+
'type' => 'video',
86+
'avopts' => '/s/128x96',
87+
'save_as' => VIDEO_SAVE_AS
88+
));
89+
formAsyncPreProcess(VIDEO_FILE, VIDEO_SAVE_KEY, $apps);
90+
}
91+
92+
/**
93+
* 文档转换上传预处理
94+
* http://docs.upyun.com/cloud/uconvert/
95+
*/
96+
function formDocAsyncConvert()
97+
{
98+
// 使用时,按文档和个人需求填写apps
99+
$apps = array(array(
100+
'name' => 'uconvert',
101+
'save_as' => DOC_SAVE_AS
102+
));
103+
formAsyncPreProcess(DOC_FILE, DOC_SAVE_KEY, $apps);
104+
}
105+
106+
/**
107+
* 图片内容识别上传预处理
108+
* http://docs.upyun.com/ai/audit/
109+
*/
110+
function formImageAsyncAudit()
111+
{
112+
// 使用时,按文档和个人需求填写apps
113+
$apps = array(array(
114+
'name' => 'imgaudit',
115+
));
116+
formAsyncPreProcess(IMAGE_FILE, IMAGE_SAVE_KEY, $apps);
117+
}
118+
119+
/**
120+
* 视频内容识别上传预处理
121+
* http://docs.upyun.com/ai/audit/
122+
*/
123+
function formVideoAsyncAudit()
124+
{
125+
// 使用时,按文档和个人需求填写apps
126+
$apps = array(array(
127+
'name' => 'videoaudit',
128+
));
129+
formAsyncPreProcess(VIDEO_FILE, VIDEO_SAVE_KEY, $apps);
130+
}
131+
132+
/**
133+
* 接口调用
134+
*/
135+
formImageAsyncProcess();
136+
formImageSyncProcess();
137+
formVideoAsyncProcess();
138+
formDocAsyncConvert();
139+
formImageAsyncAudit();
140+
formVideoAsyncAudit();

0 commit comments

Comments
 (0)