承接 caherrera/infobip-api-php-client 相关项目开发

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

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

caherrera/infobip-api-php-client

Composer 安装命令:

composer require caherrera/infobip-api-php-client

包简介

Infobip SMS library for PHP

README 文档

README

Prerequisites

Installation

For using Infobip API PHP client in your project, you have to add the following to your composer.json file:

"require": {
	"caherrera/infobip-api-php-client": "dev-master"
}

and run composer install command inside the project's root folder.

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.

Running examples

Before you start any of the examples, you have to populate specific data (sender address, receiver address, etc.) to caherrera/examples/examples.php file.

Then, you should uncomment the example you want to test and run the PHP script with your username and password (in plain text) as arguments like the following:

php caherrera/examples/examples.php YOUR_USERNAME YOUR_PASSWORD

Basic messaging example

The first thing that needs to be done is to include autoload.php and to initialize the messaging client:

require_once '<PATH-TO-VENDOR-FOLDER>/autoload.php';

$client = new infobip\api\client\SendSingleTextualSms(new infobip\api\configuration\BasicAuthConfiguration(USERNAME, PASSWORD));

You are basically logging in to Infobip, so an exception will be thrown if the username and/or password are incorrect.

The next step is to prepare the message:

$requestBody = new infobip\api\model\sms\mt\send\textual\SMSTextualRequest();
$requestBody->setFrom(FROM);
$requestBody->setTo(TO);
$requestBody->setText("This is an example message.");

Now you are ready to send the message:

$response = $client->execute($requestBody);

Messaging with notification push example

For sending SMS and expecting delivery report to be pushed to some notify URL, you have to initialize the messaging client:

$client = new infobip\api\client\SendMultipleTextualSmsAdvanced(new infobip\api\configuration\BasicAuthConfiguration(USERNAME, PASSWORD));

And prepare the advanced message:

$destination = new infobip\api\model\Destination();
$destination->setTo(TO);

$message = new infobip\api\model\sms\mt\send\Message();
$message->setFrom(FROM);
$message->setDestinations([$destination]);
$message->setText("This is an example message.");
$message->setNotifyUrl(NOTIFY_URL);

$requestBody = new infobip\api\model\sms\mt\send\textual\SMSAdvancedTextualRequest();
$requestBody->setMessages([$message]);

When the delivery notification is pushed to your server as a HTTP POST request, you could process body of the message with the following code:

$mapper = new JsonMapper();
$responseObject = $mapper->map(json_decode($responseBody), new infobip\api\model\sms\mt\reports\SMSReportResponse());

for ($i = 0; $i < count($responseObject->getResults()); ++$i) {
	$result = $responseObject->getResults()[$i];
	echo "Message ID: " . $result->getMessageId() . "\n";
	echo "Sent at: " . $result->getSentAt()->format('y-M-d H:m:s T') . "\n";
	echo "Receiver: " . $result->getTo() . "\n";
	echo "Status: " . $result->getStatus()->getName() . "\n";
	echo "Price: " . $result->getPrice()->getPricePerMessage() . " " . $result->getPrice()->getCurrency() . "\n\n";
}

Sending message with special characters example

If you want to send message with special characters, this is how you initialize the client and prepare your message:

$client = new infobip\api\client\SendMultipleTextualSmsAdvanced(new infobip\api\configuration\BasicAuthConfiguration(USERNAME, PASSWORD));

$destination = new infobip\api\model\Destination();
$destination->setTo(TO);

$language = new infobip\api\model\sms\mt\send\Language();
//specific language code (TR stands for Turkish)
$language->setLanguageCode("TR");
//use single shift table for specific language ('false' or 'true')
$language->setSingleShift(true);
//use locking shift table for specific language ('false' or 'true')
$language->setLockingShift(false);

$message = new infobip\api\model\sms\mt\send\Message();
$message->setFrom(FROM);
$message->setDestinations([$destination]);
$message->setText("Artık Ulusal Dil Tanımlayıcısı ile Türkçe karakterli smslerinizi rahatlıkla iletebilirsiniz.");
$message->setLanguage($language);

$requestBody = new infobip\api\model\sms\mt\send\textual\SMSAdvancedTextualRequest();
$requestBody->setMessages([$message]);

Currently supported languages (with their language codes) are: Spanish - "ES", Portuguese - "PT", Turkish - "TR".

Number Context example

Initialize the number context query client:

$client = new infobip\api\client\NumberContextQuery(new infobip\api\configuration\BasicAuthConfiguration(USERNAME, PASSWORD));

Create request body:

$requestBody = new infobip\api\model\nc\query\NumberContextRequest();
$requestBody->setTo(TO);

Retrieve the number context:

$response = $client->execute($requestBody);

$numberContext = $response->getResults()[0];
echo "Phone number: " . $numberContext->getTo() . "\n";
echo "MccMnc: " . $numberContext->getMccMnc() . "\n";
echo "Original country prefix: " . $numberContext->getOriginalNetwork()->getCountryPrefix() . "\n";
echo "Original network prefix: " . $numberContext->getOriginalNetwork()->getNetworkPrefix() . "\n";
echo "Serving MSC: " . $numberContext->getServingMSC();

Number Context with notification push example

Similar to the previous example, but this time you must set the notification URL where the result will be pushed:

$client = new infobip\api\client\NumberContextNotify(new infobip\api\configuration\BasicAuthConfiguration(USERNAME, PASSWORD));

$requestBody = new infobip\api\model\nc\notify\NumberContextRequest();
$requestBody->setTo(TO);
$requestBody->setNotifyUrl(NOTIFY_URL);

$response = $client->execute($requestBody);

When the number context notification is pushed to your server as a HTTP POST request, you could process the body of the message with the following code:

$mapper = new JsonMapper();
$responseObject = $mapper->map(json_decode($responseBody), new infobip\api\model\nc\query\NumberContextResponse());

$numberContext = $responseObject->getResults()[0];
echo "Phone number: " . $numberContext->getTo() . "\n";
echo "MccMnc: " . $numberContext->getMccMnc() . "\n";
echo "Original country prefix: " . $numberContext->getOriginalNetwork()->getCountryPrefix() . "\n";
echo "Original network prefix: " . $numberContext->getOriginalNetwork()->getNetworkPrefix() . "\n";
echo "Status: " . $numberContext->getStatus()->getName();

Retrieve inbound messages example

The client that has to be initialized is:

$client = new infobip\api\client\GetReceivedMessages(new infobip\api\configuration\BasicAuthConfiguration(USERNAME, PASSWORD));

Then you have to create execution context:

$context = new infobip\api\model\sms\mo\reports\GetReceivedMessagesExecuteContext;

If you want to filter inbound messages, you can do it by setting the value to any of execute context class fields.

The response type will be \infobip\api\model\sms\mo\reports\MOReportResponse:

$response = $client->execute($context);

for ($i = 0; $i < count($response->getResults()); ++$i) {
	$result = $response->getResults()[$i];
	echo "Message ID: " . $result->getMessageId() . "\n";
	echo "Received at: " . $result->getReceivedAt()->format('y-M-d H:m:s T') . "\n";
	echo "Sender: " . $result->getFrom() . "\n";
	echo "Receiver: " . $result->getTo() . "\n";
	echo "Message text: " . $result->getText() . "\n\n";
}

Inbound message push example

The subscription to receive inbound messages can be set up on Infobip platform. When the inbound message notification is pushed to your server as a HTTP POST request, you could process body of the message with the following code:

$mapper = new JsonMapper();
$responseObject = $mapper->map(json_decode($responseBody), new infobip\api\model\sms\mo\reports\MOReportResponse());

$result = $responseObject->getResults()[0];
echo "Message ID: " . $result->getMessageId() . "\n";
echo "Received at: " . $result->getReceivedAt()->format('y-M-d H:m:s T') . "\n";
echo "Sender: " . $result->getFrom() . "\n";
echo "Receiver: " . $result->getTo() . "\n";
echo "Message text: " . $result->getText() . "\n";
echo "Keyword: " . $result->getKeyword() . "\n";
echo "Clean text: " . $result->getCleanText() . "\n";
echo "Sms count: " . $result->getSmsCount() . "\n";

License

This library is licensed under the Apache License, Version 2.0

caherrera/infobip-api-php-client 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-02-12