Skip to content

Commit a9b6716

Browse files
authored
Bump to 7.13.0 (#431)
1 parent f5a6fcf commit a9b6716

File tree

10 files changed

+281
-31
lines changed

10 files changed

+281
-31
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 7.13.0 (2024-09-05)
4+
* 对象存储,验证回调方法新增支持 Qiniu 签名
5+
* 对象存储,调整查询空间区域域名顺序与默认空间管理域名
6+
* 支持闲时任务配置
7+
38
## 7.12.1 (2024-02-21)
49
* 对象存储,添加上传策略部分字段
510

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
],
2020
"require": {
2121
"php": ">=5.3.3",
22+
"ext-xml": "*",
23+
"ext-curl": "*",
2224
"myclabs/php-enum": "~1.5.2 || ~1.6.6 || ~1.7.7 || ~1.8.4"
2325
},
2426
"require-dev": {

src/Qiniu/Auth.php

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Qiniu;
34

45
use Qiniu\Http\Header;
@@ -94,7 +95,7 @@ public function signQiniuAuthorization($urlString, $method = "GET", $body = "",
9495
$data .= ":" . $url["port"];
9596
}
9697

97-
// try append content type
98+
// try to append content type
9899
if ($headers != null && isset($headers["Content-Type"])) {
99100
// append content type
100101
$data .= "\n";
@@ -133,9 +134,32 @@ public function signQiniuAuthorization($urlString, $method = "GET", $body = "",
133134
return array($this->sign($data), null);
134135
}
135136

136-
public function verifyCallback($contentType, $originAuthorization, $url, $body)
137-
{
138-
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
137+
public function verifyCallback(
138+
$contentType,
139+
$originAuthorization,
140+
$url,
141+
$body,
142+
$method = "GET",
143+
$headers = array()
144+
) {
145+
if (strpos($originAuthorization, 'Qiniu') === 0) {
146+
$qnHeaders = new Header($headers);
147+
if (!isset($qnHeaders['Content-Type'])) {
148+
$qnHeaders['Content-Type'] = $contentType;
149+
}
150+
list($sign, $err) = $this->signQiniuAuthorization(
151+
$url,
152+
$method,
153+
$body,
154+
$qnHeaders
155+
);
156+
if ($err !== null) {
157+
return false;
158+
}
159+
$authorization = 'Qiniu ' . $sign;
160+
} else {
161+
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
162+
}
139163
return $originAuthorization === $authorization;
140164
}
141165

@@ -198,6 +222,7 @@ public function uploadToken($bucket, $key = null, $expires = 3600, $policy = nul
198222
'persistentOps',
199223
'persistentNotifyUrl',
200224
'persistentPipeline',
225+
'persistentType', // 为 `1` 时开启闲时任务
201226

202227
'deleteAfterDays',
203228
'fileType',

src/Qiniu/Config.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
final class Config
66
{
7-
const SDK_VER = '7.12.1';
7+
const SDK_VER = '7.13.0';
88

99
const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
1010

1111
const RSF_HOST = 'rsf.qiniuapi.com';
1212
const API_HOST = 'api.qiniuapi.com';
13-
const RS_HOST = 'rs.qiniuapi.com'; //RS Host
14-
const UC_HOST = 'uc.qbox.me'; //UC Host
15-
const QUERY_REGION_HOST = 'kodo-config.qiniuapi.com';
13+
const RS_HOST = 'rs.qiniuapi.com'; // RS Host
14+
const UC_HOST = 'uc.qiniuapi.com'; // UC Host
15+
const QUERY_REGION_HOST = Config::UC_HOST;
1616
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
1717
const ARGUS_HOST = 'ai.qiniuapi.com';
1818
const CASTER_HOST = 'pili-caster.qiniuapi.com';
@@ -50,8 +50,8 @@ public function __construct(Region $z = null)
5050
$this->ucHost = Config::UC_HOST;
5151
$this->queryRegionHost = Config::QUERY_REGION_HOST;
5252
$this->backupQueryRegionHosts = array(
53+
"kodo-config.qiniuapi.com",
5354
"uc.qbox.me",
54-
"api.qiniu.com"
5555
);
5656
$this->backupUcHostsRetryTimes = 2;
5757
}

src/Qiniu/Http/Header.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ public function __construct($obj = array())
1818
foreach ($obj as $key => $values) {
1919
$normalizedKey = self::normalizeKey($key);
2020
$normalizedValues = array();
21-
foreach ($values as $value) {
22-
array_push($normalizedValues, self::normalizeValue($value));
21+
if (!is_array($values)) {
22+
array_push(
23+
$normalizedValues,
24+
self::normalizeValue($values)
25+
);
26+
} else {
27+
foreach ($values as $value) {
28+
array_push(
29+
$normalizedValues,
30+
self::normalizeValue($value)
31+
);
32+
}
2333
}
2434
$this->data[$normalizedKey] = $normalizedValues;
2535
}

src/Qiniu/Processing/PersistentFop.php

+32-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Qiniu\Http\Error;
77
use Qiniu\Http\Client;
88
use Qiniu\Http\Proxy;
9+
use Qiniu\Zone;
910

1011
/**
1112
* 持久化处理类,该类用于主动触发异步持久化操作.
@@ -45,25 +46,34 @@ public function __construct($auth, $config = null, $proxy = null, $proxy_auth =
4546
* 对资源文件进行异步持久化处理
4647
* @param string $bucket 资源所在空间
4748
* @param string $key 待处理的源文件
48-
* @param string $fops string|array 待处理的pfop操作,多个pfop操作以array的形式传入。
49+
* @param string|array $fops 待处理的pfop操作,多个pfop操作以array的形式传入。
4950
* eg. avthumb/mp3/ab/192k, vframe/jpg/offset/7/w/480/h/360
5051
* @param string $pipeline 资源处理队列
5152
* @param string $notify_url 处理结果通知地址
5253
* @param bool $force 是否强制执行一次新的指令
54+
* @param int $type 为 `1` 时开启闲时任务
5355
*
5456
*
55-
* @return array 返回持久化处理的persistentId, 和返回的错误
57+
* @return array 返回持久化处理的 persistentId 与可能出现的错误
5658
*
5759
* @link http://developer.qiniu.com/docs/v6/api/reference/fop/
5860
*/
59-
public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = null, $force = false)
60-
{
61+
public function execute(
62+
$bucket,
63+
$key,
64+
$fops,
65+
$pipeline = null,
66+
$notify_url = null,
67+
$force = false,
68+
$type = null
69+
) {
6170
if (is_array($fops)) {
6271
$fops = implode(';', $fops);
6372
}
6473
$params = array('bucket' => $bucket, 'key' => $key, 'fops' => $fops);
6574
\Qiniu\setWithoutEmpty($params, 'pipeline', $pipeline);
6675
\Qiniu\setWithoutEmpty($params, 'notifyURL', $notify_url);
76+
\Qiniu\setWithoutEmpty($params, 'type', $type);
6777
if ($force) {
6878
$params['force'] = 1;
6979
}
@@ -72,7 +82,8 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
7282
if ($this->config->useHTTPS === true) {
7383
$scheme = "https://";
7484
}
75-
$url = $scheme . Config::API_HOST . '/pfop/';
85+
$apiHost = $this->getApiHost();
86+
$url = $scheme . $apiHost . '/pfop/';
7687
$headers = $this->auth->authorization($url, $data, 'application/x-www-form-urlencoded');
7788
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
7889
$response = Client::post($url, $data, $headers, $this->proxy->makeReqOpt());
@@ -84,18 +95,33 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
8495
return array($id, null);
8596
}
8697

98+
/**
99+
* @param string $id
100+
* @return array 返回任务状态与可能出现的错误
101+
*/
87102
public function status($id)
88103
{
89104
$scheme = "http://";
90105

91106
if ($this->config->useHTTPS === true) {
92107
$scheme = "https://";
93108
}
94-
$url = $scheme . Config::API_HOST . "/status/get/prefop?id=$id";
109+
$apiHost = $this->getApiHost();
110+
$url = $scheme . $apiHost . "/status/get/prefop?id=$id";
95111
$response = Client::get($url, array(), $this->proxy->makeReqOpt());
96112
if (!$response->ok()) {
97113
return array(null, new Error($url, $response));
98114
}
99115
return array($response->json(), null);
100116
}
117+
118+
private function getApiHost()
119+
{
120+
if (!empty($this->config->zone) && !empty($this->config->zone->apiHost)) {
121+
$apiHost = $this->config->zone->apiHost;
122+
} else {
123+
$apiHost = Config::API_HOST;
124+
}
125+
return $apiHost;
126+
}
101127
}

tests/Qiniu/Tests/AuthTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,61 @@ public function testDisableQiniuTimestampSignatureEnvBeIgnored()
236236
$this->assertArrayHasKey("X-Qiniu-Date", $authedHeaders);
237237
putenv('DISABLE_QINIU_TIMESTAMP_SIGNATURE');
238238
}
239+
public function testQboxVerifyCallbackShouldOkWithRequiredOptions()
240+
{
241+
$auth = new Auth('abcdefghklmnopq', '1234567890');
242+
$ok = $auth->verifyCallback(
243+
'application/x-www-form-urlencoded',
244+
'QBox abcdefghklmnopq:T7F-SjxX7X2zI4Fc1vANiNt1AUE=',
245+
'https://test.qiniu.com/callback',
246+
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123'
247+
);
248+
$this->assertTrue($ok);
249+
}
250+
public function testQboxVerifyCallbackShouldOkWithOmitOptions()
251+
{
252+
$auth = new Auth('abcdefghklmnopq', '1234567890');
253+
$ok = $auth->verifyCallback(
254+
'application/x-www-form-urlencoded',
255+
'QBox abcdefghklmnopq:T7F-SjxX7X2zI4Fc1vANiNt1AUE=',
256+
'https://test.qiniu.com/callback',
257+
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123',
258+
'POST', // this should be omit
259+
array(
260+
'X-Qiniu-Bbb' => 'BBB'
261+
) // this should be omit
262+
);
263+
$this->assertTrue($ok);
264+
}
265+
public function testQiniuVerifyCallbackShouldOk()
266+
{
267+
$auth = new Auth('abcdefghklmnopq', '1234567890');
268+
$ok = $auth->verifyCallback(
269+
'application/x-www-form-urlencoded',
270+
'Qiniu abcdefghklmnopq:ZqS7EZuAKrhZaEIxqNGxDJi41IQ=',
271+
'https://test.qiniu.com/callback',
272+
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123',
273+
'GET',
274+
array(
275+
'X-Qiniu-Bbb' => 'BBB'
276+
)
277+
);
278+
$this->assertTrue($ok);
279+
}
280+
public function testQiniuVerifyCallbackShouldFailed()
281+
{
282+
$auth = new Auth('abcdefghklmnopq', '1234567890');
283+
$ok = $auth->verifyCallback(
284+
'application/x-www-form-urlencoded',
285+
'Qiniu abcdefghklmnopq:ZqS7EZuAKrhZaEIxqNGxDJi41IQ=',
286+
'https://test.qiniu.com/callback',
287+
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123',
288+
'POST',
289+
array(
290+
'X-Qiniu-Bbb' => 'BBB'
291+
)
292+
);
293+
$this->assertFalse($ok);
294+
}
239295
}
240296
}

tests/Qiniu/Tests/ConfigTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ public function testGetApiHostV2Errored()
6666
public function testSetUcHost()
6767
{
6868
$conf = new Config();
69-
$this->assertEquals("http://uc.qbox.me", $conf->getUcHost());
69+
$this->assertEquals('http://' . Config::UC_HOST, $conf->getUcHost());
7070
$conf->setUcHost("uc.example.com");
7171
$this->assertEquals("http://uc.example.com", $conf->getUcHost());
7272

7373
$conf = new Config();
7474
$conf->useHTTPS = true;
75-
$this->assertEquals("https://uc.qbox.me", $conf->getUcHost());
75+
$this->assertEquals('https://' . Config::UC_HOST, $conf->getUcHost());
7676
$conf->setUcHost("uc.example.com");
7777
$this->assertEquals("https://uc.example.com", $conf->getUcHost());
7878
}
@@ -94,7 +94,7 @@ public function testGetRegionWithBackupDomains()
9494
"fake-uc.phpsdk.qiniu.com",
9595
array(
9696
"unavailable-uc.phpsdk.qiniu.com",
97-
"uc.qbox.me" // real uc
97+
Config::UC_HOST // real uc
9898
)
9999
);
100100
list(, $err) = $conf->getRsHostV2($this->accessKey, $this->bucketName);
@@ -108,7 +108,7 @@ public function testGetRegionWithUcAndBackupDomains()
108108
$conf->setBackupQueryRegionHosts(
109109
array(
110110
"unavailable-uc.phpsdk.qiniu.com",
111-
"uc.qbox.me" // real uc
111+
Config::UC_HOST // real uc
112112
)
113113
);
114114
list(, $err) = $conf->getRsHostV2($this->accessKey, $this->bucketName);

tests/Qiniu/Tests/MiddlewareTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testSendWithMiddleware()
5252

5353
$request = new Request(
5454
"GET",
55-
"https://qiniu.com/index.html",
55+
"http://localhost:9000/ok.php",
5656
array(),
5757
null,
5858
$reqOpt
@@ -79,7 +79,7 @@ public function testSendWithRetryDomains()
7979
new Middleware\RetryDomainsMiddleware(
8080
array(
8181
"unavailable.phpsdk.qiniu.com",
82-
"qiniu.com",
82+
"localhost:9000",
8383
),
8484
3
8585
),
@@ -88,7 +88,7 @@ public function testSendWithRetryDomains()
8888

8989
$request = new Request(
9090
"GET",
91-
"https://fake.phpsdk.qiniu.com/index.html",
91+
"http://fake.phpsdk.qiniu.com/ok.php",
9292
array(),
9393
null,
9494
$reqOpt
@@ -130,7 +130,7 @@ public function testSendFailFastWithRetryDomains()
130130
new Middleware\RetryDomainsMiddleware(
131131
array(
132132
"unavailable.phpsdk.qiniu.com",
133-
"qiniu.com",
133+
"localhost:9000",
134134
),
135135
3,
136136
function () {
@@ -142,7 +142,7 @@ function () {
142142

143143
$request = new Request(
144144
"GET",
145-
"https://fake.phpsdk.qiniu.com/index.html",
145+
"http://fake.phpsdk.qiniu.com/ok.php",
146146
array(),
147147
null,
148148
$reqOpt

0 commit comments

Comments
 (0)