spryng/rest-api-php
Composer 安装命令:
composer require spryng/rest-api-php
包简介
Implementation of the REST API in PHP
README 文档
README
This repository contains the source code for the Spryng SMS REST API library for PHP. This library will make it very easy to integrate the SMS gateway into your application. It offers all the functionality that the API has to offer.
Installation
Installation is easily done using composer:
composer require spryng/rest-api-php
When the installation is complete, you can initialize the library with your API key:
require_once "vendor/autoload.php"; use Spryng\SpryngRestApi\Spryng; $spryng = new Spryng($apiKey);
Sending messages
To send a message, supply the send method with the information about the message you'd like to send:
use Spryng\SpryngRestApi\Objects\Message; use Spryng\SpryngRestApi\Spryng; $spryng = new Spryng($apiKey); $message = new Message(); $message->setBody('My message'); $message->setRecipients(['31612344567', '31698765432']); $message->setOriginator('My Company'); $response = $spryng->message->send($message); if ($response->wasSuccessful()) { $message = $response->toObject(); echo "Message with ID " . $message->getId() . " was send successfully!\n"; } else if ($response->serverError()) { echo "Message could not be send because of a server error...\n"; } else { echo "Message could not be send. Response code: " . $response->getResponseCode() ."\n"; }
Getting info about a message
Single messages can be queried by their ID:
use Spryng\SpryngRestApi\Objects\Message; use Spryng\SpryngRestApi\Spryng; $spryng = new Spryng($apiKey); $response = $spryng->message->getMessage("9dbc5ffb-7524-4fae-9514-51decd94a44f"); if ($resposne->wasSuccessful()) { echo "The body of the message is: " . $response->toObject()->getBody() . "\n"; }
Listing messages
You can list the messages you have send in a paginated manner. You can also apply filters to get a sub-set of the messages you have send:
use Spryng\SpryngRestApi\Objects\Message; use Spryng\SpryngRestApi\Spryng; $spryng = new Spryng($apiKey); $response = $spryng->message->showAll( 1, // page 20, // limit: items per page [ // An array of filters 'recipient_number' => '31612345667' ] ); if ($response->wasSuccessful()) { // Will return an instance of MessageCollection $messages = $response->toObject(); echo "Found " . $messages->getTotal() . " results:\n"; foreach ($messages->getData() as $message) { echo sprintf("ID: %s ('%s') send on: %s\n", $message->getId(), $message->getBody(), $message->getCreatedAt() ); } }
Getting your balance
You can also check the remaining credit balance on your account:
use Spryng\SpryngRestApi\Objects\Message; use Spryng\SpryngRestApi\Spryng; $spryng = new Spryng($apiKey); $balance = $spryng->balance->get()->toObject(); echo "You have " . $balance->getAmount() . " credits remaining\n";
spryng/rest-api-php 适用场景与选型建议
spryng/rest-api-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 308.49k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「text」 「rest」 「api」 「sms」 「gateway」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spryng/rest-api-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spryng/rest-api-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spryng/rest-api-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Common libraries used by Zimbra Api
Text file manipulation
Plain text view engine
统计信息
- 总下载量: 308.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 27
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2019-06-01