PHP code example of sy-records / vod-hls

1. Go to this page and download the library: Download sy-records/vod-hls 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/ */

    

sy-records / vod-hls example snippets


/**
 * 创建 HLS 普通加密模板
 * @url https://cloud.tencent.com/document/product/266/35167
 */
$config = [
    "Action" => "CreateSimpleAesTemplate", // 接口指令的名称
    "get_key_url" => "", // HLS 普通加密模板的 GetKeyURL 必须https
    "Region" => "", // 区域参数
    "Timestamp" => time(), // 当前 UNIX 时间戳
    "Nonce" => uniqid(), // 随机正整数,与 Timestamp 联合起来, 用于防止重放攻击
    "SecretId" => "", // 由腾讯云平台上申请的标识身份的 SecretId
];

$secretKey = ""; // 由腾讯云平台上申请的标识身份的SecretKey 需要生成签名

$data = Core::getCloudData($config, $secretKey);


/**
 * 通过 ProcessFile 接口发起视频加密
 * @url https://cloud.tencent.com/document/product/266/9642
 */
$config = [
	"Action" => "ProcessFile",
	"fileId" => "", // 文件 ID
	"transcode.definition.0" => 230, // 转码输出模板号
	"transcode.drm.definition" => 10, // 视频加密控制参数,加密方式;
	"Region" => "", // 区域参数
	"Timestamp" => time(), // 当前 UNIX 时间戳
	"Nonce" => uniqid(), // 随机正整数,与 Timestamp 联合起来, 用于防止重放攻击
	"SecretId" => "", // 由腾讯云平台上申请的标识身份的 SecretId
	"notifyMode" => "Finish" // 任务流状态变更通知模式任务流状态变更通知模式。
];

$secretKey = ""; // 由腾讯云平台上申请的标识身份的SecretKey 需要生成签名

$data = Core::getCloudData($config, $secretKey);


/**
 * 获取视频信息
 * @url https://cloud.tencent.com/document/product/266/8586
 */
$config = [
	"Action" => "GetVideoInfo",
	"fileId" => "", // 文件 ID
	"Region" => "", // 区域参数
	"Timestamp" => time(), // 当前 UNIX 时间戳
	"Nonce" => uniqid(), // 随机正整数,与 Timestamp 联合起来, 用于防止重放攻击
	"SecretId" => "", // 由腾讯云平台上申请的标识身份的 SecretId
	"notifyMode" => "Finish" // 任务流状态变更通知模式任务流状态变更通知模式。
];

$secretKey = ""; // 由腾讯云平台上申请的标识身份的SecretKey 需要生成签名

$data = Core::getCloudData($config, $secretKey);

/**
 * getkeyurl获取dk
 * @url https://cloud.tencent.com/document/product/266/9643
 */
$config = [
	"Action" => "DescribeDrmDataKey",
	"edkList.0" => "", // 视频edk
	"Region" => "", // 区域参数
	"Timestamp" => time(), // 当前 UNIX 时间戳
	"Nonce" => uniqid(), // 随机正整数,与 Timestamp 联合起来, 用于防止重放攻击
	"SecretId" => "", // 由腾讯云平台上申请的标识身份的 SecretId
];

$secretKey = ""; // 由腾讯云平台上申请的标识身份的SecretKey 需要生成签名

$data = Core::getCloudData($config, $secretKey);

$res = json_decode($data,true);

// 需要进行decode还原为二进制
echo base64_decode($res['data']['keyList'][0]['dk']);