定制 fingerprint/fingerprint-pro-server-api-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fingerprint/fingerprint-pro-server-api-sdk

Composer 安装命令:

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

包简介

Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mob

README 文档

README

Fingerprint logo

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

Fingerprint Server PHP SDK

Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device.

This PHP package is automatically generated by the OpenAPI Generator project:

  • API version: 4
    • Package version: 7.1.0
  • Build package: org.openapitools.codegen.languages.PhpClientCodegen

Requirements

This library supports the following PHP implementations:

  • PHP 8.2
  • PHP 8.3
  • PHP 8.4

We currently don't support external PHP Runtimes like:

  • Bref
  • ReactPHP

Installation & Usage

Composer

To install the bindings via Composer, add the following to composer.json:

{
    "require": {
        "fingerprint/server-sdk": "^7.1.0"
    }
}

Then run composer install.

Or you can just run this command on your terminal:

composer require fingerprint/server-sdk

Getting Started

Please follow the installation procedure and then run the following:

<?php

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

// Fingerprint Secret API Key
const FP_API_SECRET = "Fingerprint Secret API Key";
// An optional visitorId of a specific visitor
const FP_VISITOR_ID = "visitorId";
// An optional eventId made by a specific visitor
const FP_EVENT_ID = "requestId";

// An optional linkedId of the visit
const FP_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 Server PHP SDK Classes and Guzzle Http Client
use Fingerprint\ServerSdk\Api\FingerprintApi;
use Fingerprint\ServerSdk\Configuration;
use Fingerprint\ServerSdk\Model\EventUpdate;
use GuzzleHttp\Client;

// Create a new Configuration instance with your Fingerprint Server API Key and your Fingerprint Server API Region.
/**
 * You can specify a region on 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 = new Configuration(FP_API_SECRET, Configuration::REGION_EUROPE);
$client = new FingerprintApi(
    $config,
    new Client(), // This is optional. Default: GuzzleHttp\Client
);

// Get an event with a given eventId
try {
    // Fetch the event with a given eventId
    list($event, $response) = $client->getEventWithHttpInfo(FP_EVENT_ID);
    echo "<pre>" . $response->getBody()->getContents() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->getEventWithHttpInfo: ', $e->getMessage(), PHP_EOL;
}

// Search for specific events
try {
    // Search events for given visitor id marked as suspicious and "bad" bot
    list($model, $response) = $client->searchEventsWithHttpInfo(LIMIT, visitor_id: FP_VISITOR_ID, bot: SearchEventsBot::BAD, suspect: true);
    // Use pagination key to get the next page
    // list($model, $response) = $client->searchEventsWithHttpInfo(LIMIT, pagination_key: $model->getPaginationKey(), visitor_id: FP_VISITOR_ID, bot: SearchEventsBot::BAD, suspect: true);
    echo "<pre>" . $response->getBody()->getContents() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->searchEventsWithHttpInfo: ', $e->getMessage(), PHP_EOL;
}

// Update Event
try {
    $body = new EventUpdate([
        'linked_id' => 'new linked id',
        'tags' => ['new_property' => 'new value'],
        'suspect' => true,
    ]);
    list($model, $response) = $client->updateEventWithHttpInfo($body, FP_EVENT_ID);
    echo "<pre>" . $response->getBody()->getContents() . "</pre>";
} catch (Exception $e) {
    echo 'Exception when calling FingerprintApi->updateEventWithHttpInfo: ', $e->getMessage(), PHP_EOL;
}

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

⚠️ Warning It's not possible to update events older than 10 days.

⚠️ If you are interested in using deleteVisitorData API, please contact our support team to enable it for you. Otherwise, you will receive a 403.

Sealed results

This SDK provides utility methods for decoding sealed results.

<?php

use Fingerprint\ServerSdk\Sealed\DecryptionAlgorithm;
use Fingerprint\ServerSdk\Sealed\DecryptionKey;
use Fingerprint\ServerSdk\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);
}

To learn more, refer to example located in sealed_results_example.php.

Documentation for API Endpoints

All URIs are relative to your region's base URL.

Region BasePath
US / Global https://api.fpjs.io/v4
Europe https://eu.api.fpjs.io/v4
Asia https://ap.api.fpjs.io/v4

Webhook Signing

This SDK provides utility method for verifying the HMAC signature of the incoming webhook request. You can use below code to verify signature:

<?php

use Fingerprint\ServerSdk\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);
}

Endpoints

Class Method HTTP request Description
FingerprintApi deleteVisitorData DELETE /visitors/{visitor_id} Delete data by visitor ID
FingerprintApi getEvent GET /events/{event_id} Get an event by event ID
FingerprintApi searchEvents GET /events Search events
FingerprintApi updateEvent PATCH /events/{event_id} Update an event

Documentation for Models

Documentation for Authorization

bearerAuth

  • Type: HTTP basic authentication

Documentation for sealed results

Documentation for webhooks

Tests

To run the unit tests:

composer install
./vendor/bin/phpunit

Support

To report problems, ask questions or provide feedback, please use Issues. If you need private support, you can email us at oss-support@fingerprint.com.

License

This project is licensed under the MIT License.

fingerprint/fingerprint-pro-server-api-sdk 适用场景与选型建议

fingerprint/fingerprint-pro-server-api-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 276.93k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2022 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「browser」 「sdk」 「detection」 「identification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fingerprint/fingerprint-pro-server-api-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fingerprint/fingerprint-pro-server-api-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 fingerprint/fingerprint-pro-server-api-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 276.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 33
  • 点击次数: 50
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 32
  • Watchers: 10
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-01