imamrasyid/php-ayosms
Composer 安装命令:
composer require 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.
关键字:
README 文档
README
A modern, production-ready PHP SDK for AYOSMS! Global SMS Gateway, 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
✅ Complete API Coverage
sendSMS()— Send single or bulk SMScheckBalance()— Retrieve account balancesendHLR()— Perform HLR lookupsotpRequest()— Request OTP delivery via SMSotpCheck()— 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 & 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
🧩 Manual Install
# Copy the SDK file
cp Ayosms.php /path/to/your/project/application/libraries/
⚙️ Composer (recommended for modular use)
If you’re managing dependencies manually:
composer require imamrasyid/php-ayosms
🧰 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
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
$response = $ayosms->checkBalance();
3️⃣ HLR Lookup
$response = $ayosms->sendHLR('628123456789', [ 'trx_id' => 'hlr-check-1' ]);
4️⃣ OTP Request
$response = $ayosms->otpRequest([ 'from' => 'AYOSMS', 'to' => '628123456789', 'secret' => 'my-shared-secret', 'msisdncheck' => 1 ]);
5️⃣ OTP Check
$response = $ayosms->otpCheck([ 'from' => 'AYOSMS', 'secret' => 'my-shared-secret', 'pin' => '123456' ]);
🧾 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)
| Code | Description |
|---|---|
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
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
Pull requests are welcome! Please follow:
- PSR-12 coding standard
- PHPDoc best practices
- Commit message style:
feat:,fix:,docs:etc.
🪄 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
MIT License © 2025 — Created by Imam Rasyid
“Simple, elegant, and reliable — just like your SMS delivery.” 📡
📜 Changelog
🆕 v1.1 — 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
Stable release – V1.0
- Full AYOSMS API coverage (SMS, OTP, HLR, Balance)
- Comprehensive error mapping
- CodeIgniter & Composer support
- PHPUnit test suite with 95 % coverage
imamrasyid/php-ayosms 适用场景与选型建议
imamrasyid/php-ayosms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「otp」 「php sdk」 「Api Wrapper」 「balance」 「hlr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 imamrasyid/php-ayosms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 imamrasyid/php-ayosms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 imamrasyid/php-ayosms 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
OTP generating package
yii2-sms expand
OTP generating package
Alfabank REST API integration
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-16