vendor/codeages/biz-framework/src/Token/Service/Impl/RedisTokenServiceImpl.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Codeages\Biz\Framework\Token\Service\Impl;
use Codeages\Biz\Framework\Context\Biz;
use Codeages\Biz\Framework\Token\Service\GenerateException;
use Codeages\Biz\Framework\Token\Service\TokenService;
use Codeages\Biz\Framework\Service\BaseService;
use Webpatser\Uuid\Uuid;
class RedisTokenServiceImpl extends BaseService implements TokenService
{
/**
* @var \Redis|\RedisArray
*/
protected $redis;
public function __construct(Biz $biz)
{
parent::__construct($biz);
$pool = isset($this->biz['token_service.redis.pool']) ? $this->biz['token_service.redis.pool'] : null;
if ($pool) {
$this->redis = $this->biz['mult_redis'][$pool];
} else {
$this->redis = $this->biz['redis'];
}
}
public function generate($place, $lifetime, $times = 0, $data = null)
{
$token = array();
$token['place'] = $place;
$token['key'] = str_replace('-', '', Uuid::generate(4));
$token['data'] = $data;
$token['expired_time'] = empty($lifetime) ? 0 : time() + $lifetime;
$token['times'] = $times;
$token['remaining_times'] = $times;
$token['created_time'] = time();
$key = $this->key($place, $token['key']);
$seted = $this->redis->setnx($key, $token);
if (!$seted) {
throw new GenerateException("Generate Token Failed(key:{$token['key']}.");
}
if ($lifetime) {
$this->redis->expire($key, $lifetime);
}
return $token;
}
public function verify($place, $key)
{
$key = $this->key($place, $key);
$token = $this->redis->get($key);
if (empty($token)) {
return false;
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。