qdenka / safe-browsing
客户端使用谷歌和Yandex安全浏览API(v4)
1.1
2021-03-16 13:42 UTC
Requires
Requires (Dev)
- php-http/mock-client: ^1.4
This package is auto-updated.
Last update: 2024-09-23 17:05:40 UTC
README
客户端使用 谷歌 和 Yandex 安全浏览API(v4)。这个库是基于 bitecodes/safe-browsing 改进和更新的。
要求
-
PHP7+ / PHP8
-
guzzlehttp/guzzle >= v7
安装
通过 composer 安装此库是首选方式。
运行以下命令之一
$ composer require qdenka/safe-browsing
或者将以下内容添加到您的 composer.json
文件的 require
部分:
"saippuakauppias/safe-browsing": "^1.0"
用法
require 'vendor/autoload.php'; use Saippuakauppias\SafeBrowsing\Client as SBClient; use Http\Adapter\Guzzle7\Client as GuzzleClient; // config for Safe Browsing request $config = [ 'api_key' => '0123456789', // see API Keys section 'client_id' => 'ShortClientName', // change to your client name 'client_version' => '1.0.0', // change to your client version ]; // create HTTP Client $guzzle = new GuzzleClient(); // create Safe Browsing Client from HTTP Client and config $sbc = new SBClient($guzzle, $config); // if you need to check urls in Yandex Safe Browsing // uncomment next line (and change API Key of course!): // $sbc->setHost('sba.yandex.net'); // urls array (up to 500) $urls_need_check = [ // yandex safe browsing test urls "https://ydx-phish-shavar.cepera.ru", "https://ydx-malware-driveby-shavar.cepera.ru", // google safe browsing test urls // (see all in: https://testsafebrowsing.appspot.com ) "https://testsafebrowsing.appspot.com/s/phishing.html", "https://testsafebrowsing.appspot.com/s/malware.html", ]; // check urls in SB (execute 'threatMatches:find' request) $result = $sbc->lookup($urls_need_check); // example: result as php array var_dump($result->getContent()); // array(1) { // ["matches"]=> // array(2) { // [0]=> // array(5) { // ["threatType"]=> // string(18) "SOCIAL_ENGINEERING" // ["platformType"]=> // string(12) "ANY_PLATFORM" // ["threat"]=> // array(1) { // ["url"]=> // string(52) "https://testsafebrowsing.appspot.com/s/phishing.html" // } // ["cacheDuration"]=> // string(4) "300s" // ["threatEntryType"]=> // string(3) "URL" // } // [1]=> // array(5) { // ["threatType"]=> // string(7) "MALWARE" // ["platformType"]=> // string(12) "ANY_PLATFORM" // ["threat"]=> // array(1) { // ["url"]=> // string(51) "https://testsafebrowsing.appspot.com/s/malware.html" // } // ["cacheDuration"]=> // string(4) "300s" // ["threatEntryType"]=> // string(3) "URL" // } // } // } // example: show url valid or not one by one foreach($urls_need_check as $test_url) { echo $test_url . ' is valid: ' . (int) $result->isValid($test_url) . PHP_EOL; } // https://ydx-phish-shavar.cepera.ru is valid: 1 // https://ydx-malware-driveby-shavar.cepera.ru is valid: 1 // https://testsafebrowsing.appspot.com/s/phishing.html is valid: 0 // https://testsafebrowsing.appspot.com/s/malware.html is valid: 0
使用Yandex安全浏览
要使用Yandex安全浏览,您必须通过方法更改API密钥并替换基本主机
$sbc->setHost('sba.yandex.net');
API密钥
在这里获取谷歌API密钥 这里.
在这里获取Yandex API密钥 这里.