创建并验证具有有限生效期的签名 URL
use Spatie\UrlSigner\Laravel\Facades\UrlSigner;
UrlSigner::sign('https://myapp.com/protected-route', now()->addDays(30));
输出如下:
https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx
可以使用 `validate` 函数验证 URL。php
// returns true if the signed URL is valid, false if not
UrlSigner::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');
该包还提供了 [用于保护路由的中间件](https://github.com/spatie/laravel-url-signer#protecting-routes-with-middleware)。
您必须设置名为 `URL_SIGNER_SIGNATURE_KEY` 的环境变量,并将其设置为一个长的秘密值。此值将用于签名和验证签名的 URL。
[](https://spatie.be/github-ad-click/laravel-url-signer)暂无开放 Issues,或尚未同步最近议题。