mobilemessage/php-sdk
Composer 安装命令:
composer require mobilemessage/php-sdk
包简介
PHP SDK for Mobile Message SMS API
README 文档
README
An unofficial PHP SDK for the Mobile Message SMS API. Send SMS messages, track delivery status, and manage your messaging campaigns with Australia's leading SMS service.
Features
- ✅ Send single and bulk SMS messages
- ✅ Track message delivery status
- ✅ Check account balance
- ✅ Simple and Advanced API endpoints
- ✅ Automatic message validation before sending
- ✅ Comprehensive error handling
- ✅ Laravel and CodeIgniter compatible
- ✅ PSR-4 autoloading
- ✅ Extensive test coverage
- ✅ Type-safe with PHP 7.4+ support
Installation
Install the SDK via Composer:
composer require mobilemessage/php-sdk
Requirements
- PHP 7.4 or higher
- Guzzle HTTP client
- Mobile Message API credentials
Quick Start
<?php require_once 'vendor/autoload.php'; use MobileMessage\MobileMessageClient; use MobileMessage\DataObjects\Message; // Initialise the client $client = new MobileMessageClient('your_username', 'your_password'); // Send a single SMS $response = $client->sendMessage( '0412345678', // recipient 'Hello from Mobile Message!', // message 'YourCompany', // sender ID 'optional-reference' // custom reference (optional) ); if ($response->isSuccess()) { echo "Message sent! ID: " . $response->getMessageId(); } else { echo "Failed to send: " . $response->getStatus(); }
Usage
Basic Configuration
use MobileMessage\MobileMessageClient; $client = new MobileMessageClient('your_username', 'your_password'); // Optional: Configure HTTP client options $client = new MobileMessageClient('your_username', 'your_password', [ 'timeout' => 60, 'connect_timeout' => 10, ]); // Optional: Override the default base URL (e.g., for staging) $client = new MobileMessageClient('your_username', 'your_password', [ 'base_uri' => 'https://staging.api.mobilemessage.com.au/', ]);
Note: The constructor will throw a
ValidationExceptionif the username or password is empty.
Sending Messages
Single Message
$response = $client->sendMessage( '0412345678', 'Your verification code is 1234', 'YourApp' ); echo "Status: " . $response->getStatus() . "\n"; echo "Message ID: " . $response->getMessageId() . "\n"; echo "Cost: " . $response->getCost() . " credits\n";
Bulk Messages
use MobileMessage\DataObjects\Message; $messages = [ new Message('0412345678', 'Message 1', 'YourApp', 'ref1'), new Message('0412345679', 'Message 2', 'YourApp', 'ref2'), new Message('0412345680', 'Message 3', 'YourApp', 'ref3'), ]; $responses = $client->sendMessages($messages); foreach ($responses as $response) { echo "To: {$response->getTo()}, Status: {$response->getStatus()}\n"; }
Checking Account Balance
$balance = $client->getBalance(); echo "Current balance: " . $balance->getBalance() . " credits\n"; echo "Plan: " . $balance->getPlan() . "\n"; if ($balance->hasCredits()) { echo "You have credits available\n"; }
Message Status Tracking
// Get message status by ID $messageId = 'your-message-id-here'; $status = $client->getMessage($messageId); echo "Message Status: " . $status->getStatus() . "\n"; echo "Delivered: " . ($status->isDelivered() ? 'Yes' : 'No') . "\n"; echo "Failed: " . ($status->isFailed() ? 'Yes' : 'No') . "\n"; if ($status->getDeliveredAt()) { echo "Delivered at: " . $status->getDeliveredAt() . "\n"; }
Message Validation
Messages are automatically validated before sending via sendMessage() and sendMessages(). The following rules are enforced:
- Message content cannot be empty
- Message length cannot exceed 765 characters
- Recipient phone number is required
- Sender ID is required
Both ASCII and Unicode messages are accepted.
You can also validate manually:
use MobileMessage\DataObjects\Message; use MobileMessage\Exceptions\ValidationException; $message = new Message('0412345678', 'Test message', 'Sender'); try { $client->validateMessage($message); echo "Message is valid\n"; } catch (ValidationException $e) { echo "Validation error: " . $e->getMessage() . "\n"; }
Laravel Integration
Service Provider Registration
Add to your config/app.php:
// Create a custom service provider 'providers' => [ // ... other providers App\Providers\MobileMessageServiceProvider::class, ],
Service Provider Implementation
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use MobileMessage\MobileMessageClient; class MobileMessageServiceProvider extends ServiceProvider { public function register() { $this->app->singleton(MobileMessageClient::class, function ($app) { return new MobileMessageClient( config('services.mobile_message.username'), config('services.mobile_message.password') ); }); } }
Configuration
Add to your config/services.php:
'mobile_message' => [ 'username' => env('MOBILE_MESSAGE_USERNAME'), 'password' => env('MOBILE_MESSAGE_PASSWORD'), ],
Usage in Laravel
<?php namespace App\Http\Controllers; use MobileMessage\MobileMessageClient; class SmsController extends Controller { public function __construct(private MobileMessageClient $smsClient) { } public function sendNotification(Request $request) { $response = $this->smsClient->sendMessage( $request->phone, $request->message, 'YourApp' ); return response()->json([ 'success' => $response->isSuccess(), 'message_id' => $response->getMessageId(), ]); } }
CodeIgniter Integration
Library Setup
Create application/libraries/MobileMessage.php:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); require_once APPPATH . '../vendor/autoload.php'; use MobileMessage\MobileMessageClient; class MobileMessage { private $client; public function __construct($params = []) { $CI = &get_instance(); $CI->load->config('mobile_message'); $this->client = new MobileMessageClient( $CI->config->item('mobile_message_username'), $CI->config->item('mobile_message_password') ); } public function send_sms($to, $message, $sender, $custom_ref = null) { return $this->client->sendMessage($to, $message, $sender, $custom_ref); } public function get_balance() { return $this->client->getBalance(); } }
Configuration
Create application/config/mobile_message.php:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); $config['mobile_message_username'] = 'your_username'; $config['mobile_message_password'] = 'your_password';
Usage in CodeIgniter
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Sms extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('mobilemessage'); } public function send_notification() { $response = $this->mobilemessage->send_sms( '0412345678', 'Your order has been confirmed!', 'YourStore' ); if ($response->isSuccess()) { echo "SMS sent successfully!"; } else { echo "Failed to send SMS: " . $response->getStatus(); } } }
Error Handling
The SDK provides specific exception types for different error conditions:
use MobileMessage\Exceptions\AuthenticationException; use MobileMessage\Exceptions\ValidationException; use MobileMessage\Exceptions\RateLimitException; use MobileMessage\Exceptions\MobileMessageException; try { $response = $client->sendMessage('0412345678', 'Test', 'Sender'); } catch (AuthenticationException $e) { echo "Authentication failed: " . $e->getMessage(); } catch (ValidationException $e) { echo "Validation error: " . $e->getMessage(); } catch (RateLimitException $e) { echo "Rate limit exceeded: " . $e->getMessage(); } catch (MobileMessageException $e) { echo "API error: " . $e->getMessage(); }
Testing
Quick Start Testing Setup
For easy testing with your real Mobile Message API credentials:
# Run the interactive setup script
./setup-testing.sh
This will:
- Create a
.envfile with your API credentials - Configure test phone number and sender ID
- Set up safety controls for real SMS testing
Manual Testing Setup
-
Copy the environment template:
cp .env.example .env
-
Edit
.envwith your credentials:API_USERNAME=your_api_username API_PASSWORD=your_api_password TEST_PHONE_NUMBER=0400322583 SENDER_PHONE_NUMBER=your_sender_phone ENABLE_REAL_SMS_TESTS=false # Set to true to send real SMS ENABLE_BULK_SMS_TESTS=false # Set to true to enable bulk testing
Running Tests
# Unit tests only (safe, no API calls) composer test # Integration tests (requires valid .env credentials) composer test -- --testsuite Integration # Test coverage report composer test-coverage # Comprehensive test script with real API php examples/test_example.php # Test individual examples php examples/basic_example.php php examples/bulk_example.php
⚠️ Important: Integration tests with ENABLE_REAL_SMS_TESTS=true will send actual SMS messages and use credits from your Mobile Message account.
Examples
See the examples/ directory for complete working examples:
API Reference
MobileMessageClient
| Method | Description | Parameters | Returns |
|---|---|---|---|
sendMessage() |
Send a single SMS | $to, $message, $sender, $customRef? |
MessageResponse |
sendMessages() |
Send multiple SMS | Message[] |
MessageResponse[] |
getMessage() |
Get message status | $messageId |
MessageStatusResponse |
getBalance() |
Get account balance | - | BalanceResponse |
validateMessage() |
Validate message | Message |
void (throws on error) |
Data Objects
- Message: Input message data
- MessageResponse: API response for sent messages
- MessageStatusResponse: Message status lookup response
- BalanceResponse: Account balance information
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
This is an unofficial SDK for the Mobile Message API. It is not affiliated with or endorsed by Mobile Message Pty Ltd. For official support and documentation, please visit Mobile Message.
Support
mobilemessage/php-sdk 适用场景与选型建议
mobilemessage/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.68k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sms」 「messaging」 「australia」 「bulk sms」 「Mobile message」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mobilemessage/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mobilemessage/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mobilemessage/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
Azure service bus Transport
Official PHP client for NATS messaging system
yii2-sms expand
统计信息
- 总下载量: 1.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-30