承接 smsgist/smsgist-php 相关项目开发

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

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

smsgist/smsgist-php

Composer 安装命令:

composer require smsgist/smsgist-php

包简介

PHP SDK for the SMSGist messaging platform — send SMS and email from any PHP application

README 文档

README

PHP SDK for the SMSGist messaging platform. Send SMS and email from any PHP application.

Works with vanilla PHP, Laravel, Symfony, or any PHP 8.1+ project.

Installation

composer require smsgist/smsgist-php

Configuration

Set these environment variables:

SMSGIST_CLIENT_ID=your-client-id
SMSGIST_CLIENT_SECRET=your-client-secret
SMSGIST_APP_KEY=your-32-byte-encryption-key
SMSGIST_URI=https://api.smsgist.com

Get your credentials from the SMSGist Dashboard.

Quick Start

use SMSGist\Client;

$client = Client::create();

// Send SMS
$response = $client->send('sms')
    ->to('0240000001')
    ->from('MyApp')
    ->message('Hello from SMSGist!')
    ->exec();

echo $response->messageId;    // "9b1deb4d-3b7d-..."
echo $response->status;       // "queued"
echo $response->totalCost;    // 0.03

Sending SMS

// Basic SMS
$response = $client->send('sms')
    ->to('0240000001', '0240000002')
    ->from('MyApp')
    ->message('Hello World')
    ->exec();

// OTP with priority routing
$response = $client->send('sms')
    ->to('0240000001')
    ->messageOtp('Your verification code is 123456')
    ->exec();

// With idempotency key (prevents duplicate sends)
$response = $client->send('sms')
    ->to('0240000001')
    ->message('Order #1234 confirmed')
    ->idempotencyKey('order-confirm-1234')
    ->exec();

Sending Email

// Basic email — message() defaults to HTML content
$response = $client->send('email')
    ->to('user@example.com')
    ->from('My App')
    ->subject('Welcome!')
    ->message('<h1>Hello</h1><p>Welcome to our platform.</p>')
    ->exec();

// With reply-to and attachments
$response = $client->send('email')
    ->to('user@example.com')
    ->from('Billing')
    ->subject('Your Invoice')
    ->message('<p>Please find your invoice attached.</p>')
    ->replyTo('billing@myapp.com')
    ->attachFile('/path/to/invoice.pdf')
    ->attach('summary.csv', $csvContent)
    ->exec();

// Disable open/click tracking
$response = $client->send('email')
    ->to('user@example.com')
    ->subject('Password Reset')
    ->message('<p>Click <a href="https://myapp.com/reset/abc123">here</a> to reset.</p>')
    ->noTracking()
    ->exec();

HTML vs Plain Text & OTP Routing

Email bodies can be sent as HTML or plain text, and OTP/verification emails can be routed to a high-priority queue. Use these explicit helpers instead of the bare message() / messageOtp() for new code:

// HTML email (regular priority) — same as message(), but explicit
$client->send('email')->to('user@example.com')->subject('Welcome')
    ->messageHtml('<h1>Hello</h1>')
    ->exec();

// HTML OTP email (high-priority "otp" route)
$client->send('email')->to('user@example.com')->subject('Your code')
    ->messageHtmlOtp('<p>Your code is <b>123456</b></p>')
    ->exec();

// Plain-text email (regular priority)
$client->send('email')->to('user@example.com')->subject('Welcome')
    ->messagePlainText('Hello, welcome to our platform.')
    ->exec();

// Plain-text OTP email (high-priority "otp" route)
$client->send('email')->to('user@example.com')->subject('Your code')
    ->messagePlainTextOtp('Your code is 123456')
    ->exec();
MethodContent typeRoute
messageHtml($body)htmlregular
messageHtmlOtp($body)htmlotp
messagePlainText($body)textregular
messagePlainTextOtp($body)textotp

message() on email defaults to HTML content, and messageOtp() on email is routed to the otp queue — so existing code keeps working unchanged. These helpers and content_type apply to email only; SMS payloads are unaffected.

Response Objects

SendResponse

Returned by exec():

$response->messageId;        // string — unique message ID
$response->status;           // "queued", "sent", "dryrun"
$response->recipientsCount;  // int
$response->segments;         // int (SMS only, 0 for email)
$response->totalCost;        // float
$response->costPerUnit;      // float
$response->recipients;       // RecipientRef[] — per-recipient tracking IDs

Delivery Status

$status = $client->getDeliveryStatus($response->messageId);

$status->messageId;
$status->status;             // "queued", "sending", "sent"
$status->totalRecipients;    // int
$status->delivered;          // int
$status->pending;            // int
$status->failed;             // int

foreach ($status->recipients as $r) {
    echo $r->recipient;       // "0240000001"
    echo $r->sendStatus;      // "sent"
    echo $r->deliveryStatus;  // "delivered"
    echo $r->deliveredAt;     // DateTimeImmutable or null
    echo $r->error;           // null or error message
}

Retry Failed Messages

$retryResponse = $client->retry($messageId);
// Returns a new SendResponse with a new messageId

Credit Balance

$credits = $client->getCreditBalance();

$credits->balance;    // 150.50
$credits->reserved;   // 10.00
$credits->available;  // 140.50
$credits->currency;   // "GHS"

Webhooks

SMSGist sends webhook events when message status changes. Verify incoming webhooks:

use SMSGist\Webhook;
use SMSGist\Events;

// Verify the signature (HMAC-SHA256 + replay protection)
$isValid = Webhook::verifySignature(
    body: file_get_contents('php://input'),
    signature: $_SERVER['HTTP_X_SMSGIST_SIGNATURE'],
    timestamp: $_SERVER['HTTP_X_SMSGIST_TIMESTAMP'],
    secret: 'your-webhook-secret',
);

if (!$isValid) {
    http_response_code(401);
    exit;
}

// Parse the event
$event = Webhook::parse(file_get_contents('php://input'));

switch ($event->event) {
    case Events::MESSAGE_DELIVERED:
        // Mark message as delivered in your system
        break;
    case Events::MESSAGE_FAILED:
        // Handle failure
        break;
    case Events::MESSAGE_OPENED:
        // Track email open
        break;
}

Event Types

ConstantValueChannel
Events::MESSAGE_QUEUEDmessage.queuedSMS, Email
Events::MESSAGE_SENTmessage.sentSMS, Email
Events::MESSAGE_DELIVEREDmessage.deliveredSMS, Email
Events::MESSAGE_FAILEDmessage.failedSMS, Email
Events::MESSAGE_OPENEDmessage.openedEmail only
Events::MESSAGE_CLICKEDmessage.clickedEmail only
Events::MESSAGE_BOUNCEDmessage.bouncedEmail only
Events::MESSAGE_COMPLAINEDmessage.complainedEmail only

Modes

Control how messages are sent during development:

use SMSGist\Mode;

// Dry run — logs only, no real sends
$client = Client::create(['mode' => Mode::DryRun]);

// Test — sends to test phone/email instead of real recipients
$client = Client::create([
    'mode' => Mode::Test,
    'test_phone' => '0240000000',
    'test_email' => 'dev@myapp.com',
]);

// Live — sends to real recipients (default)
$client = Client::create(['mode' => Mode::Live]);
ModeSMSEmail
LiveSends to real recipientsSends to real recipients
TestSends to test_phoneSends to test_email
DryRunLogs onlySends to test_email if set, otherwise logs only

The backend credential mode is the source of truth. Client-level mode override is for local development only.

Error Handling

All errors throw exceptions:

use SMSGist\Exception\SMSGistException;
use SMSGist\Exception\ValidationException;
use SMSGist\Exception\ApiException;
use SMSGist\Exception\MissingConfigException;

try {
    $response = $client->send('sms')
        ->to('0240000001')
        ->message('Hello')
        ->exec();
} catch (ValidationException $e) {
    // Missing recipients, empty message, etc.
} catch (ApiException $e) {
    echo $e->statusCode;     // HTTP status code
    echo $e->responseBody;   // Raw response body
} catch (SMSGistException $e) {
    // Any other SDK error
}

Laravel Integration

The package auto-discovers in Laravel. No manual registration needed.

Publish Config

php artisan vendor:publish --tag=smsgist-config

This creates config/smsgist.php where you can customize settings.

Using the Facade

use SMSGist\Laravel\Facades\SMSGist;

$response = SMSGist::send('sms')
    ->to('0240000001')
    ->message('Hello from Laravel!')
    ->exec();

Using Dependency Injection

use SMSGist\Client;

class NotificationController extends Controller
{
    public function __construct(private Client $smsgist) {}

    public function sendWelcome(string $phone)
    {
        return $this->smsgist->send('sms')
            ->to($phone)
            ->message('Welcome!')
            ->exec();
    }
}

Webhook Route (Laravel)

// routes/api.php
Route::post('/webhooks/smsgist', function (Request $request) {
    $isValid = Webhook::verifySignature(
        body: $request->getContent(),
        signature: $request->header('X-SMSGist-Signature'),
        timestamp: $request->header('X-SMSGist-Timestamp'),
        secret: config('smsgist.webhook_secret'),
    );

    if (!$isValid) {
        return response('Invalid signature', 401);
    }

    $event = Webhook::parse($request->getContent());

    // Handle event...

    return response('OK', 200);
});

Requirements

  • PHP 8.1+
  • ext-curl
  • ext-json
  • ext-openssl
  • ext-mbstring

License

MIT

smsgist/smsgist-php 适用场景与选型建议

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

它主要适用于以下技术方向: 「email」 「sms」 「messaging」 「africa」 「Ghana」 「smsgist」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-24