Skip to content

Commit

Permalink
Update test sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
superxxm committed Jun 25, 2019
1 parent 4ff1c5f commit 9d40c86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
6 changes: 3 additions & 3 deletions examples/DemoVodPlay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

23 changes: 4 additions & 19 deletions examples/DemoVodUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

27 changes: 17 additions & 10 deletions src/Service/Vod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -77,7 +84,7 @@ private function getUploadAuthTokenV1(string $space, array &$token)
'config' => [
'query' => [
'Action' => 'ApplyUpload',
'Version' => '2019-03-05',
'Version' => '2018-01-01',
],
]
],
Expand All @@ -87,7 +94,7 @@ private function getUploadAuthTokenV1(string $space, array &$token)
'config' => [
'query' => [
'Action' => 'CommitUpload',
'Version' => '2019-03-05',
'Version' => '2018-01-01',
],
]
],
Expand Down

0 comments on commit 9d40c86

Please sign in to comment.