PHPackages                             imamrasyid/php-ayosms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. imamrasyid/php-ayosms

ActiveLibrary

imamrasyid/php-ayosms
=====================

Unofficial PHP SDK for AYOSMS! Gateway – a lightweight, modern, and developer-friendly wrapper for AYOSMS HTTP APIs (SMS, Balance, HLR, OTP verification). This project is independent and NOT affiliated with, endorsed by, or sponsored by AYOSMS or PT Ayomobile Media International.

v1.1(6mo ago)00MITPHPPHP &gt;=7.4

Since Oct 16Pushed 6mo agoCompare

[ Source](https://github.com/imamrasyid/php-ayosms)[ Packagist](https://packagist.org/packages/imamrasyid/php-ayosms)[ Docs](https://github.com/imamrasyid/php-ayosms)[ RSS](/packages/imamrasyid-php-ayosms/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Ayosms PHP SDK v1.0
===================

[](#ayosms-php-sdk-v10)

[![PHP Version](https://camo.githubusercontent.com/6eff5053a32c9e0bcc0982c4f118ef689cad7831a3d982767aae3901bf67313c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344372e342d626c75652e737667)](https://www.php.net/)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](./LICENSE)[![Build](https://camo.githubusercontent.com/1aaf4451a9bd7f8a9315378706cbc3f79115562bab3c7a880a0fb8a45842ed05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d737563636573732e737667)](#)[![Packagist](https://camo.githubusercontent.com/ba742bc76edf63ad9df730328a727562387d35aae48aa844f1c26ca0f9a4b0c9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5061636b61676973742d696d616d7261737969642532467068702d2d61796f736d732d6f72616e67652e737667)](#)[![CodeIgniter Compatible](https://camo.githubusercontent.com/01a6925f54860c8bf6a8382776a3a2c484b8b42495722351cd13986593e9bd65/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f646549676e697465722d33253246342d7265642e737667)](#)

A modern, production-ready **PHP SDK** for [AYOSMS! Global SMS Gateway](https://ayosms.com/api/), fully aligned with their official API documentation.

> ⚙️ Designed for developers who want reliable SMS, OTP, and HLR integration within PHP applications — including CodeIgniter, Laravel, or pure PHP environments.

---

🚀 Features
----------

[](#-features)

✅ **Complete API Coverage**

- `sendSMS()` — Send single or bulk SMS
- `checkBalance()` — Retrieve account balance
- `sendHLR()` — Perform HLR lookups
- `otpRequest()` — Request OTP delivery via SMS
- `otpCheck()` — Verify received OTP

✅ **Robust Error Handling**

- Handles network, HTTP, and JSON parsing errors
- Detects invalid parameters and malformed requests
- Maps AYOSMS official error codes (`ERR001–ERR999`)

✅ **Professional PHPDoc**

- Full type-hinting for modern IDEs (PhpStorm, VSCode, etc.)
- Inline documentation for every parameter and return type

✅ **Secure &amp; Standards-Compliant**

- Uses HTTPS with `CURLOPT_SSL_VERIFYPEER`
- Sanitizes and validates all inputs before request
- Compatible with PHP 7.4 – 8.3

✅ **CodeIgniter Ready**

- Drop directly into `application/libraries/Ayosms.php`
- Optional config file `application/config/ayosms.php`

---

🧠 Installation
--------------

[](#-installation)

### 🧩 Manual Install

[](#-manual-install)

```
# Copy the SDK file
cp Ayosms.php /path/to/your/project/application/libraries/
```

### ⚙️ Composer (recommended for modular use)

[](#️-composer-recommended-for-modular-use)

If you’re managing dependencies manually:

```
composer require imamrasyid/php-ayosms
```

---

🧰 Configuration
---------------

[](#-configuration)

```
// application/config/ayosms.php
$config['api_key'] = 'YOUR_AYOSMS_API_KEY';
```

Then in your controller:

```
$this->load->library('Ayosms', $this->config->item('ayosms'));
```

Or in pure PHP:

```
require_once 'Ayosms.php';
$ayosms = new Ayosms(['api_key' => 'YOUR_API_KEY']);
```

---

✉️ Usage Examples
-----------------

[](#️-usage-examples)

### 1️⃣ Send SMS

[](#1️⃣-send-sms)

```
$response = $ayosms->sendSMS(
    from: 'AYOSMS',
    to: ['628123456789', '628987654321'],
    msg: 'Hello from AYOSMS PHP SDK!',
    options: [
        'trx_id' => 'demo-001',
        'dlr' => 1,
        'priority' => 'high'
    ]
);

echo $response; // JSON output
```

### 2️⃣ Check Balance

[](#2️⃣-check-balance)

```
$response = $ayosms->checkBalance();
```

### 3️⃣ HLR Lookup

[](#3️⃣-hlr-lookup)

```
$response = $ayosms->sendHLR('628123456789', [
    'trx_id' => 'hlr-check-1'
]);
```

### 4️⃣ OTP Request

[](#4️⃣-otp-request)

```
$response = $ayosms->otpRequest([
    'from' => 'AYOSMS',
    'to' => '628123456789',
    'secret' => 'my-shared-secret',
    'msisdncheck' => 1
]);
```

### 5️⃣ OTP Check

[](#5️⃣-otp-check)

```
$response = $ayosms->otpCheck([
    'from' => 'AYOSMS',
    'secret' => 'my-shared-secret',
    'pin' => '123456'
]);
```

---

🧾 Response Format
-----------------

[](#-response-format)

Every method returns a **JSON string** — you can decode it via:

```
$data = json_decode($response, true);
if ($data['status'] === 1) {
    echo 'Success!';
} else {
    echo 'Error: ' . $data['error-text'];
}
```

---

⚡ Error Reference (Common Codes)
--------------------------------

[](#-error-reference-common-codes)

CodeDescription`ERR001`Account suspended`ERR002`Insufficient balance`ERR005`Invalid or empty `from``ERR006`Invalid or empty `to``ERR007`Empty or too long message`ERR008`Invalid characters (non-GSM 7-bit)`ERR010`Invalid datetime format`ERR011`Delivery time is in the past`ERR012`Secret (OTP) missing`ERR013`trx\_id too long`ERR999`API Key missing`CURL001`Network/connection error`HTTP###`Unexpected HTTP code (e.g., 404, 500)`JSON###`Response not valid JSON---

🧪 DLR (Delivery Report) Integration
-----------------------------------

[](#-dlr-delivery-report-integration)

If you enable DLR (Delivery Report) callback in your AYOSMS dashboard, use the helper:

```
$result = $ayosms->validateDlrPayload($_POST);
if ($result['valid']) {
    echo 'OK'; // required by AYOSMS
} else {
    error_log('Invalid DLR: ' . implode(',', $result['errors']));
}
```

---

🧩 Contributing
--------------

[](#-contributing)

Pull requests are welcome! Please follow:

- PSR-12 coding standard
- PHPDoc best practices
- Commit message style: `feat:`, `fix:`, `docs:` etc.

---

🪄 Example Integration (CodeIgniter 3)
-------------------------------------

[](#-example-integration-codeigniter-3)

```
class Sms extends CI_Controller {
    public function send() {
        $this->load->library('Ayosms', ['api_key' => 'YOUR_KEY']);
        $resp = $this->ayosms->sendSMS('AYOSMS', '628123456789', 'Testing AYOSMS SDK');
        echo $resp;
    }
}
```

---

🧭 License
---------

[](#-license)

MIT License © 2025 — Created by [Imam Rasyid](https://github.com/imamrasyid)

> “Simple, elegant, and reliable — just like your SMS delivery.” 📡

📜 Changelog
-----------

[](#-changelog)

### 🆕 v1.1 — Word-Safe SMS Splitting &amp; Encoding Fix

[](#-v11--word-safe-sms-splitting--encoding-fix)

**Released V1.1**

- 🧩 **Fixed:** Message encoding no longer uses `rawurlencode($msg)` (prevented double-encoding issues on special characters).
- 💬 **Improved:** Added intelligent word-safe segmentation (`softSplitMessage()`) ensuring long messages split naturally at spaces, never mid-word.
- 🧮 **Refined:** Segment calculation (`calcSegments()`) now respects human-readable boundaries.
- ⚡ **Optimized:** Internal code structure cleaned up for clarity and maintainability.
- ✅ **Compatibility:** 100 % backward-compatible with v1.0 API behavior.

### 🧰 v1.0 — Initial Release

[](#-v10--initial-release)

**Stable release – V1.0**

- Full AYOSMS API coverage (SMS, OTP, HLR, Balance)
- Comprehensive error mapping
- CodeIgniter &amp; Composer support
- PHPUnit test suite with 95 % coverage

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance66

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

208d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d25b79dfd71878f77c68211a96597bb647ee3062506affc8608077e8fb637c5?d=identicon)[eyetracker](/maintainers/eyetracker)

---

Top Contributors

[![imamrasyid](https://avatars.githubusercontent.com/u/64980773?v=4)](https://github.com/imamrasyid "imamrasyid (8 commits)")

---

Tags

otpsmsphp-sdkApi Wrapperindonesiasms-gatewaycomposer-packagehlrbalanceayosms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/imamrasyid-php-ayosms/health.svg)

```
[![Health](https://phpackages.com/badges/imamrasyid-php-ayosms/health.svg)](https://phpackages.com/packages/imamrasyid-php-ayosms)
```

###  Alternatives

[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[smsapi/php-client

SMSAPI API PHP Client

652.1M17](/packages/smsapi-php-client)[salehhashemi/laravel-otp-manager

Laravel OTP manager

18713.2k](/packages/salehhashemi-laravel-otp-manager)[smsapi.pl/php-client

SMSAPI API PHP Client

6581.4k1](/packages/smsapipl-php-client)[ghasedak/php

ghasedak sms gateway package for PHP

2044.3k7](/packages/ghasedak-php)[otherguy/php-currency-api

A PHP API Wrapper to offer a unified programming interface for popular Currency Rate APIs.

2526.2k](/packages/otherguy-php-currency-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
