承接 mkakpabla/sms-gateway 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mkakpabla/sms-gateway

Composer 安装命令:

composer require mkakpabla/sms-gateway

包简介

Framework-agnostic SMS gateway with multi-provider fallback support

README 文档

README

License: MIT

Framework-agnostic SMS gateway with multi-provider fallback support for PHP 8.3+.

Features

  • Multi-driver support — register multiple SMS providers and switch between them
  • Automatic fallback — if one provider fails, the next one in the chain is used
  • Laravel integration — service provider with auto-discovery, notification channel, and publishable config
  • Extensible — implement SmsDriverInterface to add your own providers

Supported Providers

Provider Driver Status
FasterMessage faster-message ✅ Available
AfrikSMS afriksms ✅ Available
NATYABIP natyabip ✅ Available

Installation

composer require mkakpabla/sms-gateway

Laravel

The service provider is auto-discovered. Publish the configuration file:

php artisan vendor:publish --tag=sms-gateway-config

Add your credentials to .env:

SMS_DRIVER=faster-message

# FasterMessage
FASTER_MESSAGE_FROM=MyApp
FASTER_MESSAGE_API_URL=https://api.fastermessage.com
FASTER_MESSAGE_USERNAME=your-username
FASTER_MESSAGE_PASSWORD=your-password

# AfrikSMS
AFRIKSMS_CLIENT_ID=your-client-id
AFRIKSMS_API_KEY=your-api-key
AFRIKSMS_SENDER_ID=AFRIKSMS

# NATYABIP
NATYABIP_USERNAME=your-username
NATYABIP_PASSWORD=your-password
NATYABIP_FROM=EASYSERVICE
NATYABIP_API_URL=https://api.natyabip.com/smsapiprod_web/FR/api.awp

Usage

Standalone

use SmsGateway\SmsGateway;
use SmsGateway\SmsMessage;
use SmsGateway\Drivers\FasterMessageDriver;

$gateway = new SmsGateway();

$gateway->registerDriver('faster-message', new FasterMessageDriver(
    from: 'MyApp',
    apiUrl: 'https://api.fastermessage.com',
    username: 'your-username',
    password: 'your-password',
));

$gateway->setDefaultDriver('faster-message');

$gateway->send('+22890001234', SmsMessage::create('Hello!'));

AfrikSMS

use SmsGateway\SmsGateway;
use SmsGateway\SmsMessage;
use SmsGateway\Drivers\AfrikSmsDriver;

$gateway = new SmsGateway();

$gateway->registerDriver('afriksms', new AfrikSmsDriver(
    clientId: 'your-client-id',
    apiKey: 'your-api-key',
    senderId: 'AFRIKSMS',
));

$gateway->setDefaultDriver('afriksms');

$gateway->send('22890001234', SmsMessage::create('Hello!'));

NATYABIP

use SmsGateway\SmsGateway;
use SmsGateway\SmsMessage;
use SmsGateway\Drivers\NatyabipDriver;

$gateway = new SmsGateway();

$gateway->registerDriver('natyabip', new NatyabipDriver(
    apiUrl: 'https://your-natyabip-api-url',
    username: 'your-username',
    password: 'your-password',
    from: 'EASYSERVICE',
));

$gateway->setDefaultDriver('natyabip');

$gateway->send('22890001234', SmsMessage::create('Hello!'));

With fallback

$gateway->registerDriver('driver-a', $driverA);
$gateway->registerDriver('driver-b', $driverB);

$gateway->setFallbackOrder(['driver-a', 'driver-b']);

// Tries driver-a first, falls back to driver-b on failure
$gateway->sendWithFallback('+22890001234', SmsMessage::create('Hello!'));

Laravel Notification

Implement the HasSmsNotification contract on your notification:

use Illuminate\Notifications\Notification;
use SmsGateway\Contracts\HasSmsNotification;
use SmsGateway\SmsMessage;

class OrderShipped extends Notification implements HasSmsNotification
{
    public function via($notifiable): array
    {
        return ['sms-gateway'];
    }

    public function toSms(object $notifiable): SmsMessage
    {
        return SmsMessage::create('Your order has been shipped!');
    }
}

Make sure your notifiable model provides a phone number:

public function routeNotificationForSms(): string
{
    return $this->phone;
}

Creating a Custom Driver

Implement SmsDriverInterface:

use SmsGateway\Contracts\SmsDriverInterface;
use SmsGateway\SmsMessage;

class MyCustomDriver implements SmsDriverInterface
{
    public function send(string $to, SmsMessage $message): void
    {
        // Your implementation here
    }
}

Then register it:

$gateway->registerDriver('my-driver', new MyCustomDriver());

Configuration

The config file (config/sms-gateway.php) supports the following options:

Key Description
default The default SMS driver to use
fallback Ordered list of drivers for the fallback chain
drivers Per-driver configuration (credentials, API URLs, etc.)

Testing

composer test

Quality tools

composer phpstan   # Static analysis
composer phpmd     # Mess detector
composer phpcs     # Code style
composer quality   # Run all checks

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.

License

MIT

mkakpabla/sms-gateway 适用场景与选型建议

mkakpabla/sms-gateway 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mkakpabla/sms-gateway 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mkakpabla/sms-gateway 我们能提供哪些服务?
定制开发 / 二次开发

基于 mkakpabla/sms-gateway 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-17