src/Biz/User/Service/Impl/TokenServiceImpl.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Biz\User\Service\Impl;

use Biz\BaseService;
use Biz\User\Service\TokenService;
use Rhumsaa\Uuid\Uuid;

class TokenServiceImpl extends BaseService implements TokenService
{
    public function makeToken($type, array $args = array())
    {
        $token = array();
        $token['type'] = $type;
        $token['token'] = $this->_makeTokenValue();
        $token['data'] = !isset($args['data']) ? '' : $args['data'];
        $token['times'] = empty($args['times']) ? 0 : (int) $args['times'];
        $token['remainedTimes'] = $token['times'];
        $token['userId'] = empty($args['userId']) ? 0 : $args['userId'];
        $token['expiredTime'] = empty($args['duration']) ? 0 : time() + $args['duration'];
        $token['createdTime'] = time();

        return $this->getTokenDao()->create($token);
    }

    //length 被多处调用,length参数可认为是无效,插件等外部调用清除后,去掉length参数
    public function makeFakeTokenString($length = 32)
    {
        return $this->_makeTokenValue();
    }

    public function verifyToken($type, $value, array $data = array())
    {
        $token = $this->getTokenDao()->getByToken($value);

        if (empty($token)) {
            return false;
        }

        if ($token['type'] != $type) {
            return false;
        }

        if (($token['expiredTime'] > 0) && ($token['expiredTime'] < time())) {
            return false;
        }

        if ($token['remainedTimes'] > 1) {
            $this->getTokenDao()->wave(array($token['id']), array('remainedTimes' => -1));
        }

        if (!empty($data)) {
            $token = $this->getTokenDao()->update($token['id'], array('data' => $data));
        }

        $this->_gcToken($token);

        return $token;
    }

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。