resolventa / stopforumspam-php-api
StopForumSpam服务的PHP API。有关详细信息,请参阅 https://www.stopforumspam.com。
2.0.0
2022-06-06 07:48 UTC
Requires
- php: >=8.1
- ext-curl: *
- ext-json: *
Requires (Dev)
- fzaninotto/faker: ^1.8
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-09-09 19:34:19 UTC
README
StopForumSpam服务的Composer友好型PHP API库和响应分析器。
要求
- PHP >= 8.1
- cURL扩展
安装
composer require resolventa/stopforumspam-php-api
使用
请参阅 example.php
和 tests/UseCaseTest.php
以获取使用示例。
<?php use Resolventa\StopForumSpamApi\ResponseAnalyzer; use Resolventa\StopForumSpamApi\ResponseAnalyzerSettings; use Resolventa\StopForumSpamApi\StopForumSpamApi; use Resolventa\StopForumSpamApi\Exception\StopForumSpamApiException; include 'vendor/autoload.php'; $stopForumSpamApi = new StopForumSpamApi(); /** * Set up Email, IP and Username to be checked * You can use only one, two or all three together * * Use $stopForumSpamApi->checkIp('135.34.23.33'); if only IP address need to be checked */ $stopForumSpamApi ->checkEmail('test@test-domain.com') ->checkIp('135.34.23.33') ->checkUsername('someGreatUsername'); /** * Get Response from StopForumSpam service */ $response = $stopForumSpamApi->getCheckResponse(); /** * You can analyze response on your own or use Resolventa\StopForumSpamApi\ResponseAnalyzer to make decision * See ResponseAnalyzer usage below */ var_dump($response); /** * Create analyzer instance with $response and default analyser settings * * Or customize analyser settings to your needs * $settings = new ResponseAnalyzerSettings(); * $settings->setMinSpamFlagsCount(2); * $settings->setMinFlagAppearanceFrequency(10); * $settings->setFlagLastSeenDaysAgo(14); * $settings->setConfidenceThreshold(70); */ $analyzer = new ResponseAnalyzer(new ResponseAnalyzerSettings()); try { if($analyzer->isSpammerDetected($response)) { echo "Spam user detected. \n"; } else { echo "User is ok. \n"; } } catch (StopForumSpamApiException $e) { echo 'Bad response: ', $e->getMessage(), "\n"; exit(); }
响应分析器
库包含一个分析器类,用于检查StopForumSpam API响应并判断用户是否为垃圾邮件发送者。
默认分析器设置
请参阅 StopForumSpam API文档 以了解给定的分析器设置。
$confidenceThreshold = 90
如果响应置信度等于或高于$confidenceThreshold
,则用户被检测为垃圾邮件发送者。$minFlagAppearanceFrequency = 5
如果标记(ip、电子邮件、用户名)在垃圾邮件报告中出现的频率低于$minFlagAppearanceFrequency
值,则用户不会被检测为垃圾邮件发送者。$flagLastSeenDaysAgo = 7
如果标记(ip、电子邮件、用户名)上次被报告为垃圾邮件超过$flagLastSeenDaysAgo
天,则用户不会被检测为垃圾邮件发送者。$minSpamFlagsCount = 1
检测到作为垃圾邮件的标记(ip、电子邮件、用户名)的最小数量,以检测用户为垃圾邮件发送者。
分析器使用
// Create analyzer settings with default values $settings = new ResponseAnalyzerSettings(); // Update any setting with your preferable value $settings->setMinSpamFlagsCount(2); $settings->setMinFlagAppearanceFrequency(10); $settings->setFlagLastSeenDaysAgo(14); $settings->setConfidenceThreshold(70); // Start analyzer with given settings $analyzer = new ResponseAnalyzer(new ResponseAnalyzerSettings()); // Validate response with the give analyzer settings if($analyzer->isSpammerDetected($response)) { // Throw away that spam registration }
提交垃圾邮件报告
要提交垃圾邮件报告,您需要获取StopForumSpam API密钥。使用示例请参阅 test/SubmitReportTest.php
// Instantiate StopForumSpamApi with API key $stopForumSpamApi = new StopForumSpamApi(self::API_KEY); // Submit report $result = $stopForumSpamApi->submitSpamReport(string $username, string $ip, string $email, string $evidence);