moay/virus-total-api

非常简单的Laravel 5病毒总API包装器

dev-master 2015-03-25 14:05 UTC

This package is auto-updated.

Last update: 2024-09-29 04:19:59 UTC


README

非常简单的Laravel 5病毒总API包装器。此软件包将病毒总API包装成非常简单的方法,以便您可以非常容易地对URL或文件执行病毒扫描或恶意软件扫描。请注意,公共API有一些限制。请参阅他们的文档:https://www.virustotal.com/documentation/public-api/

安装

安装非常简单。使用Composer要求此软件包

    "require": {
        "moay/virus-total-api": "dev-master"
    }

通过composer update拉取存储库后,您需要将此添加到app/config/app.php中的Laravel提供者(在提供者数组中)

'moay\VirusTotalApi\VirusTotalApiServiceProvider',

为了访问API,您需要一个病毒总API密钥。在他们的网站上获取一个,并发布软件包设置

php artisan vendor:publish

这将发布一个名为virus-total-api的文件到您的app/config目录。在此处插入您的API密钥以使其生效。

用法

用法非常简单。让我们想象一个简单的控制器

<?php namespace app\Http\Controllers;

// Include the alias, else it won't work
use VirusTotal;

class Simplecontroller extends Controller {

	public function example()
	{
		// Let's scan google for malware
		$googleResults = VirusTotal::scanUrl('http://google.de');

		// Let's scan a file for malware
		$fileResults = VirusTotal::scanFile('/my/absolute/filename.txt');

		//Let's scan a file for malware via its URL
		$remoteFileResults = VirusTotal::scanFileViaUrl('http://somecooldomain.com/filename.txt');
	}

}

这就是全部,没有更多的方法要学习。请注意API的访问频率限制。更多关于返回内容的阅读,请参阅https://www.virustotal.com/documentation/public-api/

包装器将在返回的数组中添加一个success变量,以指示API请求是否成功。如果您已超出当前分钟内API配额或未提供有效的API,则将其设置为false。

使用结果

处理返回内容的快速示例。

<?php namespace app\Http\Controllers;

use VirusTotal;

class Simplecontroller extends Controller {

	public function anotherExample()
	{
		// Let's scan google for malware
		$googleResults = VirusTotal::scanUrl('http://google.de');

		if($googleResults['success'])
		{
			// Let's check if there was a virus detected
			if($googleResults['positives']>0)
			{
				// There was a virus - do something about it!
			}
		}
		elseif($googleResults['error'] == 'rate limit exceeded')
		{
			// Reschedule the scan
			...
		}
	}

}