de.sr.secntfy / secntfy-php
PHP port of the SecNtfy C# library
1.0.1
2025-11-07 12:29 UTC
Requires
- php: >=8.2
- ext-curl: *
- ext-openssl: *
Requires (Dev)
- phpunit/phpunit: ^11.0
README
SecNtfy-PHP is the official PHP port of the original [SecNtfy C# library](https://github.com/SecNtfy/SecNtfy-Nuget) (currently Private).
It provides secure, end-to-end encrypted notifications via the SecNtfy API,
including RSA encryption, critical alerts, sound options, and message priority support.
β¨ Features
- π RSA encryption (OpenSSL, fully compatible with the C# version)
- π Simple JSON API powered by cURL
- β‘ Pure PHP 8.2+, no external dependencies
- π§© Composer-ready (PSR-4 autoloading)
- β Includes example and optional PHPUnit tests
π¦ Installation
Requirements
- PHP β₯ 8.2
- PHP extensions:
openssl,curl - Composer installed
Install via Composer
composer require de.sr.secntfy/secntfy-php
Autoloading
Include Composerβs autoloader in your project entrypoint:
require __DIR__ . '/vendor/autoload.php';
π Quick Example
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use SecNtfyPHP\\SecNtfy; $secNtfy = new SecNtfy(); // or new SecNtfy('https://api.secntfy.app') try { $res = $secNtfy->sendNotification( 'NTFY-DEVICE-ABCDEFG123456...', 'Test message', 'This is a test body from SecNtfy-PHP', false, '', // optional image URL 0 // priority ); echo "Encrypted title: {$secNtfy->encTitle}\\n"; if ($res === null) { echo "No public key received or device lookup failed.\\n"; } else { echo "Status: {$res->Status}\\n"; echo "Message: {$res->Message}\\n"; echo "Error: {$res->Error}\\n"; } } catch (Throwable $e) { echo "Error: {$e->getMessage()}\\n"; echo $e->getTraceAsString() . "\\n"; }
π§ͺ Running Locally
Example script
composer install php examples/test.php
Optional unit tests
If you have PHPUnit installed or added as a dev dependency:
composer test # or vendor/bin/phpunit
π§± Project Structure
SecNtfy-PHP/
βββ src/
β βββ SecNtfy.php # Main client logic (HTTP + encryption)
β βββ MsgCrypto.php # RSA encryption handling
β βββ SecNtfyModel.php # Data models and response classes
βββ examples/
β βββ test.php # Example usage
βββ tests/ # Optional PHPUnit tests
βββ composer.json
βββ phpunit.xml
βββ LICENSE
π§ Troubleshooting
| Issue | Possible Cause |
|---|---|
Response is null or empty! |
Invalid device token or missing public key |
RSA encryption failed |
The public key is invalid or not Base64-encoded |
curl_exec() returns false |
Network issue or incorrect API URL |
π€ Contributing
Pull requests and issues are welcome!
Please follow the PSR-12 coding style
and include unit tests when adding new features.
π License
Released under the MIT License.
Β© 2025 androidseb25 β SecNtfy-PHP