tweekersnut/license-sdk 问题修复 & 功能扩展

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

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

tweekersnut/license-sdk

Composer 安装命令:

composer require tweekersnut/license-sdk

包简介

Official PHP SDK for TweekersNut License Management System

README 文档

README

Official PHP SDK for integrating TweekersNut License Management System into your applications.

Latest Version PHP Version License

Features

  • 🔐 License Activation - Activate licenses with hardware binding
  • License Validation - Online and offline validation with caching
  • 🎯 Feature Gating - Control features based on license type
  • 💻 Hardware Fingerprinting - Bind licenses to specific machines (excludes USB/removable storage)
  • Smart Caching - Automatic caching to reduce server load
  • 🛡️ Exception Handling - Proper error handling with custom exceptions
  • 🌐 Cross-Platform - Works on Windows, Linux, and macOS

Installation

Install via Composer:

composer require tweekersnut/license-sdk

Quick Start

1. Initialize the Client

<?php
require 'vendor/autoload.php';

use TweekersNut\LicenseSDK\LicenseClient;

$license = new LicenseClient(
    'https://license.yourdomain.com',  // Your license server URL
    file_get_contents('public.pem'),    // Public key for verification
    'license.tnlic'                     // License file path (optional)
);

2. Activate a License

try {
    $result = $license->activate('TNPRO-XXXXX-XXXXX-XXXXX-XXXXX');
    echo "License activated successfully!\n";
} catch (\TweekersNut\LicenseSDK\Exceptions\LicenseException $e) {
    echo "Activation failed: " . $e->getMessage() . "\n";
}

3. Validate License

try {
    $result = $license->validate(true); // true = online validation
    
    if ($result['valid']) {
        echo "License is valid!\n";
        // Your application code here
    } else {
        echo "License invalid: " . $result['reason'] . "\n";
    }
} catch (\TweekersNut\LicenseSDK\Exceptions\ValidationException $e) {
    echo "Validation error: " . $e->getMessage() . "\n";
}

4. Check Features

if ($license->hasFeature('premium')) {
    // Show premium features
    echo "Premium features enabled!\n";
} else {
    // Show basic features only
    echo "Upgrade to unlock premium features\n";
}

// Get all enabled features
$features = $license->getFeatures();
print_r($features);

Complete Example

<?php
require 'vendor/autoload.php';

use TweekersNut\LicenseSDK\LicenseClient;
use TweekersNut\LicenseSDK\Exceptions\LicenseException;

// Initialize
$license = new LicenseClient(
    'https://license.yourdomain.com',
    file_get_contents('public.pem'),
    'license.tnlic'
);

// Check if already activated
if (!$license->isActivated()) {
    // Show activation form
    echo "Please enter your license key: ";
    $licenseKey = trim(fgets(STDIN));
    
    try {
        $license->activate($licenseKey);
        echo "✓ License activated successfully!\n";
    } catch (LicenseException $e) {
        die("✗ Activation failed: " . $e->getMessage() . "\n");
    }
}

// Validate license
try {
    $result = $license->validate(true);
    
    if ($result['valid']) {
        echo "✓ License is valid\n";
        
        // Check features
        if ($license->hasFeature('api_access')) {
            echo "✓ API access enabled\n";
        }
        
        if ($license->hasFeature('premium')) {
            echo "✓ Premium features enabled\n";
        }
        
        // Your application logic here
        runApplication();
        
    } else {
        die("✗ License invalid: " . $result['reason'] . "\n");
    }
} catch (LicenseException $e) {
    die("✗ Validation error: " . $e->getMessage() . "\n");
}

function runApplication() {
    echo "\n🚀 Application is running...\n";
    // Your application code here
}

API Reference

LicenseClient

Constructor

public function __construct(
    string $serverUrl,
    string $publicKey,
    ?string $licenseFile = null
)
  • $serverUrl - License server URL (e.g., https://license.yourdomain.com)
  • $publicKey - Public key in PEM format for signature verification
  • $licenseFile - Optional path to store license file

Methods

activate(string $licenseKey): array

Activate a license with the provided license key.

Returns: ['success' => true, 'message' => '...']

Throws: LicenseException on failure

validate(bool $online = true): array

Validate the current license.

Parameters:

  • $online - true for online validation, false for offline

Returns: ['valid' => true, 'license_key' => '...', 'features' => [...]]

Throws: ValidationException if no license is activated

hasFeature(string $featureName): bool

Check if a specific feature is enabled.

Returns: true if feature is enabled, false otherwise

getFeatures(): array

Get all enabled features.

Returns: Array of feature names

deactivate(): array

Deactivate the current license.

Returns: ['success' => true, 'message' => '...']

Throws: LicenseException on failure

isActivated(): bool

Check if a license is currently activated.

Returns: true if activated, false otherwise

getLicenseInfo(): ?array

Get current license information.

Returns: License data array or null if not activated

Integration Examples

WordPress Plugin

class MyPremiumPlugin {
    private $license;
    
    public function __construct() {
        $this->license = new LicenseClient(
            'https://license.yourdomain.com',
            file_get_contents(plugin_dir_path(__FILE__) . 'public.pem'),
            plugin_dir_path(__FILE__) . 'license.tnlic'
        );
        
        add_action('admin_init', [$this, 'check_license']);
    }
    
    public function check_license() {
        if (!$this->license->isActivated()) {
            add_action('admin_notices', function() {
                echo '<div class="error"><p>Please activate your license</p></div>';
            });
            return;
        }
        
        try {
            $result = $this->license->validate();
            if (!$result['valid']) {
                add_action('admin_notices', function() use ($result) {
                    echo '<div class="error"><p>License error: ' . $result['reason'] . '</p></div>';
                });
            }
        } catch (Exception $e) {
            // Handle error
        }
    }
}

Laravel Application

// In a Service Provider
public function boot() {
    $license = new LicenseClient(
        config('license.server_url'),
        file_get_contents(storage_path('app/public.pem')),
        storage_path('app/license.tnlic')
    );
    
    $this->app->instance('license', $license);
}

// In a Middleware
public function handle($request, Closure $next) {
    $license = app('license');
    
    if (!$license->isActivated()) {
        return redirect()->route('license.activate');
    }
    
    try {
        $result = $license->validate();
        if (!$result['valid']) {
            return response()->json(['error' => 'Invalid license'], 403);
        }
    } catch (Exception $e) {
        return response()->json(['error' => 'License error'], 500);
    }
    
    return $next($request);
}

Standalone Application

// bootstrap.php
require 'vendor/autoload.php';

$license = new LicenseClient(
    getenv('LICENSE_SERVER_URL'),
    file_get_contents(__DIR__ . '/public.pem'),
    __DIR__ . '/license.tnlic'
);

// Validate on startup
if (!$license->isActivated() || !$license->validate()['valid']) {
    die("License required. Please activate your license.\n");
}

// Continue with application

Hardware Fingerprinting

The SDK automatically collects hardware information for license binding:

  • CPU ID - Processor serial number
  • System Disk Serial - Primary disk only (excludes USB/external drives)
  • MAC Address - Primary network adapter
  • Motherboard Serial - Motherboard identifier
  • OS Information - Operating system type and version

Important: The SDK only fingerprints permanent hardware. USB drives, external storage, and removable media are excluded to prevent false hardware change detections.

Caching

The SDK automatically caches validation results for 15 minutes to reduce server load and improve performance. Cache is stored in the system temp directory by default.

Error Handling

The SDK provides specific exceptions for different error types:

use TweekersNut\LicenseSDK\Exceptions\LicenseException;
use TweekersNut\LicenseSDK\Exceptions\ValidationException;
use TweekersNut\LicenseSDK\Exceptions\NetworkException;

try {
    $license->activate($key);
} catch (NetworkException $e) {
    // Network/connectivity issues
    echo "Network error: " . $e->getMessage();
} catch (ValidationException $e) {
    // Validation-specific errors
    echo "Validation error: " . $e->getMessage();
} catch (LicenseException $e) {
    // General license errors
    echo "License error: " . $e->getMessage();
}

Requirements

  • PHP 8.0 or higher
  • cURL extension
  • JSON extension
  • OpenSSL extension

Support

License

MIT License. See LICENSE file for details.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Made with ❤️ by TweekersNut Network

tweekersnut/license-sdk 适用场景与选型建议

tweekersnut/license-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 tweekersnut/license-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-19