infobip/infobip-api-php-client
Composer 安装命令:
composer require infobip/infobip-api-php-client
包简介
PHP library for consuming Infobip's API
关键字:
README 文档
README
This is a PHP Client for Infobip API and you can use it as a dependency to add Infobip APIs to your application. To use this, you'll need an Infobip account. If not already having one, you can create a free trial account here.
infobip-api-php-client is built on top of OpenAPI Specification, generated by Infobip OSCAR service powered by OpenAPI Generator.
Table of contents:
Documentation
Detailed documentation about Infobip API can be found here. The current version of this library includes this subset of Infobip products:
General Info
For infobip-api-php-client versioning we use Semantic Versioning scheme.
Published under MIT License.
The library requires PHP version >= 8.3.
Installation
Using Composer
To start using the library add it as dependency in your composer.json file like shown below.
"require": { "infobip/infobip-api-php-client": "6.2.1" }
And simply run composer install to download dependencies.
Without Composer
If your setup prevents you from using composer you can manually download this package and all of its dependencies and reference them from your code. However, there are solutions that can automate this process.
One of them is php-download online tool. You can use it to find pre-composed infobip client package, download it from there and use in your project without manually collecting the dependencies.
Quickstart
Initialize the Configuration & HTTP client
The library supports the API Key Header authentication method. Once you have an Infobip account, you can manage your API keys through the Infobip API key management page.
To see your base URL, log in to the Infobip API Resource hub with your Infobip credentials or visit your Infobip account.
use Infobip\Configuration; $configuration = new Configuration( host: 'your-base-url', apiKey: 'your-api-key' );
Send an SMS
See below, a simple example of sending a single SMS message to a single recipient.
use Infobip\ApiException; use Infobip\Model\SmsRequest; use Infobip\Model\SmsDestination; use Infobip\Model\SmsMessage; use Infobip\Api\SmsApi; use Infobip\Model\SmsTextContent; $sendSmsApi = new SmsApi(config: $configuration); $message = new SmsMessage( destinations: [ new SmsDestination( to: '41793026727' ) ], content: new SmsTextContent( text: 'This is a dummy SMS message sent using infobip-api-php-client.' ), sender: 'InfoSMS' ); $request = new SmsRequest(messages: [$message]); try { $smsResponse = $sendSmsApi->sendSmsMessages($request); } catch (ApiException $apiException) { // HANDLE THE EXCEPTION }
Fields provided within ApiException object are code referring to the HTTP Code response, as well as the responseHeaders and responseBody.
Also, you can get the deserialized response body using getResponseObject method.
$apiException->getCode(); $apiException->getResponseHeaders(); $apiException->getResponseBody(); $apiException->getResponseObject();
Additionally, you can retrieve a bulkId and a messageId from the SmsResponse object to use for troubleshooting or fetching a delivery report for a given message or a bulk.
Bulk ID will be received only when you send a message to more than one destination address or multiple messages in a single request.
$bulkId = $smsResponse->getBulkId(); $messages = $smsResponse->getMessages(); $messageId = (!empty($messages)) ? current($messages)->getMessageId() : null;
Receive SMS message delivery report
For each SMS that you send out, we can send you a message delivery report in real time.
All you need to do is specify your endpoint when sending SMS in the webhooks.delivery.url field of your request, or subscribe for reports by contacting our support team at support@infobip.com.
You can use data models from the library and the pre-configured Infobip\ObjectSerializer serializer.
Example of webhook implementation:
use Infobip\Model\SmsDeliveryResult; use Infobip\ObjectSerializer; $objectSerializer = new ObjectSerializer(); $data = \file_get_contents('php://input'); /** * @var SmsDeliveryResult $deliveryResult */ $deliveryResult = $objectSerializer->deserialize($data, SmsDeliveryResult::class); foreach ($deliveryResult->getResults() ?? [] as $report) { echo $report->getMessageId() . " - " . $report->getStatus()->getName() . "\n"; }
If you prefer to use your own serializer, please pay attention to the supported date format.
Fetching delivery reports
If you are for any reason unable to receive real-time delivery reports on your endpoint, you can use messageId or bulkId to fetch them.
Each request will return a batch of delivery reports - only once. See documentation for more details.
$deliveryReports = $sendSmsApi ->getOutboundSmsMessageDeliveryReports( bulkId: 'some-bulk-id', messageId: 'some-message-id', limit: 10 ); foreach ($deliveryReports->getResults() ?? [] as $report) { echo $report->getMessageId() . " - " . $report->getStatus()->getName() . "\n"; }
Unicode & SMS preview
Infobip API supports Unicode characters and automatically detects encoding. Unicode and non-standard GSM characters use additional space, avoid unpleasant surprises and check how different message configurations will affect your message text, number of characters and message parts.
use Infobip\Model\SmsPreviewRequest; $previewResponse = $sendSmsApi ->previewSmsMessage( new SmsPreviewRequest( text: 'Let\'s see how many characters will remain unused in this message.' ) ); foreach ($previewResponse->getPreviews() ?? [] as $preview) { echo sprintf( 'Characters remaining: %s, text preview: %s', $preview->getCharactersRemaining(), $preview->getTextPreview() ) . PHP_EOL; }
Receive incoming SMS
If you want to receive SMS messages from your subscribers we can have them delivered to you in real time. When you buy and configure a number capable of receiving SMS, specify your endpoint, as explained in documentation.
e.g. https://{yourDomain}/incoming-sms.
Example of webhook implementation:
use Infobip\ObjectSerializer; use Infobip\Model\SmsInboundMessageResult; $objectSerializer = new ObjectSerializer(); $data = \file_get_contents('php://input'); /** * @var SmsInboundMessageResult $messages */ $messages = $objectSerializer->deserialize($data, SmsInboundMessageResult::class); foreach ($messages->getResults() ?? [] as $message) { echo $message-> getFrom() . " - " . $message-> getCleanText() . "\n"; }
Two-Factor Authentication (2FA)
For the 2FA quick start guide please check these examples.
Send email
For the send email quick start guide please check these examples.
For the WhatsApp quick start guide, view these examples.
Messages API
For the Messages API quick start guide, view these examples.
Moments
For the Moments quick start guide, view these examples.
Versioning
This project follows a pragmatic Semantic Versioning approach.
For full details on how versions are managed, please see our Versioning guide.
Ask for help
Feel free to open an issue on the repository if you see any problem or want to request a feature. As per pull requests, for details check the CONTRIBUTING file related to it - in short, we will not merge any pull requests, this code is auto generated.
This code is auto generated, and we are unable to merge any pull request from here, but we will review and implement changes directly within our pipeline, as described in the CONTRIBUTING file.
For anything that requires our immediate attention, contact us @ support@infobip.com.
infobip/infobip-api-php-client 适用场景与选型建议
infobip/infobip-api-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.91M 次下载、GitHub Stars 达 94, 最近一次更新时间为 2015 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「rest」 「api」 「email」 「sms」 「sdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 infobip/infobip-api-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 infobip/infobip-api-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 infobip/infobip-api-php-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
BlockCypher's PHP SDK for REST API
Helper classes for creating cookie headers
统计信息
- 总下载量: 1.91M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 96
- 点击次数: 32
- 依赖项目数: 11
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-16