PHP code example of ttvcloud / vcloud-sdk-php

1. Go to this page and download the library: Download ttvcloud/vcloud-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ttvcloud / vcloud-sdk-php example snippets


composer 

$client = Vod::getInstance();
// call below method if you dont set ak and sk in ~/.vcloud/config
// $client->setAccessKey($ak);
// $client->setSecretKey($sk);

$expire = 60; // 请求的签名有效期

echo "\nSTS2鉴权签名\n";
$space = "";
$response = $client->getVideoPlayAuthWithExpiredTime([], [], [], $expire);
echo json_encode($response);

echo "\nSTS2鉴权签名,过期时间默认1小时\n";
$vid = "";
$response = $client->getVideoPlayAuth([], [], []);
echo json_encode($response);

// 第1步 创建 actions 和 resources
$actions = ['service:Method']; // eg: vod:GetPlayInfo
$resources = [];
// 其中每个 resource 格式类似 "trn:vod::*:video_id/%s",若允许全部则用 * 替代,否则用实际字符串替代,本例可以填写实际的 vid
if (sizeof($vidList) == 0) {
    $resources[] = sprintf($ResourceVideoFormat, "*");
} else {
    foreach ($vidList as $vid) {
        $resources[] = sprintf($ResourceVideoFormat, $vid);
    }
}

// 第2步 创建 Statement,允许的 NewAllowStatement, 拒绝的 NewDenyStatement,并添加到 Policy 对应的 Statement 数组里,并创建 Policy
$statement = $this->newAllowStatement($actions, $resources);
$policy = [
    'Statement' => [$statement],
];

// 第3步 调用 signSts2 生成签名
$this->signSts2($policy, $expire);