andrey-helldar/blacklist-client

此包已被废弃且不再维护。作者建议使用 johannebert/laravel-spam-protector 包代替。

用于连接黑名单服务器的黑名单客户端包

v2.2.1 2020-12-30 19:48 UTC

README

用于连接黑名单服务器的黑名单客户端包。

blacklist client

StyleCI Total Downloads Latest Stable Version Latest Unstable Version License

内容

安装

要获取 Laravel Blacklist Client 的最新版本,只需使用 Composer 依赖项目

composer require andrey-helldar/blacklist-client

当然,您也可以手动更新 require 块并运行 composer update,如果这样选择的话

{
    "require": {
        "andrey-helldar/blacklist-client": "^2.0"
    }
}

现在,您还可以发布配置文件以更改实现(例如,将接口更改为特定类)

php artisan vendor:publish --provider="Helldar\BlacklistClient\ServiceProvider"

使用

首先查看 配置

检查 / 存在

要检查数据库中是否存在垃圾邮件发送者,需要传递数据类型和值

/*
 * DATABASE
 * foo@example.com - exists
 * bar@example.com - not exists
 */

use Helldar\BlacklistClient\Facades\Client;

return Client::check('http://example.com'); // false
return Client::check('192.168.1.1'); // false
return Client::check('+0 (000) 000-00-00'); // false

return Client::check('foo@example.com');
/* GuzzleHttp\Exception\ClientException with 423 code and content:
 *
 * {"error":{"code":400,"msg":["Checked foo@example.com was found in our database.]}}
 */

例如

use GuzzleHttp\Exception\ClientException;
use Helldar\BlacklistClient\Facades\Client;

class Foo
{
    public function store(array $data)
    {
        if (! $this->isSpammer($data['email'])) {
            // storing data
        }
    }

    private function isSpammer(string $value): bool
    {
        try {
            return Client::check($value);
        }
        catch (ClientException $exception) {
            return true;
        }
    }
}

存储

要将垃圾邮件发送者存储到数据库中,请使用 facade 的 Clientstore 方法

use Helldar\BlacklistClient\Facades\Client;

return Client::store('foo@example.com', 'email');
return Client::store('http://example.com', 'url');
return Client::store('192.168.1.1', 'ip');
return Client::store('+0 (000) 000-00-00', 'phone');

例如

use Helldar\BlacklistClient\Facades\Client;

$item = Client::store('foo@example.com', 'email');

return $item->expired_at; // 2019-09-27 23:25:27

许可证

此包按照 MIT 许可证 发布。