biologreen/sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

biologreen/sdk

Composer 安装命令:

composer require biologreen/sdk

包简介

The official PHP SDK for the BioLogreen Facial Authentication API.

README 文档

README

The official PHP SDK for the BioLogreen Facial Authentication API.

This SDK provides a modern, robust, and PSR-4 compliant way for PHP developers to integrate face-based signup and login into their backend applications (e.g., Laravel, Symfony, or any Composer-based project).

Features

  • Modern PHP: Uses namespaces, type-hinting, and PSR-4 autoloading.
  • Robust: Built on the industry-standard Guzzle HTTP client.
  • Clean & Object-Oriented: Provides a simple client and immutable Data Transfer Objects (DTOs).
  • Graceful Error Handling: Throws a custom BioLogreenApiException for predictable error management.

Installation

The recommended way to install the SDK is through Composer.

Run the following command in your project's root directory:

composer require biologreen/sdk

This will download the SDK and automatically configure the autoloader in your vendor/autoload.php file.

Usage
Make sure to include Composer's autoloader at the beginning of your PHP script.

Here is a basic example of how to use the client:

PHP

<?php

// 1. Include the Composer autoloader
require_once __DIR__ . '/vendor/autoload.php';

use BioLogreen\Sdk\BioLogreenClient;
use BioLogreen\Sdk\Exception\BioLogreenApiException;

// It is highly recommended to load your API key from environment variables (.env file)
$apiKey = 'YOUR_SECRET_API_KEY';
$localApiUrl = 'http://localhost:8000/v1'; // Use for local testing

// 2. Create a new client instance
$client = new BioLogreenClient($apiKey, $localApiUrl);

try {
    // --- Example: Signing up a new user ---
    echo "Attempting to sign up a new user...\n";
    $signupImagePath = 'path/to/user_signup_image.jpg';
    $customFields = ['plan' => 'premium', 'userId' => 'user-php-123'];
    
    $signupResponse = $client->signupWithFace($signupImagePath, $customFields);

    echo "Signup Successful!\n";
    echo "New User ID: " . $signupResponse->getUserId() . "\n";
    // Using a ternary operator to print a boolean nicely
    echo "Is New User: " . ($signupResponse->isNewUser() ? 'Yes' : 'No') . "\n";
    print_r($signupResponse->getCustomFields());


    // --- Example: Logging in an existing user ---
    echo "\nAttempting to log in the user...\n";
    $loginImagePath = 'path/to/user_login_image.jpg';
    
    $loginResponse = $client->loginWithFace($loginImagePath);

    echo "Login Successful!\n";
    echo "User ID: " . $loginResponse->getUserId() . "\n";

} catch (BioLogreenApiException $e) {
    // Handle specific API errors
    echo "API Error: " . $e->getMessage() . " (Status Code: " . $e->getStatusCode() . ")\n";
} catch (\Exception $e) {
    // Handle other errors (e.g., file not found, network issues)
    echo "An unexpected error occurred: " . $e->getMessage() . "\n";
}
Contributing
Suggestions and contributions are welcome. Please open an issue or a pull request on the GitHub repository to suggest changes.

License

This SDK is licensed under the MIT License with The Commons Clause. See the LICENSE file for more details.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-21