engin / iletimerkezi-php
iletimerkezi.com PHP 客户端库
dev-master
2017-01-26 13:06 UTC
Requires
- php: ^5.3.2 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^4.5 || ^5.0.5
- phpunit/phpunit-mock-objects: ^2.3 || ^3.0
- symfony/console: ^3.2
This package is not auto-updated.
Last update: 2024-09-18 19:17:25 UTC
README
v01 版本路线图
- 发送短信
- 处理错误
- 查询已发送短信报告
- 查询账户余额
- 查询可用发送者(即发送者)
示例
让我们配置和初始化一个客户端
<?php require_once 'vendor/autoload.php'; use Emarka\Sms\Client; $client = Client::createClient([ 'api_key' => '<xyz-etc>', // generate api key / secret pair from account -> settings 'secret' => '<secret>', // don't ever expose this guy. 'sender' => 'Engin Dumlu', 'local_timezone' => 'Europe/Istanbul', ]);
发送简单消息 - 示例
- 简单
$client->send('5321112233', 'Hello World'); // this is the most basic usage of sending sms
- 简单,发送给多个收件人
$client->send(['5321112233', '5321112234'], 'Hello World'); // same text to multiple recipients
- 每个收件人具有不同文本的多个收件人
$client->send( [ '05321112233' => 'Hello World', '05321112234' => 'Selam Dünya', '05321112235' => '你好,世界' ], // recipients with messages null, // [ 'encoding' => 'unicode', // text encoding ] );
可选参数
消息编码:可以是 gsm8 | 土耳其 | unicode 之一。或者保留为账户默认值。
$client->send('5321112233', 'Türkçe sms göndermek bu kadar zor olmamalı.', [ 'encoding' => 'turkish', // text encoding ]);
未来投递:可以是任何未来的日期 [待办:统一和简单的日期解析 ]
$client->send('5321112233', 'Meet me at the chinese restaurant!', [ 'send_at' => '2 hours later', // deliver sms at 2 hours later ]);
更改发送者名称 [又称:发送者]
$client->send('5321112233', 'Authentication verify. Please enter the code: '.mt_rand(9999, 99999), [ 'sender' => 'OTP Verify', // change the sender ]);
基本报告与跟踪 ID(即订单 ID)
$tracking_id = $client->send(['5321112233', '5321112234', '5321112234'], 'Hello reporting..'); $reporter = $client->reportIterator($tracking_id); echo 'report id: '. $reporter->getId().PHP_EOL; echo 'sender: '. $reporter->sender().PHP_EOL; echo 'report status: '. $reporter->status()->description().PHP_EOL; echo 'total recipients: '. $reporter->totalRecipients().PHP_EOL; echo 'total delivered: '. $reporter->totalDelivered().PHP_EOL; echo 'total failed: '. $reporter->totalFailed().PHP_EOL; echo 'total enroute: '. $reporter->totalEnroute().PHP_EOL; echo 'send at: '. $reporter->sendAt().PHP_EOL; echo 'submit at: '. $reporter->submitAt().PHP_EOL;
遍历收件人列表
$tracking_id = $client->send('5321112233', 'Hello World'); // later, you can query delivery status of the messages $reporter = $client->reportIterator($tracking_id); while ($reporter->next()) { $reporter->each(function ($number, Emarka\Sms\StateInterface $state) { echo $number.' -> '.$state->state().' / '.$state->description().PHP_EOL; }); }
+905321131913 -> TEXT_ENROUTE / Message is being sent or waiting for delivery report.
可用发送者(发送者名称)
$senders = $client->originators(); print_r($senders);
示例输出
Array
(
[0] => Engin Dumlu
)
查询账户当前余额
echo $client->balance()->humanReadable();
示例输出
973 TL
黑名单操作
将号码添加到黑名单
$status = $client->addToBlacklist('5321112233'); if ($status->isSuccess()) { // number added to blacklist } else { // something went wrong; echo $status->description().PHP_EOL; }
从黑名单中移除号码
$status = $client->removeFromBlacklist('5321112233'); if ($status->isSuccess()) { // number removed from blacklist } else { // something went wrong; echo $status->description().PHP_EOL; }
获取被黑的列表
$client->blacklistIterator()->each(function ($number) { echo $number.' is in the blacklist.'.PHP_EOL; });
开源
我们喜欢从开源社区获得反馈和贡献。请随时贡献。