psilocyberunner / stop-forum-spam
stopforumspam.com 网络服务 API 的 PHP 封装器
Requires
- php: ^7.1
- ext-curl: *
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- filp/whoops: ^2.3
- phpstan/phpstan: ^0.11.12
- phpunit/phpunit: ^7.5
- symfony/var-dumper: *
README
作为独立库,封装 https://www.stopforumspam.com/usage 网络服务 API 的 PHP 封装器。
安装
克隆此仓库
git clone git@github.com:psilocyberunner/stop-forum-spam.git
或者通过 composer 需求包
composer require psilocyberunner/stop-forum-spam
使用方法
首先 - 引导应用程序(有关详细信息,请参阅 public/bootstrap.php)
<?php require_once '../vendor/autoload.php'; # Add exception handler, Whoops is a good choice for your experiments $whoops = new \Whoops\Run; $whoops->prependHandler(new \Whoops\Handler\PrettyPageHandler); $whoops->register();
按邮箱搜索
<?php use StopForumSpam\SearchByEmail; require_once 'bootstrap.php'; # --- Search by email address $client = new SearchByEmail('shamrykenkokatya@gmail.com'); $client->asJSON(); $client->withConfidence(); # If you need confidence score /** @var Psr\Http\Message\ResponseInterface $result */ $result = $client->search(); return $result->getBody()->getContents();
示例响应
{ "success": 1, "email": { "lastseen": "2019-03-24 14:19:15", "frequency": 5027, "appears": 1, "confidence": 97.01 } }
按域名搜索
此搜索几乎等同于邮箱搜索,除了它使用敌对域名的通配符列表。没有其他选项可用,仅使用域名列表:https://www.stopforumspam.com/downloads/toxic_domains_whole.txt
<?php use StopForumSpam\SearchByDomain; require_once 'bootstrap.php'; # --- Search by domain $client = new SearchByDomain('kinogomyhit.ru'); $result = $client->search(); return $result->getBody()->getContents();
示例响应
{ "success": 1, "domain": { "appears": 1 } }
对于未找到的域名,您将获得
{ "success": 1, "domain": { "appears": 0 } }
按邮箱哈希搜索
邮箱哈希是电子邮件地址的 plain md5 校验和
<?php use StopForumSpam\SearchByEmailHash; require_once 'bootstrap.php'; # --- Search by email hash (hash is md5 checksum for desired email) $client = new SearchByEmailHash(md5('shamrykenkokatya@gmail.com')); $client->withConfidence(); # If you need confidence score $result = $client->search(); return $result->getBody()->getContents();
示例响应
{ "success": 1, "emailhash": { "lastseen": "2019-03-24 14:19:15", "frequency": 5027, "appears": 1, "confidence": 97.01 } }
按 IP 搜索
<?php use StopForumSpam\SearchByIp; require_once 'bootstrap.php'; # --- Search by ip address $client = new SearchByIp('77.111.247.62'); $client->asJSON(); $client->withConfidence(); # If you need confidence score $result = $client->search(); return $result->getBody()->getContents();
示例响应
{ "success": 1, "ip": { "lastseen": "2018-10-02 11:48:41", "frequency": 8, "appears": 1, "confidence": 0.46, "delegated": "fr", "country": "fr", "asn": 205016 } }
按用户名搜索
<?php use StopForumSpam\SearchByUsername; require_once 'bootstrap.php'; # --- Search by user name $client = new SearchByUsername('Nicole'); $client->asJSON(); $client->withConfidence(); # If you need confidence score $result = $client->search(); return $result->getBody()->getContents();
示例响应
{ "success": 1, "username": { "lastseen": "2019-03-04 02:07:58", "frequency": 12, "appears": 1, "confidence": 3.01 } }
多个搜索参数
<?php use StopForumSpam\SearchMultiple; require_once 'bootstrap.php'; # --- Search multiple targets at once $client = new SearchMultiple([ 'email' => 'test@test.tld', 'ip' => '77.111.247.62', 'username' => 'c0dex', ]); $client->withConfidence(); # If you need confidence score $result = $client->search(); return $result->getBody()->getContents();
示例响应
{ "success": 1, "username": { "frequency": 0, "appears": 0 }, "email": { "frequency": 0, "appears": 0 }, "ip": { "lastseen": "2018-10-02 11:48:41", "frequency": 8, "appears": 1, "confidence": 0.46, "delegated": "fr", "country": "fr", "asn": 205016 } }
按批量数据搜索
如果您想一次性搜索多个 IP、用户名或邮箱,可以使用 SearchByBulk 类。可以构造如下数组,进行最多 15 次任何字段组合的查询。
<?php use StopForumSpam\SearchByBulk; require_once 'bootstrap.php'; # --- Search multiple targets at once $client = new SearchByBulk([ 'ip' => [ '127.0.0.1', '77.111.247.62', ], 'username' => [ 'Nicole', 'some-random-username-for-test', ], 'email' => [ 'shamrykenkokatya@gmail.com', 'some-email@test.tld', ], ]); $client->withConfidence(); # If you need confidence score $result = $client->search(); return $result->getBody()->getContents();
示例响应
{ "success": 1, "ip": [ { "value": "127.0.0.1", "frequency": 0, "appears": 0, "country": "us", "asn": 14618 }, { "value": "77.111.247.62", "lastseen": "2018-10-02 11:48:41", "frequency": 8, "appears": 1, "confidence": 0.34, "delegated": "fr", "country": "us", "asn": 14618 } ], "username": [ { "value": "Nicole", "lastseen": "2019-06-22 01:20:24", "frequency": 14, "appears": 1, "confidence": 11.82 }, { "value": "some-random-username-for-test", "frequency": 0, "appears": 0 } ], "email": [ { "value": "shamrykenkokatya@gmail.com", "lastseen": "2019-06-26 07:25:30", "frequency": 5112, "appears": 1, "confidence": 98.92 }, { "value": "some-email@test.tld", "frequency": 0, "appears": 0 } ] }
提交您的垃圾邮件数据
您需要您的个人 API 令牌来使用此功能。在 https://www.stopforumspam.com/ 注册并获取一个。
<?php use StopForumSpam\SearchMultiple; require_once 'bootstrap.php'; # --- Report spam data $client = new SubmitSpamReport(); $client->setApiToken('token'); $client->setIpAddress('178.159.37.84'); # already listed as spam source $client->setEmail('test@test.com'); $client->setEvidence('evidence'); $client->setUsername('tester'); $result = $client->submit(); return $result->getStatusCode();
对于提交垃圾邮件请求,只有响应代码是成功/失败的指标。没有返回 JSON。
提交请求后,您可以在 https://www.stopforumspam.com/ 网站的特殊部分中查看您所有的垃圾邮件数据,该部分称为 https://www.stopforumspam.com/myspammers。
通配符
SFS 运营一个电子邮件域名、用户名和 IP 地址列表,这些地址被认为是敌对的。您可能希望忽略这些列表,在这种情况下,您需要添加以下 URL 参数
忽略电子邮件/域名列表检查
$client->withNoBadEmail();
忽略用户名(部分字符串)列表检查
$client->withNoBadUsername();
忽略 IP 列表(包括互联网上一些最敌对的垃圾邮件友好网络)
$client->withNoBadIp();
或忽略所有通配符检查
$client->withNoBadAll();
地理访问
API 提供了几个地理位置不同的位置。
api.stopforumspam.org 应该使用,这将使您的查询指向最近的区域服务器,以提供最快的响应。如果您希望将流量限制在特定区域,例如为了遵守公司或国家隐私法规,则可以强制连接到特定区域。
<?php $client = new SearchByEmail('test@email.com'); $client->useEuropeRegion(); # If you want to use Europe region servers
<?php $client = new SearchByIp('127.0.0.1'); $client->useUSRegion(); # If you want to use US region servers
Tor 退出节点
仅在 IP 搜索中可用。已知 Tor 退出节点将包含在所有序列化回复中。如果您想忽略任何已知 Tor 退出节点的列表,请在请求中包含
<?php $client->withNoTorExit();
调用。任何已知为 Tor 退出节点的 IP 地址将返回频率为 0。
{ "success":1, "ip":{ "torexit":1, "frequency":0, "appears":0 } }
一些管理员可能希望 无论其列表如何都阻止已知的 Tor 退出节点。记录为 Tor 退出节点的 IP 地址的结果将返回频率为 255,无论是否列表中。
<?php $client->withBadTorExit();
{ "success":1, "ip":{ "torexit":1, "lastseen":"2016-06-22 17:36:47", "frequency":255, "appears":1 } }
一些有用的方法
方法调用 withConfidence() 将包含响应中关于置信度分数的额外信息
$client->withConfidence();
方法调用 withUnixTimestamp() 将返回数据/时间结果,格式为 UNIXTIME,即自 Unix纪元以来的秒数
$client->withUnixTimestamp();
方法调用 withExpire(10) 提供了当最后访问日期超过指定天数时过滤API结果的能力。
$client->withExpire(10);
方法调用 asJSONP('函数名') 提供了带有JSONP的ajax/jquery支持,允许在JSON结果周围指定一个回调函数。
$client->asJSONP('test');
响应示例
test({
"success":1,
"email":{
"lastseen":"2019-03-24 14:19:15",
"frequency":5027,
"appears":1,
"confidence":97.01
}
})