指纹识别/fingerprint-pro-server-api-sdk

Fingerprint Pro Server API提供了验证Fingerprint Pro颁发的访客数据的方式。


README

CI badge CI badge Unit Test Coverage CI badge Latest Stable Version on Packagist PHP Version Require Discord server

Fingerprint Pro Server API PHP SDK

Fingerprint Pro Server API允许您在服务器环境中获取访客信息和单个事件的信息。它可用于数据导出、决策制定和数据分析场景。服务器API旨在服务器端使用,不适合从客户端使用,无论是浏览器还是移动设备。

此PHP包由Swagger Codegen项目自动生成

  • API版本:3
    • 包版本:5.0.0
  • 构建包:io.swagger.codegen.v3.generators.php.PhpClientCodegen

要求

此库支持以下PHP实现

  • PHP 8.1
  • PHP 8.2
  • PHP 8.3

我们目前不支持Bref、ReactPHP等外部PHP运行时

  • Bref
  • ReactPHP

安装与使用

Composer

要通过Composer安装绑定,请将以下内容添加到composer.json

{
    "require": {
        "fingerprint/fingerprint-pro-server-api-sdk": "dev-main"
    }
}

然后运行composer install

或者您可以直接在终端运行此命令

composer require fingerprint/fingerprint-pro-server-api-sdk

入门

请按照安装过程进行,然后运行以下命令

<?php

require_once(__DIR__ . '/vendor/autoload.php');

// Fingerprint Pro Secret API Key
const FPJS_API_SECRET = "Fingerprint Pro Secret API Key";
// A mandatory visitorId of a specific visitor
const FPJS_VISITOR_ID = "visitorId";
// An optional requestId made by a specific visitor
const FPJS_REQUEST_ID = "requestId";

// An optional linkedId of the visit
const FPJS_LINKED_ID = "linkedId";
// An optional parameter limiting scanned results
const LIMIT = 10;
// An optional parameter used to paginate results, see lastTimestamp
const PAGINATION_KEY = "1683900801733.Ogvu1j";

// Import Fingerprint Pro Classes and Guzzle Http Client
use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Configuration;
use Fingerprint\ServerAPI\Model\EventUpdateRequest;
use GuzzleHttp\Client;

// Create a new Configuration instance with your Fingerprint Pro Server API Key and your Fingerprint Pro Server API Region.
/**
 * You can specify a region on getDefaultConfiguration function's second parameter
 * If you leave the second parameter empty, then Configuration::REGION_GLOBAL will be used as a default region
 * Options for regions are:
 * Configuration::REGION_EUROPE
 * Congiruration::REGION_GLOBAL
 * Configuration::REGION_ASIA
 */
$config = Configuration::getDefaultConfiguration(FPJS_API_SECRET, Configuration::REGION_EUROPE);
$client = new FingerprintApi(
    new Client(),
    $config
);

// Get an event with a given requestId
try {
    // Fetch the event with a given requestId
    list($model, $response) = $client->getEvent(FPJS_REQUEST_ID);
    echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->getEvent: ', $e->getMessage(), PHP_EOL;
}

// Get a specific visitor's all visits
try {
    // Fetch all visits with a given visitorId, with a page limit
    list($model, $response) = $client->getVisits(FPJS_VISITOR_ID, null, null, LIMIT);
    echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->getVisits: ', $e->getMessage(), PHP_EOL;
}

// Get a specific visitor's all visits with a linkedId
try {
    // Fetch all visits with a given visitorId, with a page limit, skipping the first visit
    list($model, $response) = $client->getVisits(FPJS_VISITOR_ID, null, FPJS_LINKED_ID, LIMIT, PAGINATION_KEY);
    echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->getVisits: ', $e->getMessage(), PHP_EOL;
}

// Use all the parameters on getVisits
try {
    // Fetch the visitor's all visits with a given requestId and linkedId with a page limit while skipping the first visit
    list($model, $response) = $client->getVisits(FPJS_VISITOR_ID, FPJS_REQUEST_ID, FPJS_LINKED_ID, LIMIT, PAGINATION_KEY);
    echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->getVisits: ', $e->getMessage(), PHP_EOL;
}

// Update Event
try {
    $body = new EventUpdateRequest([
        'linked_id' => 'new linked id',
        'tag' => json_encode(['new_property' => 'new value']),
        'suspect' => true,
    ]);
    list($model, $response) = $client->updateEvent($body, FPJS_REQUEST_ID);
    echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->updateEvent: ', $e->getMessage(), PHP_EOL;
}

// Delete by visitor ID
try {
    list($model, $response) = $client->deleteVisitorData(FPJS_VISITOR_ID);
    echo "<pre>" . $response->__toString() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->deleteVisitorData: ', $e->getMessage(), PHP_EOL;
}

⚠️警告:无法更新10天前的旧事件。

⚠️如果您有兴趣使用deleteVisitorData API,请联系我们的支持团队以启用它。否则,您将收到403错误。

密封结果

此SDK提供了解码密封结果的实用方法。

<?php

use Fingerprint\ServerAPI\Sealed\DecryptionAlgorithm;
use Fingerprint\ServerAPI\Sealed\DecryptionKey;
use Fingerprint\ServerAPI\Sealed\Sealed;

require_once(__DIR__ . '/vendor/autoload.php');

$sealed_result = base64_decode($_ENV['BASE64_SEALED_RESULT']);
$sealed_key = base64_decode($_ENV['BASE64_KEY']);

try {
    $data = Sealed::unsealEventResponse($sealed_result, [new DecryptionKey($sealed_key, DecryptionAlgorithm::AES_256_GCM)]);

    fwrite(STDOUT, sprintf("Unsealed event: %s \n", $data));
} catch (Exception $e) {
    fwrite(STDERR, sprintf("Exception when unsealing event: %s\n", $e->getMessage()));
    exit(1);
}

有关更多信息,请参阅位于sealed_results_example.php中的示例。

API端点文档

所有URI相对于您所在区域的基准URL。

Webhook签名

此SDK提供了验证传入Webhook请求的HMAC签名的实用方法。您可以使用以下代码验证签名

<?php

use Fingerprint\ServerAPI\Webhook\WebhookVerifier;

// Your webhook signing secret.
$webhookSecret = "secret";

// Request data. In real life scenerio this will be the body of incoming request
$webhookData = "data";

// Value of the "fpjs-event-signature" header.
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";

$isValidWebhookSign = WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);

if(!$isValidWebhookSign) {
    fwrite(STDERR, sprintf("Webhook signature verification failed\n"));
    exit(1);
}

端点

模型文档

授权文档

ApiKeyHeader

  • 类型:API密钥
  • API密钥参数名称:Auth-API-Key
  • 位置:HTTP头

ApiKeyQuery

  • 类型:API密钥
  • API密钥参数名称:api_key
  • 位置:URL查询字符串

密封结果文档

Webhook文档

测试

运行单元测试

composer install
./vendor/bin/phpunit

支持

要报告问题、提问或提供反馈,请使用问题。如果您需要私人支持,您可以给我们发送邮件至oss-support@fingerprint.com

许可证

本项目采用MIT许可证