fresh/sinch-bundle
最新稳定版本:0.4.0
Composer 安装命令:
composer require fresh/sinch-bundle
包简介
Provides integration with Sinch.com SMS API.
README 文档
README
📦 Provides integration with Sinch.com SMS API.
Requirements
- PHP 7.1 and later
- Symfony 4.0 and later
Installation
Create application for Sinch
Sing up in Sinch.com and create a new app.
Add dependency via Composer
composer req fresh/sinch-bundle='dev-master'
Add key and secret to parameters.yml
Add the following lines to your parameters.yml.dist file:
parameters: sinch.key: EnterKeyForYourSinchApp sinch.secret: EnterSecretForYourSinchApp
During the composer update you have to enter your own key and secret for your Sinch application, which you can find in your Sinch dashboard.
Update config.yml
Add the following lines to config.yml file:
fresh_sinch: key: "%sinch.key%" secret: "%sinch.secret%"
Usage
Example of sending SMS
use Fresh\SinchBundle\Service\Sinch; class Foo { public function bar(Sinch $sinch) { // Set the outbound number where you want to send the SMS $messageId = $sinch->sendSMS('+13155555552', 'Your message'); // If success then the ID of sent message is returned (it is an integer value) echo $messageId; } }
Example of checking SMS status
use Fresh\SinchBundle\Service\Sinch; class Foo { public function bar(Sinch $sinch) { $messageId = 123456789; // The ID of Sinch message you get after successful SMS sending // Status is a string with one of these values: pending, successful, faulted, unknown $status = $sinch->getStatusOfSMS($messageId); // Other helper methods, return true of false $sinch->smsIsSentSuccessfully($messageId); $sinch->smsIsPending($messageId); $sinch->smsIsFaulted($messageId); $sinch->smsInUnknownStatus($messageId); } }
Catching and processing Sinch exceptions
use Fresh\SinchBundle\Exception\PaymentRequired\SinchPaymentRequiredException; use Fresh\SinchBundle\Service\Sinch; class Foo { public function bar(Sinch $sinch) { try { $messageId = $sinch->sendSMS($phoneNumber, 'Your message'); // Some logic related to SMS processing... } catch (SinchPaymentRequiredException $e) { $logger->error('SMS was not sent. Looks like your Sinch account run out of money.'); // Here you can, for example, send urgent emails to admin users // to notify that your Sinch account run out of money } } }
Contributing
See CONTRIBUTING file.
fresh/sinch-bundle 适用场景与选型建议
fresh/sinch-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 793 次下载、GitHub Stars 达 18, 最近一次更新时间为 2015 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「api」 「client」 「sms」 「bundle」 「verification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fresh/sinch-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fresh/sinch-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fresh/sinch-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Bundle Symfony DaplosBundle
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
统计信息
- 总下载量: 793
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-12
