Search by

kolaysms / kolaysms-php

tapsin

PHP client for the KolaySMS API: send SMS, parse ID: message ids, optional OTP helper, and a Laravel notification channel.

v1.0.0 2026-12-05 19:14 UTC

This package is auto-updated.

Last update: 2026-12-05 20:56:47 UTC


README

KolaySMS SMS API’si için PHP istemcisi. Sert bir çatı bağımlılığı yoktur, PHP 7.4+ hedefler ve isteğe bağlı olarak Laravel ile bütünleşir.

A PHP client for the KolaySMS SMS API. It has no hard framework dependency, targets PHP 7.4+, and optionally integrates with Laravel.

Bir KolaySMS hesabı ve API anahtarı gerekir. Bu kütüphane WordPress.org, Automattic veya Laravel LLC ile bağlı değildir.

A KolaySMS account and API token are required. This library is not affiliated with WordPress.org, Automattic, or Laravel LLC.

Varsayılan lisans MIT’tir.

Türkçe

Nedir?

KolaySms\Client ile SMS gönderir, Türk cep numaralarını normelleştirir, başarıyı ID: satırından okur ve isteğe bağlı bir OTP yardımcısı sunar.

Özellikler

  • https://kolaysms.com.tr/api/send adresine token, numara, mesaj gönderimi
  • 0532…, +90, 0090…, 532… → 905XXXXXXXXX (sabit hat ve yabancı numaralar reddedilir)
  • Başarı: HTTP 2xx ve ID:<ileti kimliği>. Anahtar sonuçlarda veya istisnalarda dönmez
  • ASCII kipi varsayılan olarak açık (Çiğ → Cig). KolaySMS UTF-8 kabul eder; teslimat operatöre bağlı olabilir
  • cURL taşıması veya TransportInterface / PSR-18
  • OTP: HMAC-SHA256, hash_equals, düz metin kod saklanmaz / döndürülmez
  • Laravel servis sağlayıcı, cephe ve bildirim kanalı (kolaysms)

Gereksinimler

  • PHP 7.4+
  • Yerleşik taşıma için ext-curl veya bir PSR-18 istemci

Kurulum

composer require kolaysms/kolaysms-php

Paket Packagist’e yayınlanana kadar bu GitHub deposunu VCS veya path olarak ekleyin.

Yapılandırma ve kullanım

use KolaySms\Client;
use KolaySms\Exception\KolaySmsException;

$client = new Client(getenv('KOLAYSMS_TOKEN'));
// UTF-8 göndermek için: new Client($token, ['ascii_mode' => false]);

try {
    $result = $client->send('0532 123 45 67', 'Merhaba Dünya');
    if ($result->isSuccess()) {
        echo $result->getMessageId();
    } else {
        echo $result->getErrorCode() . ': ' . $result->getBody();
    }
    $result->throwOnFailure();
} catch (KolaySmsException $e) {
    // geçersiz telefon, boş ileti, eksik anahtar, iletişim veya API hatası
}

OTP yardımcısı:

use KolaySms\Otp\MemoryStorage; // veya Psr16Storage($psr16Cache)
use KolaySms\Otp\OtpService;

$otp = new OtpService($client, new MemoryStorage(), [
    'secret' => getenv('KOLAYSMS_OTP_SECRET'), // HMAC anahtarı
    'expiry' => 300,
    'cooldown' => 60,
    'max_sends' => 5,
    'max_attempts' => 5,
]);
$otp->sendCode('0532 123 45 67', 'login', $sessionId);
$check = $otp->verifyCode('0532 123 45 67', 'login', $userInput, $sessionId);

Laravel: php artisan vendor:publish --tag=kolaysms-config, sonra .env içinde KOLAYSMS_TOKEN (isteğe bağlı KOLAYSMS_ASCII_MODE, KOLAYSMS_OTP_SECRET). KolaySms::send('0532…', 'Merhaba'). Bildirim kanalı adı kolaysms şeklindedir; toKolaySms() bir dizge, dizi veya KolaySmsMessage döndürebilir.

Durum / Status

Sürüm 1.0.0. Bu ortamda (PHP 8.4.28, Europe/Istanbul) PHPUnit 43 test / 106 iddia, PHPStan düzey 6 (Laravel hariç src) ve PHPCS PSR-12 temizdir. Laravel duman testleri 11.57.2, 12.75.0 ve 13.45.0 üzerinde taklit HTTP ile geçti. Laravel 8–10 bu PHP sürümünde çalıştırılmadı. Paket Packagist’e yayınlanmadı. Gerçek SMS gönderimi test edilmedi.

Lisans

MIT. LICENSE dosyasına bakın.

English

What it is

A typed PHP client for KolaySMS: send SMS, normalise Turkish mobiles, parse ID: success, and optionally issue hashed OTPs. Laravel 8–12 APIs are supported; see Status for which versions were executed.

Features

  • POST token, numara, mesaj to https://kolaysms.com.tr/api/send
  • Phone normalisation to 905XXXXXXXXX; landlines and foreign numbers are rejected
  • Success only when the HTTP status is 2xx and the body contains ID:<message id> (a non-2xx response is a failure even if the body contains ID:)
  • The API token is never returned in results or exception messages
  • ASCII mode on by default. KolaySMS accepts UTF-8, but some operators may not deliver Turkish characters
  • Built-in cURL transport, or inject TransportInterface / Psr18Transport
  • OTP helper with HMAC-SHA256 and hash_equals; plaintext codes are never stored or returned
  • Optional Laravel provider, facade and kolaysms notification channel

Requirements

  • PHP 7.4 or later
  • ext-curl for the built-in transport, or a PSR-18 client

Installation

composer require kolaysms/kolaysms-php

Until the package is on Packagist, require this GitHub repository as a VCS or path repository.

Configuration and usage

See the PHP examples in the Turkish section above (the same API). Set KOLAYSMS_TOKEN in Laravel’s .env. Publish config with php artisan vendor:publish --tag=kolaysms-config. Bind KolaySms\Http\TransportInterface in tests if you need to swap the HTTP layer.

Durum / Status

Version 1.0.0. In this workspace (PHP 8.4.28, Europe/Istanbul): PHPUnit 43 tests / 106 assertions, PHPStan level 6 on src excluding Laravel, and PHPCS PSR-12 were clean. Laravel smoke tests passed on 11.57.2, 12.75.0 and 13.45.0 with mocked HTTP. Laravel 8–10 were not run here because this PHP runtime is newer than those versions officially support. The package has not been published to Packagist. Real SMS sending was not tested.

License

MIT. See LICENSE.

Development: composer install, then vendor/bin/phpunit, vendor/bin/phpstan analyse, vendor/bin/phpcs. Do not send real SMS from tests.

💝 Destekle / Support

Eğer bu proje sana yararlı olduysa, lütfen destekle: