1
|
|
|
<?php |
2
|
|
|
namespace Upyun; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class Config |
6
|
|
|
* |
7
|
|
|
* @package Upyun |
8
|
|
|
*/ |
9
|
|
|
class Config |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string 服务名称,将会被弃用 |
13
|
|
|
*/ |
14
|
|
|
public $bucketName; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string 服务名称 |
18
|
|
|
*/ |
19
|
|
|
public $serviceName; |
20
|
|
|
/** |
21
|
|
|
* @var string 操作员名 |
22
|
|
|
*/ |
23
|
|
|
public $operatorName; |
24
|
|
|
/** |
25
|
|
|
* @var string 操作员密码 md5 hash 值 |
26
|
|
|
*/ |
27
|
|
|
public $operatorPassword; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool 是否使用 https |
31
|
|
|
*/ |
32
|
|
|
public $useSsl; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string 上传使用的接口类型,可以设置为 `REST`:使用 rest api 上传,`AUTO` 根据文件大小自动判断,`BLOCK` 使用断点续传 |
36
|
|
|
* 当上传小文件时,不推荐使用断点续传;上传时如果设置了异步预处理`withAsyncProcess=true`,将会使用表单 api 上传 |
37
|
|
|
*/ |
38
|
|
|
public $uploadType = 'AUTO'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int 上传的接口类型设置为 `AUTO` 时,文件大小的边界值:小于该值时,使用 rest api,否则使用断点续传。 默认 30M |
42
|
|
|
*/ |
43
|
|
|
public $sizeBoundary = 31457280; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var int request timeout seconds |
47
|
|
|
*/ |
48
|
|
|
public $timeout = 60; |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string 异步云处理的回调通知地址 |
53
|
|
|
*/ |
54
|
|
|
public $processNotifyUrl; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var boolean curl debug |
58
|
|
|
*/ |
59
|
|
|
public $debug = false; |
60
|
|
|
|
61
|
|
|
private $version = '3.0.0'; |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string 表单 api 的秘钥 |
67
|
|
|
*/ |
68
|
|
|
private $formApiKey; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var string rest api 和 form api 的接口地址 |
72
|
|
|
*/ |
73
|
|
|
public static $restApiEndPoint; |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* rest api 和 form api 接口请求地址,详见:http://docs.upyun.com/api/rest_api/ |
78
|
|
|
*/ |
79
|
|
|
const ED_AUTO = 'v0.api.upyun.com'; |
80
|
|
|
const ED_TELECOM = 'v1.api.upyun.com'; |
81
|
|
|
const ED_CNC = 'v2.api.upyun.com'; |
82
|
|
|
const ED_CTT = 'v3.api.upyun.com'; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* 异步云处理接口地址 |
86
|
|
|
*/ |
87
|
|
|
const ED_VIDEO = 'p0.api.upyun.com'; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* 刷新接口地址 |
91
|
|
|
*/ |
92
|
|
|
const ED_PURGE = 'http://purge.upyun.com/purge/'; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* 同步视频处理接口地址 |
96
|
|
|
*/ |
97
|
|
|
const ED_SYNC_VIDEO = 'p1.api.upyun.com'; |
98
|
|
|
|
99
|
2 |
|
public function __construct($serviceName, $operatorName, $operatorPassword) |
100
|
|
|
{ |
101
|
2 |
|
$this->serviceName = $serviceName; |
102
|
2 |
|
$this->bucketName = $serviceName; |
103
|
2 |
|
$this->operatorName = $operatorName; |
104
|
2 |
|
$this->setOperatorPassword($operatorPassword); |
105
|
2 |
|
$this->useSsl = false; |
106
|
2 |
|
self::$restApiEndPoint = self::ED_AUTO; |
107
|
2 |
|
} |
108
|
|
|
|
109
|
2 |
|
public function setOperatorPassword($operatorPassword) |
110
|
|
|
{ |
111
|
2 |
|
$this->operatorPassword = md5($operatorPassword); |
112
|
2 |
|
} |
113
|
|
|
|
114
|
|
|
public function getFormApiKey() |
115
|
|
|
{ |
116
|
|
|
if (! $this->formApiKey) { |
117
|
|
|
throw new \Exception('form api key is empty.'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $this->formApiKey; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setFormApiKey($key) |
124
|
|
|
{ |
125
|
|
|
$this->formApiKey = $key; |
126
|
|
|
} |
127
|
|
|
|
128
|
19 |
|
public function getVersion() |
129
|
|
|
{ |
130
|
19 |
|
return $this->version; |
131
|
|
|
} |
132
|
|
|
|
133
|
3 |
|
public function getPretreatEndPoint() |
134
|
|
|
{ |
135
|
3 |
|
return $this->getProtocol() . self::ED_VIDEO; |
136
|
|
|
} |
137
|
|
|
|
138
|
2 |
|
public function getSyncVideoEndPoint() |
139
|
|
|
{ |
140
|
2 |
|
return $this->getProtocol() . self::ED_SYNC_VIDEO; |
141
|
|
|
} |
142
|
|
|
|
143
|
19 |
|
public function getProtocol() |
144
|
|
|
{ |
145
|
19 |
|
return $this->useSsl ? 'https://' : 'http://'; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|