ongudidan/textsms
Composer 安装命令:
composer require ongudidan/textsms
包简介
A universal, framework-agnostic PHP package for sending bulk SMS via TextSMS API. Compatible with Laravel, Yii2, Symfony, and Vanilla PHP. Features include single/bulk messaging, balance checking, and delivery status tracking.
README 文档
README
A lightweight, framework-agnostic PHP package for sending bulk SMS via TextSMS API. Compatible with Laravel, Yii2, Symfony, and Vanilla PHP.
🚀 Features
- 📨 Send Single or Bulk SMS
- 💰 Check Account Balance
- 📊 Check Delivery Status
- 🔌 Stateles and Scalable Design
📦 Installation
Install the package via Composer:
composer require ongudidan/textsms
⚙️ Usage
Since version 2.1, this package is designed to be stateless. You pass your API credentials directly to the methods. This allows for better scalability and handling multiple configurations if needed.
1️⃣ Vanilla PHP Example
require 'vendor/autoload.php'; use TextSms\Sms; $partnerID = '1234'; $apiKey = 'your_api_key'; $shortcode = 'SMS'; // Send an SMS $response = Sms::send($partnerID, $apiKey, $shortcode, '254712345678', 'Hello from PHP!'); print_r($response);
2️⃣ Laravel Integration
It is recommended to wrap the library in a Service or Helper to avoid repeating credentials.
Step 1: Add credentials to .env
TEXTSMS_PARTNER_ID=1234 TEXTSMS_API_KEY=your_api_key TEXTSMS_SHORTCODE=SMS
Step 2: Create a Service Class (e.g., App\Services\SmsService.php)
namespace App\Services; use TextSms\Sms; class SmsService { protected $partnerID; protected $apiKey; protected $shortcode; public function __construct() { $this->partnerID = config('services.textsms.partner_id'); $this->apiKey = config('services.textsms.api_key'); $this->shortcode = config('services.textsms.shortcode'); } public function send($mobile, $message) { return Sms::send($this->partnerID, $this->apiKey, $this->shortcode, $mobile, $message); } }
Step 3: Use in Controllers
use App\Services\SmsService; public function checkout(SmsService $sms) { $sms->send('254712345678', 'Order Received!'); }
3️⃣ Yii2 Integration
You can create a helper component.
namespace common\components; use Yii; use yii\base\Component; use TextSms\Sms; class SmsComponent extends Component { public $partnerID; public $apiKey; public $shortcode; public function send($mobile, $message) { return Sms::send($this->partnerID, $this->apiKey, $this->shortcode, $mobile, $message); } }
Configuration in config/web.php:
'components' => [ 'sms' => [ 'class' => 'common\components\SmsComponent', 'partnerID' => '...', 'apiKey' => '...', 'shortcode' => '...', ], ],
Usage:
Yii::$app->sms->send('254123456789', 'Hello from Yii!');
🛠 Available Methods
Send SMS
Sms::send($partnerID, $apiKey, $shortcode, $mobile, $message);
Check Balance
Sms::balance($partnerID, $apiKey);
Check Message Status
Sms::status($partnerID, $apiKey, $messageId);
🔄 Response Format
The API returns a JSON array:
{
"responses": [
{
"response-code": 200,
"response-description": "Success",
"mobile": "254712345678",
"messageid": "1869610817",
"networkid": 1
}
]
}
📜 License
This package is licensed under the MIT License.
ongudidan/textsms 适用场景与选型建议
ongudidan/textsms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ongudidan/textsms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ongudidan/textsms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 37
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-03-09