diff --git a/examples/DemoVodPlay.php b/examples/DemoVodPlay.php index 71b37fa..3921abb 100644 --- a/examples/DemoVodPlay.php +++ b/examples/DemoVodPlay.php @@ -8,11 +8,11 @@ $response = Vod::getInstance()->request('GetPlayInfo', ['query' => ['video_id' => $vid]]); echo (string)$response->getBody(); -echo "\n获取签名以后的openAPI连接\n"; +echo "\n获取新版本签名以后的openAPI连接\n"; $response = Vod::getInstance()->getPlayAuthToken(['query' => ['video_id' => $vid]]); echo (string)$response; -echo "\n获取签名以后的openAPI连接\n"; -$response = Vod::getInstance()->getRequestUrl('GetPlayInfo', ['query' => ['video_id' => $vid]]); +echo "\n获取老版本签名以后的openAPI连接\n"; +$response = Vod::getInstance()->getPlayAuthToken(['query' => ['video_id' => $vid]], "v0"); echo (string)$response; diff --git a/examples/DemoVodUpload.php b/examples/DemoVodUpload.php index 9274344..b864c7f 100644 --- a/examples/DemoVodUpload.php +++ b/examples/DemoVodUpload.php @@ -20,15 +20,9 @@ echo "\nstaging-3:初始化上传\n"; $uploadAddress = json_decode((string)$response->getBody(), true); -$oid = $uploadAddress['Result']['UploadAddress']['Oid']; +$oid = $uploadAddress['Result']['UploadAddress']['StoreInfos'][0]['StoreUri']; $session = $uploadAddress['Result']['UploadAddress']['SessionKey']; -$auth = $uploadAddress['Result']['UploadAddress']['UploadAuth']; - -$response = Tos::getInstance()->request('InitUpload', [ - 'replace' => ['ObjectName' => $oid], - 'headers' => ['Authorization' => $auth] -]); -echo (string)$response->getBody(); +$auth = $uploadAddress['Result']['UploadAddress']['StoreInfos'][0]['Auth']; echo "\nstaging-4:分片上传\n"; $uploadInfo = json_decode((string)$response->getBody(), true); @@ -43,16 +37,7 @@ ]); echo (string)$response->getBody(); -echo "\nstaging-5:tos回写上传成功\n"; -$response = Tos::getInstance()->request('CommitUpload', [ - 'replace' => ['ObjectName' => $oid], - 'headers' => ['Authorization' => $auth], - 'query' => ['uploadID' => $uploadID], - 'body' => "0:$crc32" -]); -echo (string)$response->getBody(); - -echo "\nstaing-6:确认上传\n"; -$response = Vod::getInstance()->request('CommitUpload', ['query' => ['SpaceName' => $space], 'json' => ['Oid' => $oid, 'SessionKey' => $session]]); +echo "\nstaing-5:确认上传\n"; +$response = Vod::getInstance()->request('CommitUpload', ['query' => ['SpaceName' => $space], 'json' => ['SessionKey' => $session]]); echo (string)$response->getBody(); diff --git a/src/Service/Vod.php b/src/Service/Vod.php index 77519fa..e139165 100644 --- a/src/Service/Vod.php +++ b/src/Service/Vod.php @@ -21,17 +21,24 @@ protected function getConfig() ]; } - public function getPlayAuthToken(array $config = []) + public function getPlayAuthToken(array $config = [], string $version = "v1") { - $url = $this->getRequestUrl("GetPlayInfo", $config); - - $m = parse_url($url); - return $m["query"]; + switch ($version) { + case "v1": + $token = ["Version" => $version]; + $token["GetPlayInfoToken"] = parse_url($this->getRequestUrl("GetPlayInfo", $config))["query"]; + return base64_encode(json_encode($token)); + case "v0": + $url = $this->getRequestUrl("GetPlayInfo", $config); + $m = parse_url($url); + return $m["query"]; + default: + $token = ["Version" => $version]; + $token["GetPlayInfoToken"] = parse_url($this->getRequestUrl("GetPlayInfo", $config))["query"]; + return base64_encode(json_encode($token)); + } } - /* - * Version: - * */ public function getUploadAuthToken(string $space, string $version = "v1") { $token = ["Version" => $version]; @@ -77,7 +84,7 @@ private function getUploadAuthTokenV1(string $space, array &$token) 'config' => [ 'query' => [ 'Action' => 'ApplyUpload', - 'Version' => '2019-03-05', + 'Version' => '2018-01-01', ], ] ], @@ -87,7 +94,7 @@ private function getUploadAuthTokenV1(string $space, array &$token) 'config' => [ 'query' => [ 'Action' => 'CommitUpload', - 'Version' => '2019-03-05', + 'Version' => '2018-01-01', ], ] ],