承接 smsfire/php-sdk 相关项目开发

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

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

smsfire/php-sdk

Composer 安装命令:

composer require smsfire/php-sdk

包简介

SDK for all SMSFIRE services

README 文档

README

Version Total Downloads PHP Version Require

Requirements

Installation

You can install php-sdk via composer or by downloading the source.

Composer

php-sdk is available on Packagist as the smsfire/php-sdk package:

composer require smsfire/php-sdk

SMS Services

The reference of this service can be found here

💬 Messages Service
📬 Inbox Service
☑️ Status Service

Namespace - Smsfire\Sms\Messages

This namespace allows you to send SMS messages.

Receiving messages (MO)

When you set as true the allowReply param on sendIndividual() or sendBulk() messaging methods, your account may have additional costs per each received message. Contact your account manager to know more about it.

Flash messages - Class 0

The flash param depends of route that were settled on your account as well of each carrier's availability for this feature. Contact your account manager to know more about it.

Send individual message - sendIndividual()

Access the reference docs to check the data response and the details of each parameter of this method.

Guide of available parameters on this method

Param Type Description Condition Required
to string Phone at international syntax Max of 15 characters
text string SMS message Max of 765 characters
from string Remitent of sms Max of 11 characters
customId string Set your own id Max of 40 characters
campaignId int Merge messages into existent campaign -
flash bool Send message on flash mode - Check availability Default: false
allowReply bool Allow gateway to capture reply from your messages Default: false
scheduleTime string Schedule message on given datetime Datetime ISO8601
debug bool Debug API request Default: false

Example

//Load composer autoload file
require './vendor/autoload.php';

use Smsfire\Sms\Messages;
use Smsfire\Exceptions\SmsfireException;
use Smsfire\Exceptions\HttpException;

try {

    $user = 'myuser'; //Same user that is used to access Dashboard
    $pass = 'mypass'; //Same password that is used to access Dashboard
    $token = base64_encode("{$user}:{$pass}");   

    /**
     * Pass base64 token on Message instance
     * Check guide table of params
     */
    $messagesService = new Messages($token);
    $response = $messagesService->sendIndividual(
      $to,
      $text,
      $from,
      $customId,
      $campaignId,
      $flash,
      $allowReply,
      $scheduleTime,
      $debug
    );

    /**
     * Response as raw text
     * Good to use when Debug option is true
     */
    echo $response;

    //Response with the statusCode of Http response
    echo $response->statusCode();

    //Response as json string
    echo $response->__toJson();

    //Response as object
    print_r($response->__toObject());

    //Response as array
    print_r($response->__toArray());

} catch (SmsfireException $e) {  
    echo $e->getMessage();
} catch (HttpException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Send bulk messages - sendBulk()

Access the reference docs to check the data response and the details of each parameter of this method.

Guide of available parameters on this method

Param Type Description Condition Required
destinations array Array of destinations to message Min of 2 items and Max of 1000 items
destinations[*].to string Phone at international syntax Max of 15 characters
destinations[*].text string SMS message Max of 765 characters
destinations[*].from string Remitent of SMS Max of 11 characters
destinations[*].customId string Set your own id Max of 40 characters
destinations[*].flash bool Send message on flash mode - Check availability Default: false
allowReply bool Allow gateway to capture reply from your messages Default: false
scheduleTime string Schedule message on given datetime Datetime ISO8601
debug bool Debug API request Default: false

Example

//Load composer autoload file
require './vendor/autoload.php';

use Smsfire\Sms\Messages;
use Smsfire\Exceptions\SmsfireException;
use Smsfire\Exceptions\HttpException;

try {

    $user = 'myuser'; //Same user that is used to access Dashboard
    $pass = 'mypass'; //Same password that is used to access Dashboard
    $token = base64_encode("{$user}:{$pass}");   

    //Pass base64 token on Message instance
    $messagesService = new Messages($token);

    //Minimum of two items to use Bulk request
    $destinations = [
      [
        'to' => '5511944556677',
        'text' => 'My first message',
        'customId' => 'abc-00001',
        'flash' => true
      ],
      [
        'to' => '5565988887777',
        'text' => 'My second message'
      ]
    ];

    $response = $messagesService->sendBulk(
        $destinations,
        $campaignId,
        $allowReply,
        $scheduleTime,
        $debug
    );

    /**
     * Response as raw text
     * Good to use when Debug option is true
     */
    echo $response;

    //Response with the statusCode of Http response
    echo $response->statusCode();

    //Response as json string
    echo $response->__toJson();

    //Response as object
    print_r($response->__toObject());

    //Response as array
    print_r($response->__toArray());

} catch (SmsfireException $e) {  
    echo $e->getMessage();
} catch (HttpException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Namespace - Smsfire\Sms\Inbox

This namespace allows you to get received messages from your sms inbox.

Access the reference docs to check the data response and the details of each parameter of this method.

The statusCode 204 will be given when your inbox has no messages. REF. 204 No Content

Get all messages - getAll()

Example

//Load composer autoload file
require './vendor/autoload.php';

use Smsfire\Sms\Inbox;
use Smsfire\Exceptions\SmsfireException;
use Smsfire\Exceptions\HttpException;

try {

    $debug = false;    //Debug API request - DEFAULT: false
    $user  = 'myuser'; //Same user that is used to access Dashboard
    $pass  = 'mypass'; //Same password that is used to access Dashboard
    $token = base64_encode("{$user}:{$pass}");   

    /**
     * Pass base64 token on Inbox instance
     * Check guide table of params
     */
    $inboxServices = new Inbox($token);
    $response = $inboxServices->getAll($debug);

    /**
     * Response as raw text
     * Good to use when Debug option is true
     */
    echo $response;

    //Response with the statusCode of Http response
    echo $response->statusCode();

    //Response as json string
    echo $response->__toJson();

    //Response as object
    print_r($response->__toObject());

    //Response as array
    print_r($response->__toArray());

    //Handle empty inbox
    if($response->statusCode() === 204) {
      echo "Empty inbox";
    }

} catch (SmsfireException $e) {  
    echo $e->getMessage();
} catch (HttpException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Due API limitations this method will expose the last 100 received messages of your inbox. For more, access the Portal SMSFire and access it on menu SMS > Inbox

Get unread messages - getUnread()

Example

//Load composer autoload file
require './vendor/autoload.php';

use Smsfire\Sms\Inbox;
use Smsfire\Exceptions\SmsfireException;
use Smsfire\Exceptions\HttpException;

try {

    $debug = false;    //Debug API request - DEFAULT: false
    $user  = 'myuser'; //Same user that is used to access Dashboard
    $pass  = 'mypass'; //Same password that is used to access Dashboard
    $token = base64_encode("{$user}:{$pass}");   

    /**
     * Pass base64 token on Inbox instance
     * Check guide table of params
     */
    $inboxServices = new Inbox($token);
    $response = $inboxServices->getUnread($debug);

    /**
     * Response as raw text
     * Good to use when Debug option is true
     */
    echo $response;

    //Response with the statusCode of Http response
    echo $response->statusCode();

    //Response as json string
    echo $response->__toJson();

    //Response as object
    print_r($response->__toObject());

    //Response as array
    print_r($response->__toArray());

    //Handle empty inbox
    if($response->statusCode() === 204) {
      echo "Empty inbox";
    }

} catch (SmsfireException $e) {  
    echo $e->getMessage();
} catch (HttpException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Namespace - Smsfire\Sms\Status

This namespace allows you to get messages status by id or given customId

Access the reference docs to check the data response and the details of each parameter of this method.

The statusCode 204 will be given when given id or customId does not exist. REF. 204 No Content

Get messages status by id - messageIds()

Guide of available parameters on this method

Param Type Description Condition Required
ids string String with messages ids (Comma separated) Min of 1 and max of 200 Ids
debug bool Debug API request Default: false

Example

//Load composer autoload file
require './vendor/autoload.php';

use Smsfire\Sms\Status;
use Smsfire\Exceptions\SmsfireException;
use Smsfire\Exceptions\HttpException;

try {

    $user  = 'myuser'; //Same user that is used to access Dashboard
    $pass  = 'mypass'; //Same password that is used to access Dashboard
    $token = base64_encode("{$user}:{$pass}");   

    /**
     * Pass base64 token on Status instance
     * Check guide table of params
     */
    $messagesStatus = new Status($token);
    $ids = "000001,000002,000003"; //Messages ids - Comma separated
    $response = $messagesStatus->messageIds($ids, $debug);

    /**
     * Response as raw text
     * Good to use when Debug option is true
     */
    echo $response;

    //Response with the statusCode of Http response
    echo $response->statusCode();

    //Response as json string
    echo $response->__toJson();

    //Response as object
    print_r($response->__toObject());

    //Response as array
    print_r($response->__toArray());

    //Handle empty result
    if($response->statusCode() === 204) {
      echo "Message id does not exist";
    }

} catch (SmsfireException $e) {  
    echo $e->getMessage();
} catch (HttpException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Due API limitations this method will accepts the maximum of 200 messages ids. For more, access the Portal SMSFire and access it on menu SMS > Reports

Get messages status by customId - customIds()

Guide of available parameters on this method

Param Type Description Condition Required
customIds string String with custom id of messages (Comma separated) Min of 1 and max of 200 custom ids
debug bool Debug API request Default: false

Example

//Load composer autoload file
require './vendor/autoload.php';

use Smsfire\Sms\Status;
use Smsfire\Exceptions\SmsfireException;
use Smsfire\Exceptions\HttpException;

try {

    $user  = 'myuser'; //Same user that is used to access Dashboard
    $pass  = 'mypass'; //Same password that is used to access Dashboard
    $token = base64_encode("{$user}:{$pass}");   

    /**
     * Pass base64 token on Status instance
     * Check guide table of params
     */
    $messagesStatus = new Status($token);
    $customIds = "myid0001,myid000002,myid000003"; //Custom ids - Comma separated
    $response = $messagesStatus->customIds($customIds, $debug);

    /**
     * Response as raw text
     * Good to use when Debug option is true
     */
    echo $response;

    //Response with the statusCode of Http response
    echo $response->statusCode();

    //Response as json string
    echo $response->__toJson();

    //Response as object
    print_r($response->__toObject());

    //Response as array
    print_r($response->__toArray());

    //Handle empty result
    if($response->statusCode() === 204) {
      echo "Custom id does not exist";
    }

} catch (SmsfireException $e) {  
    echo $e->getMessage();
} catch (HttpException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Namespace - Smsfire\Exceptions

Custom exceptions that allows you a better error handling.

SmsfireException

This will be thrown when any SDK required types and data were not meet.

HttpException

This will be thrown when the core API has some request problem as timeout or bad data for example.

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-19