caiyun / license-client
Caiyun commercial license client for Laravel
Requires
- php: ^8.3
- ext-json: *
- ext-openssl: *
- illuminate/console: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/routing: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- nesbot/carbon: ^3.0
- symfony/http-foundation: ^7.2|^8.0
- symfony/http-kernel: ^7.2|^8.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel 商业授权客户端,支持 RSA 签名许可证、授权时间、域名绑定、功能权益、远程撤销和离线宽限。
安装
在业务项目的 composer.json 配置私有仓库:
{
"repositories": [
{"type": "vcs", "url": "git@github.com:763606865/caiyun-license-client.git"}
]
}
composer require caiyun/license-client:^1.0 php artisan vendor:publish --tag=caiyun-license-config
Laravel 会通过 Composer 自动发现 LicenseServiceProvider,自动注册 licensed、feature 中间件和 license:status 命令。默认将基础授权中间件加入 web 和 api 组。
配置
LICENSE_ENABLED=true LICENSE_GLOBAL_MIDDLEWARE=true LICENSE_TOKEN=<signed-license> LICENSE_PUBLIC_KEY_PATH=storage/app/license/public.pem LICENSE_VERIFY_DOMAIN=true LICENSE_REMOTE_ENABLED=true LICENSE_REMOTE_ENDPOINT=https://license.example.com/openapi/v1/leases/valid LICENSE_OPENAPI_CLIENT_ID=opk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx LICENSE_OPENAPI_CLIENT_SECRET=<secret-issued-by-license-server> LICENSE_PROJECT=cms LICENSE_REMOTE_CHECK_INTERVAL=60 LICENSE_OFFLINE_GRACE_HOURS=72 LICENSE_HEARTBEAT_SCHEDULE_ENABLED=true LICENSE_HEARTBEAT_SCHEDULE_AT=01:00
公钥放入 storage/app/license/public.pem,私钥只能保留在授权服务器。也可用 LICENSE_PUBLIC_KEY 传入 Base64 编码的 PEM 公钥。
php artisan license:status --domain=example.com php artisan license:verify --domain=example.com
启用远程授权后,包会默认每天 01:00 调度 license:verify 主动上报心跳。服务器仍需正常运行 Laravel Scheduler:
* * * * * cd /path/to/current && php artisan schedule:run >> /dev/null 2>&1
功能授权
Route::middleware('feature:payment')->group(function (): void { Route::post('/orders/{order}/pay', PayController::class); });
模块内部也应进行权益检查,避免只删除路由中间件即可绕过:
use Caiyun\License\LicenseManager; app(LicenseManager::class)->authorize('payment', request()->getHost());
新功能在发布包前加入 config/license.php 的 features。
远程租约协议
客户端会使用 OpenAPI Client Secret 对请求自动执行 AES-256-GCM 加密和 HMAC-SHA256 签名。加密前的业务数据为:
{
"license": "<signed-license>",
"license_id": "LIC-2026-0001",
"instance_id": "stable UUID",
"domain": "example.com",
"project": "cms",
"app_version": null
}
调用方不需要自行构造加密信封;请妥善保管 LICENSE_OPENAPI_CLIENT_SECRET,不要将其放入浏览器或移动端代码。
授权服务器返回 {"lease":"<signed-lease>"}。租约 Payload 必须包含:
{
"license_id": "LIC-2026-0001",
"instance_id": "stable UUID",
"domain": "example.com",
"issued_at": "2026-08-04T12:00:00+08:00",
"expires_at": "2026-08-07T12:00:00+08:00",
"features": ["payment", "mobile", "ai"]
}
租约使用同一 RSA 私钥签名,有效时间不得超过 LICENSE_OFFLINE_GRACE_HOURS。撤销返回 HTTP 403:
{"reason":"revoked","message":"授权已撤销"}
开发
composer install composer check
PHP 要求 >= 8.3,支持 Laravel 12 和 Laravel 13。
License
Proprietary. 未经授权不得复制、修改、再分发或绕过许可验证。