Skip to content

Commit

Permalink
增加签名
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Jun 5, 2018
1 parent 622b42c commit 028afef
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Service/TencentyunCosV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,31 @@ class TencentyunCosV5 extends Tencentyun
*/
protected $client;

public function signUrl($url, $seconds = '+10 minutes')
public function signUrl($url, $seconds = 60)
{
$url = $this->getClient()->getObjectUrl($this->bucket, $url, $seconds);
// 默认域名直接使用
//$url = $this->getClient()->getObjectUrl($this->bucket, $url, $seconds);

return $url;
$sign = $this->generateSign($seconds);

return $url . '?sign=' . $sign;
}

protected function generateSign($seconds)
{
$appId = $this->appId;
$bucket = $this->bucket;
$secretId = $this->secretId;
$secretKey = $this->secretKey;
$expired = time() + $seconds;
$current = time();
$rdm = rand();

$sign = 'a=' . $appId . '&b=' . $bucket . '&k=' . $secretId
. '&e=' . $expired . '&t=' . $current . '&r=' . $rdm . '&f=';
$sign = base64_encode(hash_hmac('SHA1', $sign, $secretKey, true) . $sign);

return $sign;
}

public function getClient()
Expand Down

0 comments on commit 028afef

Please sign in to comment.