forked from upyun/php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsync-Process.php
133 lines (122 loc) · 3.34 KB
/
Async-Process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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();