foxentry/php-api-client

Foxentry.com PHP API 客户端

v2.3.1 2024-08-30 13:54 UTC

This package is auto-updated.

Last update: 2024-08-30 14:00:39 UTC


README

简介

Foxentry PHP API 客户端库允许将各种数据验证功能无缝集成到您的应用程序中。无论您需要验证电话号码、地址、电子邮件或其他数据类型,此库都提供了一个用户友好的界面来与 Foxentry API 交互。有关 Foxentry 的更多信息,请访问 foxentry.com

如果您有问题或需要进一步的帮助,请联系我们 info@foxentry.cz

要求

要使用 Foxentry API 客户端,您需要以下内容

  • Foxentry 账户
  • 使用生成的 API 密钥创建的应用程序项目
  • PHP 版本 7.4 或更高版本

安装

要开始使用 Foxentry PHP API 客户端库,请按照以下安装步骤操作

使用 Composer

  1. 使用 Composer 安装库
composer require foxentry/php-api-client  
  1. 在您的 PHP 脚本中包含 Composer 自动加载器
require_once 'vendor/autoload.php';  

不使用 Composer

  1. 下载库并将其添加到项目中。
  2. 在您的 PHP 脚本中包含文件 vendor/autoload.php
include_once "foxentry-php-client/vendor/autoload.php"

入门

要开始使用 Foxentry PHP API 客户端库,请使用您的 API 密钥创建 API 客户端的实例。此实例允许您访问各种资源(例如电话、位置、电子邮件等),并调用其方法来访问 Foxentry API 的功能。

电子邮件验证的完整示例

// Require the autoloader file to load necessary dependencies from the "vendor" directory.
require "vendor/autoload.php";

// Import the Foxentry\ApiClient class, making it available for use in this script.
use Foxentry\ApiClient;

/*
Create a new instance of the ApiClient class and provide your API key. 
The API key can be generated in the Foxentry administration under Settings > API Keys section. 
*/
$api = new ApiClient();
$api->setAuth("[YOUR API KEY]");

// Set custom parameters for the email validation request.
$response = $api->email()
    ->setCustomId("CustomRequestID") // Sets a custom request ID.
    ->setClientIP("127.0.0.1") // Sets the client IP address.
    ->includeRequestDetails() // Returns the request in API response
    ->setClientCountry("CZ") // Sets the client country code.
    ->setOptions([
        "acceptDisposableEmails" => false // Disables acceptance of disposable emails.
    ])
    ->validate("info@foxentry.cz"); // Sends request to Foxentry API and performs email validation.

// Displays the result of email validation.
echo $response->getResult()->isValid ? "E-mail is Valid" : "E-mail is invalid";

APIClient 类

APIClient 类负责与 API 通信的主要类。

它提供以下方法

要从此类访问各种资源,只需提供资源名称,您就可以访问资源的方法,例如 $api->email()->search($query)$api->company()->get($query) 等。

资源

API 客户端提供各种资源,每个资源都有以下列出的相关方法。您可以通过点击方法导航到 API 文档,在那里您可以探索所有请求输入、选项等。

在每个方法中,您必须根据 API 文档 中的特定端点指定查询参数。

要指定选项,请使用方法 setOptions([])

要指定客户端,请使用方法 setClientIP($ip)setClientCountry($country)setClientLocation($lat, $lon)

响应类

响应类在每次请求后返回,并提供以下方法

测试

该库包括单元测试,以确保其功能并提供如何使用库的示例。您可以使用 PHPUnit 运行单元测试。不要忘记通过创建 phpunit.xml 文件来为这些测试设置您的 API 密钥。