Skip to content

Commit b47e512

Browse files
author
justinlguo
committed
update watermark&add token
1 parent df6e869 commit b47e512

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

sample/GetHLSTokenDemo.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
$playKey = 'playKey';//替换为用户的 playKey,请通过该接口进行查看和管理,https://cloud.tencent.com/document/product/460/104329
4+
$bucket = 'examplebucket-1250000000';
5+
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
6+
$publicKey = "publicKey";
7+
$header = array(
8+
'alg' => 'HS256',
9+
'typ' => 'JWT'
10+
);
11+
$payload = array(
12+
"Type" => "CosCiToken",
13+
"AppId" => "1250000000",
14+
"BucketId" => $bucket,
15+
"Object" => "exampleobject",
16+
"Issuer" => "client",
17+
"IssuedTimeStamp" => time(),
18+
"ExpireTimeStamp" => time() + 3600 * 6,
19+
"UsageLimit" => 3,
20+
"ProtectSchema" => "rsa1024",
21+
"PublicKey" => base64_encode($publicKey),
22+
"ProtectContentKey" => 1,
23+
);
24+
$base64header = base64UrlEncode(json_encode($header, JSON_UNESCAPED_UNICODE));
25+
$base64payload = base64UrlEncode(json_encode($payload, JSON_UNESCAPED_UNICODE));
26+
$token = $base64header . '.' . $base64payload . '.' . base64UrlEncode(hash_hmac('sha256', $base64header . '.' . $base64payload, $playKey, true));
27+
echo $token;
28+
29+
function base64UrlEncode($input) {
30+
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
31+
}

sample/getBlindWatermark.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
$blindWatermarkTemplate->setPick();
1919
$blindWatermarkTemplate->setImage("http://examplebucket-125000000.cos.ap-beijing.myqcloud.com/shuiyin.jpeg");
2020
$blindWatermarkTemplate->setType(2);
21+
$blindWatermarkTemplate->setVersion("2.0");
2122
$picOperationsTemplate = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
2223
$picOperationsTemplate->setIsPicInfo(1);
2324
$picOperationsTemplate->addRule($blindWatermarkTemplate, "resultobject");

sample/putBlindWatermark.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
$blindWatermarkTemplate = new Qcloud\Cos\ImageParamTemplate\BlindWatermarkTemplate();
1818
$blindWatermarkTemplate->setText("Test");
1919
$blindWatermarkTemplate->setType(3);
20+
$blindWatermarkTemplate->setVersion("2.0");
2021
$picOperationsTemplate = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
2122
$picOperationsTemplate->setIsPicInfo(1);
2223
$picOperationsTemplate->addRule($blindWatermarkTemplate, "resultobject");

0 commit comments

Comments
 (0)