andrey-helldar / blacklist-server
v2.2.1
2020-12-30 19:48 UTC
Requires
- php: ^7.1.3|^8.0
- ext-json: *
- andrey-helldar/api-response: ^4.3
- andrey-helldar/blacklist-core: ^2.0
- illuminate/contracts: ^5.6|^6.0|^7.0|^8.0
- illuminate/database: ^5.6|^6.0|^7.0|^8.0
- illuminate/support: ^5.6|^6.0|^7.0|^8.0
- illuminate/validation: ^5.6|^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^3.5|^4.0
- phpunit/phpunit: ^7.0|^8.0
Suggests
- andrey-helldar/blacklist-client: The blacklist client package for connecting to the Blacklist Server
- barryvdh/laravel-cors: Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
README
内容
安装
要获取Laravel Blacklist Server的最新版本,只需使用Composer引入项目
composer require andrey-helldar/blacklist-server
当然,您也可以手动更新require块并运行composer update
来选择更新
{ "require": { "andrey-helldar/blacklist-server": "^2.0" } }
现在,您还可以发布配置文件以更改实现(例如,将接口更改为特定类)
php artisan vendor:publish --provider="Helldar\BlacklistClient\ServiceProvider"
使用
首先查看配置。
安装后,您的应用程序将接受创建和验证停止名单中垃圾邮件发送者的请求。为此,您可以使用andrey-helldar/blacklist-client包,或者直接向地址https://<your-site.com>/api/blacklist
发送POST或GET请求,传递必要的参数
字段 | 必需 | 注释 |
---|---|---|
类型 | 有时 | 可用的字段有:"email","url","ip","phone" |
值 | 是 | 字符串 |
为了使服务器部分能够自行添加或检查垃圾邮件发送者,您可以在其上安装包andrey-helldar/blacklist-client,或者使用更复杂的方法使用外观
use Helldar\BlacklistServer\Facades\Blacklist; return Blacklist::store('foo@example.com', 'email') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('foo@example.com') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('foo@example.com') : bool return Blacklist::store('http://example.com', 'url') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('http://example.com') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('http://example.com') : bool return Blacklist::store('192.168.1.1', 'ip') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('192.168.1.1') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('192.168.1.1') : bool return Blacklist::store('+0 (000) 000-00-00', 'phone') : Helldar\BlacklistServer\Models\Blacklist return Blacklist::check('+0 (000) 000-00-00') // throw Helldar\BlacklistCore\Exceptions\BlacklistDetectedException if exists. return Blacklist::exists('+0 (000) 000-00-00') : bool
但是,我们建议使用客户端。
存储
当向服务器地址https://<your-site>/api/blacklist
发送正确的POST请求时。例如
POST https://<your-site>/api/blacklist
Content-Type: application/json
{
"type": "email",
"value": "foo@example.com"
}
它将返回一个JSON对象
{ "type": "email", "value": "foo@example.com", "expired_at": "2024-05-11 16:41:04", "created_at": "2019-09-14 11:45:04", "updated_at": "2019-09-14 16:41:04" }
如果发送的数据填写不正确,服务器将返回一个错误,错误代码为400,并返回以下JSON对象
{ "error": { "code": 400, "msg": ["<message of the error>"] }, "request": { // incoming data } }
例如
{ "error": { "code": 400, "msg": ["The type must be one of email, url, phone or ip, null given."] }, "request": { "type": "foo", "value": "foo@example.com" } }
存在
如果请求的数据在数据库中找不到,则网站将返回200代码
"ok"
如果请求的数据在数据库中找到,则网站将返回423(锁定)代码
{ "error": { "code": 423, "msg": ["Checked email foo@example.com was found in our database."] }, "request": { "value": "foo@example.com" } }
如果发送的数据填写不正确,服务器将返回一个错误,错误代码为400,并返回以下JSON对象。例如
{ "error": { "code": 400, "msg": ["The value field is required."] }, "request": {} } { "error": { "code": 400, "msg": ["The type must be one of email, url, phone or ip, null given."] }, "request": { "type": "foo", "value": "foo@example.com" } }
许可证
此包是在MIT许可证下发布的。