tvaliasek / simple-php-akismet
一个简单的类,用于检查评论或联系表单的垃圾邮件与Akismet API
0.1.0
2020-09-06 23:31 UTC
Requires
- php: ^7.4
Requires (Dev)
- guzzlehttp/guzzle: ^7.0
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2024-09-09 16:22:15 UTC
README
非常简单现代的PHP实现Akismet垃圾邮件检查服务。
安装
composer require tvaliasek/simple-php-akismet
使用
use SimpleAkismet\Client; use SimpleAkismet\DataObject\Message; use SimpleAkismet\Exception\AkismetException; use SimpleAkismet\Exception\InvalidKeyException; use SimpleAkismet\Exception\InvalidStatusCodeException; /* * Client covers all four API methods: * verifyKey, checkSpam, submitSpam and submitHam */ $client = new Client( 'yourAkismetApiKey', 'https://www.example.com/', new \GuzzleHttp\Client() ); $message = (new Message()) ->setBlog('https://www.example.com/') ->setCommentAuthorEmail('john@doe.com') ->setCommentContent('Cheap viagra for sale on: www.foo.com') ->setCommentDateGmt(new \DateTime()); // all available fields has their own setter and getter try { if ($client->checkSpam($message)) { // do something with spam message } } catch (AkismetException | InvalidKeyException | InvalidStatusCodeException $e) { // ... }