From 96b9bbe0f6ddeef79987f2c6b2cdfb1b49133abc Mon Sep 17 00:00:00 2001 From: lewzylu <327874225@qq.com> Date: Mon, 28 Jan 2019 20:42:22 +0800 Subject: [PATCH] feature-ip-port --- src/Qcloud/Cos/BucketStyleListener.php | 2 +- src/Qcloud/Cos/Client.php | 8 ++--- src/Qcloud/Cos/Service.php | 50 +++++++++++++++++++++----- src/Qcloud/Cos/Signature.php | 1 + 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/Qcloud/Cos/BucketStyleListener.php b/src/Qcloud/Cos/BucketStyleListener.php index 63f8fefb..a91d1ec0 100644 --- a/src/Qcloud/Cos/BucketStyleListener.php +++ b/src/Qcloud/Cos/BucketStyleListener.php @@ -73,7 +73,7 @@ public function onCommandAfterPrepare(Event $event) { { $bucket = $bucket.'-'.$this->appId; } - $request->setPath(urldecode($request->getPath())); +// $request->setPath(urldecode($request->getPath())); $request->getParams()->set('bucket', $bucket)->set('key', $key); $realHost = $bucket. '.' . $request->getHost(); diff --git a/src/Qcloud/Cos/Client.php b/src/Qcloud/Cos/Client.php index 773f57a7..a58c3861 100644 --- a/src/Qcloud/Cos/Client.php +++ b/src/Qcloud/Cos/Client.php @@ -235,14 +235,14 @@ public function doesObjectExist($bucket, $key, array $options = array()) } } public static function encodeKey($key) { - return $key; +// return $key; return str_replace('%2F', '/', rawurlencode($key)); } public static function explodeKey($key) { // Remove a leading slash if one is found - //return explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key); - return $key; - return ltrim($key, "/"); + return explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key); +// return $key; +// return ltrim($key, "/"); } } diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index a2d0abb1..dd0abb18 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -43,7 +43,9 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri', - 'minLength' => 1), + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), 'UploadId' => array( 'required' => true, 'type' => 'string', @@ -133,7 +135,9 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri', - 'minLength' => 1), + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), 'Parts' => array( 'type' => 'array', 'location' => 'xml', @@ -235,6 +239,8 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'Metadata' => array( 'type' => 'object', @@ -409,6 +415,8 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'Metadata' => array( 'type' => 'object', @@ -590,7 +598,9 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri', - 'minLength' => 1), + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), 'MFA' => array( 'type' => 'string', 'location' => 'header', @@ -670,6 +680,8 @@ public static function getService() { 'required' => true, 'type' => 'string', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'VersionId' => array( 'type' => 'string', @@ -800,7 +812,9 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri', - 'minLength' => 1), + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), 'Range' => array( 'type' => 'string', 'location' => 'header'), @@ -880,6 +894,8 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'VersionId' => array( 'type' => 'string', @@ -1171,7 +1187,9 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri', - 'minLength' => 1), + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), 'PartNumber' => array( 'required' => true, 'type' => 'numeric', @@ -1264,7 +1282,9 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri', - 'minLength' => 1), + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), 'Metadata' => array( 'type' => 'object', 'location' => 'header', @@ -1444,6 +1464,8 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'RequestPayer' => array( 'type' => 'string', @@ -1833,6 +1855,8 @@ public static function getService() { 'Key' => array( 'type' => 'string' ), + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey'), 'Value' => array( 'type' => 'string' ), @@ -2103,6 +2127,8 @@ public static function getService() { ), ), ), + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), ), ), @@ -2132,6 +2158,8 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'VersionId' => array( 'type' => 'string', @@ -2197,7 +2225,9 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri', - 'minLength' => 1), + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), 'MaxParts' => array( 'type' => 'numeric', 'location' => 'query', @@ -2456,6 +2486,8 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'Range' => array( 'type' => 'string', @@ -2599,6 +2631,8 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey') ), 'PartNumber' => array( 'required' => true, @@ -2685,7 +2719,7 @@ public static function getService() { ), 'Key' => array( 'type' => 'string', - 'location' => 'xml', + 'location' => 'xml' ), 'Expiration' => array( 'type' => 'string', diff --git a/src/Qcloud/Cos/Signature.php b/src/Qcloud/Cos/Signature.php index 51c02e91..ae5fa10d 100644 --- a/src/Qcloud/Cos/Signature.php +++ b/src/Qcloud/Cos/Signature.php @@ -11,6 +11,7 @@ public function __construct($accessKey, $secretKey) { public function __destruct() { } public function signRequest(RequestInterface $request) { + $signTime = (string)(time() - 60) . ';' . (string)(time() + 3600); $httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) . "\n\nhost=" . $request->getHost() . "\n";