ImgURL是一个简单、纯粹的图床程序,让个人图床多一个选择。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

7 years ago
<?php
/**
* Signature create related functions.
*/
namespace QcloudImage;
/**
* Auth class for creating reusable signature.
*/
class Auth {
public function __construct($appId, $secretId, $secretKey) {
$this->appId = $appId;
$this->secretId = $secretId;
$this->secretKey = $secretKey;
}
/**
* Return the appId
*/
public function getAppId() {
return $this->appId;
}
/**
* Create reusable signature.
* This signature will expire at time()+$howlong timestamp.
* Return the signature on success.
* Return false on fail.
*/
public function getSign($bucket, $howlong = 30) {
if ($howlong <= 0) {
return false;
}
$now = time();
$expiration = $now + $howlong;
$random = rand();
$plainText = "a=".$this->appId."&b=$bucket&k=".$this->secretId."&e=$expiration&t=$now&r=$random&f=";
$bin = hash_hmac('SHA1', $plainText, $this->secretKey, true);
return base64_encode($bin.$plainText);
}
private $appId = "";
private $secretId = "";
private $secretKey = "";
}