1
|
|
|
<?php |
2
|
|
|
namespace Qiniu; |
3
|
|
|
|
4
|
|
|
final class Config |
5
|
|
|
{ |
6
|
|
|
const SDK_VER = '7.6.0'; |
7
|
|
|
|
8
|
|
|
const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改 |
9
|
|
|
|
10
|
|
|
const RSF_HOST = 'rsf.qiniu.com'; |
11
|
|
|
const API_HOST = 'api.qiniu.com'; |
12
|
|
|
const RS_HOST = 'rs.qiniu.com'; //RS Host |
13
|
|
|
const UC_HOST = 'uc.qbox.me'; //UC Host |
14
|
|
|
const RTCAPI_HOST = 'http://rtc.qiniuapi.com'; |
15
|
|
|
const ARGUS_HOST = 'ai.qiniuapi.com'; |
16
|
|
|
const CASTER_HOST = 'pili-caster.qiniuapi.com'; |
17
|
|
|
const SMS_HOST="https://sms.qiniuapi.com"; |
18
|
|
|
const RTCAPI_VERSION = 'v3'; |
19
|
|
|
const SMS_VERSION='v1'; |
20
|
|
|
|
21
|
|
|
// Zone 空间对应的存储区域 |
22
|
|
|
public $region; |
23
|
|
|
//BOOL 是否使用https域名 |
24
|
|
|
public $useHTTPS; |
25
|
|
|
//BOOL 是否使用CDN加速上传域名 |
26
|
|
|
public $useCdnDomains; |
27
|
|
|
/** |
28
|
|
|
* @var Region |
29
|
|
|
*/ |
30
|
|
|
public $zone; |
31
|
69 |
|
// Zone Cache |
32
|
|
|
private $regionCache; |
33
|
69 |
|
|
34
|
69 |
|
// 构造函数 |
35
|
69 |
|
public function __construct(Region $z = null) |
36
|
69 |
|
{ |
37
|
69 |
|
$this->zone = $z; |
38
|
|
|
$this->useHTTPS = false; |
39
|
18 |
|
$this->useCdnDomains = false; |
40
|
|
|
$this->regionCache = array(); |
41
|
18 |
|
} |
42
|
18 |
|
|
43
|
|
|
public function getUpHost($accessKey, $bucket) |
44
|
|
|
{ |
45
|
18 |
|
$region = $this->getRegion($accessKey, $bucket); |
46
|
|
|
if ($this->useHTTPS === true) { |
47
|
|
|
$scheme = "https://"; |
48
|
18 |
|
} else { |
49
|
18 |
|
$scheme = "http://"; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$host = $region->srcUpHosts[0]; |
53
|
18 |
|
if ($this->useCdnDomains === true) { |
54
|
|
|
$host = $region->cdnUpHosts[0]; |
55
|
|
|
} |
56
|
3 |
|
|
57
|
|
|
return $scheme . $host; |
58
|
3 |
|
} |
59
|
3 |
|
|
60
|
|
|
public function getUpHostV2($accessKey, $bucket) |
61
|
|
|
{ |
62
|
3 |
|
list($region, $err) = $this->getRegionV2($accessKey, $bucket); |
63
|
|
|
if ($err != null) { |
64
|
|
|
return array(null, $err); |
65
|
3 |
|
} |
66
|
3 |
|
|
67
|
|
|
if ($this->useHTTPS === true) { |
68
|
|
|
$scheme = "https://"; |
69
|
|
|
} else { |
70
|
3 |
|
$scheme = "http://"; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$host = $region->srcUpHosts[0]; |
74
|
|
|
if ($this->useCdnDomains === true) { |
75
|
|
|
$host = $region->cdnUpHosts[0]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return array($scheme . $host, null); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getUpBackupHost($accessKey, $bucket) |
82
|
|
|
{ |
83
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
84
|
|
|
if ($this->useHTTPS === true) { |
85
|
|
|
$scheme = "https://"; |
86
|
|
|
} else { |
87
|
|
|
$scheme = "http://"; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$host = $region->cdnUpHosts[0]; |
91
|
|
|
if ($this->useCdnDomains === true) { |
92
|
|
|
$host = $region->srcUpHosts[0]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $scheme . $host; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getUpBackupHostV2($accessKey, $bucket) |
99
|
6 |
|
{ |
100
|
|
|
list($region, $err) = $this->getRegionV2($accessKey, $bucket); |
101
|
6 |
|
if ($err != null) { |
102
|
|
|
return array(null, $err); |
103
|
6 |
|
} |
104
|
|
|
|
105
|
|
|
if ($this->useHTTPS === true) { |
106
|
6 |
|
$scheme = "https://"; |
107
|
|
|
} else { |
108
|
|
|
$scheme = "http://"; |
109
|
6 |
|
} |
110
|
|
|
|
111
|
|
|
$host = $region->cdnUpHosts[0]; |
112
|
|
|
if ($this->useCdnDomains === true) { |
113
|
|
|
$host = $region->srcUpHosts[0]; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return array($scheme . $host, null); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getRsHost($accessKey, $bucket) |
120
|
|
|
{ |
121
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
122
|
|
|
|
123
|
|
|
if ($this->useHTTPS === true) { |
124
|
|
|
$scheme = "https://"; |
125
|
24 |
|
} else { |
126
|
|
|
$scheme = "http://"; |
127
|
24 |
|
} |
128
|
|
|
|
129
|
24 |
|
return $scheme . $region->rsHost; |
130
|
6 |
|
} |
131
|
24 |
|
|
132
|
3 |
|
public function getRsHostV2($accessKey, $bucket) |
133
|
3 |
|
{ |
134
|
3 |
|
list($region, $err) = $this->getRegionV2($accessKey, $bucket); |
135
|
21 |
|
if ($err != null) { |
136
|
21 |
|
return array(null, $err); |
137
|
|
|
} |
138
|
24 |
|
|
139
|
|
|
if ($this->useHTTPS === true) { |
140
|
|
|
$scheme = "https://"; |
141
|
|
|
} else { |
142
|
|
|
$scheme = "http://"; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return array($scheme . $region->rsHost, null); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getRsfHost($accessKey, $bucket) |
149
|
|
|
{ |
150
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
151
|
|
|
|
152
|
|
|
if ($this->useHTTPS === true) { |
153
|
|
|
$scheme = "https://"; |
154
|
|
|
} else { |
155
|
|
|
$scheme = "http://"; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return $scheme . $region->rsfHost; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getRsfHostV2($accessKey, $bucket) |
162
|
|
|
{ |
163
|
|
|
list($region, $err) = $this->getRegionV2($accessKey, $bucket); |
164
|
|
|
if ($err != null) { |
165
|
|
|
return array(null, $err); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
if ($this->useHTTPS === true) { |
169
|
|
|
$scheme = "https://"; |
170
|
|
|
} else { |
171
|
|
|
$scheme = "http://"; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return array($scheme . $region->rsfHost, null); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function getIovipHost($accessKey, $bucket) |
178
|
|
|
{ |
179
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
180
|
|
|
|
181
|
|
|
if ($this->useHTTPS === true) { |
182
|
|
|
$scheme = "https://"; |
183
|
|
|
} else { |
184
|
|
|
$scheme = "http://"; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
return $scheme . $region->iovipHost; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function getIovipHostV2($accessKey, $bucket) |
191
|
|
|
{ |
192
|
|
|
list($region, $err) = $this->getRegionV2($accessKey, $bucket); |
193
|
|
|
if ($err != null) { |
194
|
|
|
return array(null, $err); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
if ($this->useHTTPS === true) { |
198
|
|
|
$scheme = "https://"; |
199
|
|
|
} else { |
200
|
|
|
$scheme = "http://"; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return array($scheme . $region->iovipHost, null); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function getApiHost($accessKey, $bucket) |
207
|
|
|
{ |
208
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
209
|
|
|
|
210
|
|
|
if ($this->useHTTPS === true) { |
211
|
|
|
$scheme = "https://"; |
212
|
|
|
} else { |
213
|
|
|
$scheme = "http://"; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
return $scheme . $region->apiHost; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function getApiHostV2($accessKey, $bucket) |
220
|
|
|
{ |
221
|
|
|
list($region, $err) = $this->getRegionV2($accessKey, $bucket); |
222
|
|
|
if ($err != null) { |
223
|
|
|
return array(null, $err); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
if ($this->useHTTPS === true) { |
227
|
|
|
$scheme = "https://"; |
228
|
|
|
} else { |
229
|
|
|
$scheme = "http://"; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
return array($scheme . $region->apiHost, null); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
private function getRegion($accessKey, $bucket) |
236
|
|
|
{ |
237
|
|
|
$cacheId = "$accessKey:$bucket"; |
238
|
|
|
|
239
|
|
|
if (isset($this->regionCache[$cacheId])) { |
240
|
|
|
$region = $this->regionCache[$cacheId]; |
241
|
|
|
} elseif (isset($this->zone)) { |
242
|
|
|
$region = $this->zone; |
243
|
|
|
$this->regionCache[$cacheId] = $region; |
244
|
|
|
} else { |
245
|
|
|
$region = Zone::queryZone($accessKey, $bucket); |
246
|
|
|
if (is_array($region)) { |
247
|
|
|
list($region, $err) = $region; |
248
|
|
|
if ($err != null) { |
249
|
|
|
throw new \Exception($err->message()); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
$this->regionCache[$cacheId] = $region; |
253
|
|
|
} |
254
|
|
|
return $region; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
private function getRegionV2($accessKey, $bucket) |
258
|
|
|
{ |
259
|
|
|
$cacheId = "$accessKey:$bucket"; |
260
|
|
|
|
261
|
|
|
if (isset($this->regionCache[$cacheId])) { |
262
|
|
|
$region = $this->regionCache[$cacheId]; |
263
|
|
|
} elseif (isset($this->zone)) { |
264
|
|
|
$region = $this->zone; |
265
|
|
|
$this->regionCache[$cacheId] = $region; |
266
|
|
|
} else { |
267
|
|
|
$region = Zone::queryZone($accessKey, $bucket); |
268
|
|
|
if (is_array($region)) { |
269
|
|
|
list($region, $err) = $region; |
270
|
|
|
return array($region, $err); |
271
|
|
|
} |
272
|
|
|
$this->regionCache[$cacheId] = $region; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
return array($region, null); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|