Home  >  Article  >  Backend Development  >  PHP 怎么设置过期时间?

PHP 怎么设置过期时间?

WBOY
WBOYOriginal
2016-06-06 20:46:371271browse

我是在官方例子看到的代码

$getPolicy = new Qiniu_RS_GetPolicy();
$privateUrl = $getPolicy->MakeRequest($baseUrl, null);

这里的 null 是个什么参数?
官方的API 感觉很不详细。

回复内容:

我是在官方例子看到的代码

$getPolicy = new Qiniu_RS_GetPolicy();
$privateUrl = $getPolicy->MakeRequest($baseUrl, null);

这里的 null 是个什么参数?
官方的API 感觉很不详细。

为什么不看源码

<code class="lang-php"><?php class Qiniu_RS_GetPolicy
{
    public $Expires;

    public function MakeRequest($baseUrl, $mac) // => $privateUrl
    {
        $deadline = $this->Expires;
        if ($deadline == 0) {
            $deadline = 3600;
        }
        $deadline += time();

        $pos = strpos($baseUrl, '?');
        if ($pos !== false) {
            $baseUrl .= '&e=';
        } else {
            $baseUrl .= '?e=';
        }
        $baseUrl .= $deadline;

        $token = Qiniu_Sign($mac, $baseUrl);
        return "$baseUrl&token=$token";
    }
}
</code>
<code class="lang-php"><?php function Qiniu_RequireMac($mac) // => $mac
{
    if (isset($mac)) {
        return $mac;
    }

    global $QINIU_ACCESS_KEY;
    global $QINIU_SECRET_KEY;

    return new Qiniu_Mac($QINIU_ACCESS_KEY, $QINIU_SECRET_KEY);
}
</code>

如果mac不为null,则直接返回mac。
比如:

<code><?php echo Qiniu_Sign('abc',$baseurl);
// 会输出abc   而不是hash后的sign
</code></code>

七牛官方的 PHP SDK 很难用,还是看看这个吧:https://github.com/hfcorriez/php-qiniu

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn