read js api ticket from file

@return string
@throws \Simple\Filesystem\FileNotFoundException
494965
private function readTicket()
    {
        if (!$this->getFileSystem()->isFile($this->getTicketFilePath())) {
            return '';
        }

        $content = trim($this->getFileSystem()->get($this->getTicketFilePath()));
        $result = unserialize($content);

        if (isset($result['ticket']) && isset($result['expire']) && isset($result['time'])) {
            $expireTime = $result['time'] + $result['expire'] - self::EXPIRE_SUB_TIME;
            if ($expireTime > time()) {
                return $result['ticket'];
            }
        }

        return '';
    }
171505
protected function readFromHttpData()
    {
        // Check validity of the uploaded files
        $aTempFiles = [];
        foreach($_FILES as $sVarName => $aFile)
        {
            if(is_array($aFile['name']))
            {
                $nFileCount = count($aFile['name']);
                for($i = 0; $i < $nFileCount; $i++)
                {
                    if(!$aFile['name'][$i])
                    {
                        continue;
                    }
                    if(!array_key_exists($sVarName, $aTempFiles))
                    {
                        $aTempFiles[$sVarName] = [];
                    }
                    // Filename without the extension
                    $sFilename = $this->filterFilename(pathinfo($aFile['name'][$i], PATHINFO_FILENAME), $sVarName);
                    // Copy the file data into the local array
                    $aTempFiles[$sVarName][] = [
                        'name' => $aFile['name'][$i],
                        'type' => $aFile['type'][$i],
                        'tmp_name' => $aFile['tmp_name'][$i],
                        'error' => $aFile['error'][$i],
                        'size' => $aFile['size'][$i],
                        'filename' => $sFilename,
                        'extension' => pathinfo($aFile['name'][$i], PATHINFO_EXTENSION),
                    ];
                }
            }
            else
            {
                if(!$aFile['name'])
                {
                    continue;
                }
                if(!array_key_exists($sVarName, $aTempFiles))
                {
                    $aTempFiles[$sVarName] = [];
                }
                // Filename without the extension
                $sFilename = $this->filterFilename(pathinfo($aFile['name'], PATHINFO_FILENAME), $sVarName);
                // Copy the file data into the local array
                $aTempFiles[$sVarName][] = [
                    'name' => $aFile['name'],
                    'type' => $aFile['type'],
                    'tmp_name' => $aFile['tmp_name'],
                    'error' => $aFile['error'],
                    'size' => $aFile['size'],
                    'filename' => $sFilename,
                    'extension' => pathinfo($aFile['name'], PATHINFO_EXTENSION),
                ];
            }
        }

        // Check uploaded files validity
        foreach($aTempFiles as $sVarName => $aFiles)
        {
            foreach($aFiles as $aFile)
            {
                // Verify upload result
                if($aFile['error'] != 0)
                {
                    throw new \Jaxon\Exception\Error($this->trans('errors.upload.failed', $aFile));
                }
                // Verify file validity (format, size)
                if(!$this->validateUploadedFile($sVarName, $aFile))
                {
                    throw new \Jaxon\Exception\Error($this->getValidatorMessage());
                }
                // Get the path to the upload dir
                $this->getUploadDir($sVarName);
            }
        }

        // Copy the uploaded files from the temp dir to the user dir
        foreach($aTempFiles as $sVarName => $aTempFiles)
        {
            $this->aUserFiles[$sVarName] = [];
            foreach($aTempFiles as $aFile)
            {
                // Get the path to the upload dir
                $sUploadDir = $this->getUploadDir($sVarName);
                // Set the user file data
                $xUploadedFile = UploadedFile::fromHttpData($sUploadDir, $aFile);
                // All's right, move the file to the user dir.
                move_uploaded_file($aFile["tmp_name"], $xUploadedFile->path());
                $this->aUserFiles[$sVarName][] = $xUploadedFile;
            }
        }
    }
1038166
protected function readFile()
    {
        $file = $this->getFile();
        $raw = $this->ioHelper->getFileContents($file);
        return $this->jsonHelper->decode($raw);
    }
234459
public function actionReadFile()
	{
        $target_path = $this->get['path'];
		$target_fullpath = $this->getFullPath($target_path, true);
        Log::info('reading file "' . $target_fullpath . '"');

        if(is_dir($target_fullpath)) {
            $this->error('FORBIDDEN_ACTION_DIR');
        }

        // check if the name is not in "excluded" list
        if(!$this->is_allowed_name($target_fullpath, false)) {
            $this->error('INVALID_DIRECTORY_OR_FILE');
        }

		$filesize = filesize($target_fullpath);
		$length = $filesize;
		$context = null;

		if(isset($_SERVER['HTTP_RANGE'])) {
			if(!preg_match('/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $matches)) {
				header('HTTP/1.1 416 Requested Range Not Satisfiable');
				header('Content-Range: bytes */' . $filesize);
				exit;
			}

			$offset = intval($matches[1]);

			if(isset($matches[2])) {
				$end = intval($matches[2]);
				if($offset > $end) {
					header('HTTP/1.1 416 Requested Range Not Satisfiable');
					header('Content-Range: bytes */' . $filesize);
					exit;
				}
				$length = $end - $offset;
			} else {
				$length = $filesize - $offset;
			}

			$bytes_start = $offset;
			$bytes_end = $offset + $length - 1;
			$context = stream_context_create([
				's3' => [
					'seekable' => true,
					'Range' => "bytes={$bytes_start}-{$bytes_end}",
				]
			]);

			header('HTTP/1.1 206 Partial Content');
			// A full-length file will indeed be "bytes 0-x/x+1", think of 0-indexed array counts
			header('Content-Range: bytes ' . $bytes_start . '-' . $bytes_end . '/' . $filesize);
			// While playing media by direct link (not via FM) FireFox and IE doesn't allow seeking (rewind) it in player
			// This header can fix this behavior if to put it out of this condition, but it breaks PDF preview
			header('Accept-Ranges: bytes');
		}

		header('Content-Type: ' . $this->getMimeType($target_fullpath));
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: " . $length);
		header('Content-Disposition: inline; filename="' . basename($target_fullpath) . '"');

		readfile($target_fullpath, null, $context);
		exit;
	}
273784
public function fread()
    {
        try {
            $file = $this->openFile('r');
        } catch (\Exception $exc) {
            throw new \RuntimeException('Unable to open file', 0, $exc);
        }

        $result = '';
        foreach ($file as $line) {
            $result .= $line;
        }

        return $result;
    }
675224
protected function readAll()
    {
        try {
            return $this->flysystem->read((string)$this->url);
        } catch (FileNotFoundException $e) {
            throw new ResourceNotFoundException($e->getMessage(), 0, $e);
        }
    }
1313755
public function get()
    {
        $handle   = fopen($this->filePath, "rb");
        $fileSize = filesize($this->filePath);

        $hash = array(
            3 => 0,
            2 => 0,
            1 => ($fileSize >> 16) & 0xFFFF,
            0 => $fileSize & 0xFFFF
        );

        for ($i = 0; $i < 8192; $i++) {
            $tmp  = $this->readUINT64($handle);
            $hash = $this->addUINT64($hash, $tmp);
        }

        $offset = $fileSize - 65536;
        fseek($handle, $offset > 0 ? $offset : 0, SEEK_SET);

        for ($i = 0; $i < 8192; $i++) {
            $tmp  = $this->readUINT64($handle);
            $hash = $this->addUINT64($hash, $tmp);
        }

        fclose($handle);

        return $this->uINT64FormatHex($hash);
    }
977048
public function read()
    {
        $path = $this->getProjectPath() . '/' . $this->getOutputFile();
        if (!is_readable($path)) {
            $this->getContainer()->setValues(null);
            return $this->getContainer();
        }
        $newContainer = unserialize(file_get_contents($path));
        return $newContainer;
    }
815625
public function load() {
        $ext = mb_strtolower(pathinfo($this->_path, PATHINFO_EXTENSION));

        switch ($ext) {
            case 'php':
                return include $this->_path;
            break;
            case 'json':
                return json_decode(file_get_contents($this->_path), true);
            break;
            case 'ini':
                return parse_ini_file($this->_path, true);
            break;
            case 'txt':
                return file($this->_path, FILE_IGNORE_NEW_LINES);
            break;
        }

        throw new UnsupportedTypeException(sprintf('Unsupported FileLoader file type %s', $ext));
    }
1104561
protected function readManifestFile()
    {
        if (file_exists($this->manifest)) {
            return json_decode(
                file_get_contents($this->manifest),
                true
            );
        }

        return false;
    }
1284612
public function get_jsapi_ticket()
    {
        $ticket = false;
        if ($this->get_jsapi_ticket_diy !== false) {
            // 调用用户自定义获取jsapi_ticket方法
            $ticket = call_user_func($this->get_jsapi_ticket_diy);
            if ($ticket) {
                $ticket = json_decode($ticket);
            }
        } else {
            // 异常处理: 获取jsapi_ticket方法未定义
            @error_log('Not set getTicketDiy method, jsapi_ticket will be refreshed each time.', 0);
        }

        // 验证jsapi_ticket是否有效
        if (!$this->valid_jsapi_ticket($ticket)) {

            // 生成新的jsapi_ticket
            $ticket = $this->new_jsapi_ticket();
            if ($ticket === false) {
                return false;
            }

            // 保存新生成的AccessToken
            if ($this->save_jsapi_ticket_diy !== false) {
                // 用户自定义保存AccessToken方法
                call_user_func($this->save_jsapi_ticket_diy, json_encode($ticket));
            } else {
                // 异常处理: 保存access_token方法未定义
                @error_log('Not set saveTokenDiy method, jsapi_ticket will be refreshed each time.', 0);
            }
        }
        return $ticket->ticket;
    }
917319
private static function getFopen()
    {
        if (\count($args = func_get_args()) === 1) {
            $args = $args[0];
        }

        $uri      = $args[0];
        $options  = $args[1] ?? [];
        $callback = $args[2] ?? null;

        if ($callback) {
            $options['fopen']['notification'] = ['self', 'progress'];
        }

        if (isset($options['fopen']['ssl'])) {
            $ssl = $options['fopen']['ssl'];
            unset($options['fopen']['ssl']);

            $stream  = stream_context_create([
                'http' => $options['fopen'],
                'ssl' => $ssl
            ], $options['fopen']);
        } else {
            $stream  = stream_context_create(['http' => $options['fopen']], $options['fopen']);
        }


        $content = @file_get_contents($uri, false, $stream);

        if ($content === false) {
            $code = null;
            // Function file_get_contents() creates local variable $http_response_header, check it
            if (isset($http_response_header)) {
                $code = explode(' ', $http_response_header[0] ?? '')[1] ?? null;
            }

            switch ($code) {
                case '404':
                    throw new \RuntimeException('Page not found');
                case '401':
                    throw new \RuntimeException('Invalid LICENSE');
                default:
                    throw new \RuntimeException("Error while trying to download (code: {$code}): {$uri}\n");
            }
        }

        return $content;
    }
1122525
static function get_jsapi_signature($jsapi_ticket, $nonceStr, $timestamp, $url)
    {
        //排序
        try {
            $str = "jsapi_ticket=$jsapi_ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
            return sha1($str);
        } catch (\Exception $e) {
            @error_log('get_jsapi_signature Error: ' . $e->getMessage(), 0);
            return FALSE;
        }
    }
692934
protected function read()
	{
		if( $this->useCache )
		{
			$fileName	= $this->pathCache.basename( $this->fileName ).".cache";
			if( file_exists( $fileName ) && file_exists( $this->fileName ) && filemtime( $fileName ) == filemtime( $this->pathConfig.$this->fileName ) )
			{
				return $this->readCache( $fileName );
			}
			else
			{
				$this->readWDDX();
				return $this->writeCache( $fileName );
			}
		}
		return $this->readWDDX();

	}
1070480
public function getTicketString()
    {
        $cacheId = $this->getCacheId();

        if ($this->cache && $data = $this->cache->fetch($cacheId)) {
            return $data['ticket'];
        }

        $response = $this->getTicketResponse();

        if ($this->cache) {
            $this->cache->save($cacheId, $response, $response['expires_in']);
        }

        return $response['ticket'];
    }
1059133
public function getContent()
    {
        if ($this->_content === null) {
            if (!$this->canRead()) {
                throw new Exception("Unable to read config file {$this->file}.");
            }
            
            $buffer = $this->getFileContent($this->file);
            $this->_content = $this->jsonDecode($buffer);
        }
        
        return $this->_content;
    }
84557
protected function read()
    {
        $contents = $this->filesystem()->get($this->path);
        $data     = json_decode($contents, true);

        if (is_null($data)) {
            throw new RuntimeException("Invalid JSON file in [{$this->path}]");
        }

        return (array) $data;
    }