andi / kickbox-bundle
此软件包已被废弃且不再维护。未建议替代软件包。
Symfony Kickbox Bundle
1.1.0
2015-07-07 17:17 UTC
Requires
- guzzlehttp/guzzle: ~6.0
- symfony/framework-bundle: ~2.3
Requires (Dev)
- phake/phake: ~2.0
- phpunit/phpunit: ~4.5
This package is not auto-updated.
Last update: 2020-09-18 20:30:53 UTC
README
Symfony 的电子邮件验证库
Kickbox 确定电子邮件地址不仅有效,而且与实际用户关联。应用场景包括
- 防止用户在您的应用程序上使用虚假、拼写错误或一次性电子邮件地址创建账户。
- 通过从您的邮件列表中删除旧的、无效的和低质量的电子邮件地址来减少退信。
- 通过只向真实电子邮件用户发送邮件来节省金钱并维护您的声誉。
入门
首先,前往 kickbox.io 并创建一个免费账户。注册并登录后,点击 API 设置,然后点击 添加 API 密钥。请注意生成的 API 密钥 - 您需要它来按照以下说明设置客户端。
安装
请确保已安装 composer。
将以下内容添加到您的 composer.json 中
$ php composer.phar require andi/kickbox-bundle
此软件包遵循其类名的
PSR-4规范,这意味着您可以轻松地将这些类集成到自己的自动加载器中。
在 app/AppKernel.php 中注册该软件包
public function registerBundles() { $bundles = array( new Andi\KickBoxBundle\AndiKickBoxBundle(), ); }
在您的 config.yml 中,您必须配置
# Default configuration for extension with alias: "andi_kick_box" andi_kick_box: # API key list. api_keys: # Required toto: # The api key generated in kickbox.io. key: YOU_API_KEY # Required tata: key: AN_OTHER_API_KEY # The default API name. If not set, the default value will be the first api name. default_api_name: tata # The endpoint of the kickbox API. endpoint: 'https://api.kickbox.io/v2/verify'
使用
将以下代码添加到我们的控制器中
public function indexAction($email) { $kickboxClient = $this->get('kickbox_client'); $response = $kickboxClient->verify($email); }
我们还可以通过在 config.yml 中定义的特定键来获取服务名称
示例
$kickboxClient = $this->get('kickbox_client'); // The default client. In our example : tata $kickboxClient = $this->get('kickbox_client.tata'); $kickboxClient = $this->get('kickbox_client.toto');
简单地验证电子邮件
$response = $kickboxClient->verify($email);
带有超时
// Maximum time, in milliseconds, for the API to complete a verification request. Default value : 6000 $response = $kickboxClient->verify($email, 6000);
如果 HTTP 状态码不是 200,API 客户端可能会抛出异常:Andi\KickBoxBundle\Exception\KickBoxApiException
响应
成功的 API 调用将返回以下对象
$response->getBalance(); // The remaining credit balance (Daily + On Demand). $response->getDomain(); // The domain of the provided email address. $response->getEmail(); // Returns a normalized version of the provided email address. $response->getReason(); // The reason for the result. $response->getResponseTime(); // The elapsed time (in milliseconds) it took Kickbox to process the request. $response->getResult(); // The verification result: deliverable, undeliverable, risky, unknown $response->getSuggestion(); // Returns a suggested email if a possible spelling error was detected. $response->getSendex(); // A quality score of the provided email address ranging between 0 (no quality) and 1 (perfect quality). $response->getUser(); // The user (a.k.a local part) of the provided email address. (bob@example.com -> bob). $response->isAcceptAll(); // If the email was accepted, but the domain appears to accept all emails addressed to that domain. $response->isDisposable(); // If the email address uses a disposable domain like trashmail.com or mailinator.com. $response->isFree(); // If the email address uses a free email service like gmail.com or yahoo.com. $response->isRole(); // If the email address is a role address $response->isSuccess(); // If the API request was successful.
所有 Kickbox API 的解释都在这里: 使用 API