de.sr.secntfy/secntfy-php

PHP port of the SecNtfy C# library

Maintainers

Package info

github.com/SecNtfy/SecNtfy-PHP

pkg:composer/de.sr.secntfy/secntfy-php

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2025-11-07 12:29 UTC

This package is auto-updated.

Last update: 2026-03-07 13:22:19 UTC


README

PHP License

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