vmosoti / bongatech-sms
用于BongaTech API (http://bongatech.co.ke) 的PHP客户端库
v2.0.1
2017-04-15 14:06 UTC
Requires
- php: >=5.6.4
- mashape/unirest-php: 3.*
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: 5.7
This package is auto-updated.
Last update: 2024-09-16 22:47:21 UTC
README
这是一个用于BongaTech SMS API的PHP客户端库 查看Bonga Tech网站了解更多
安装
您可以通过composer安装此包
composer require vmosoti/bongatech-sms
用法
提供变量
Config类需要从系统环境中获取一些变量。这些变量是在SMS类初始化时使用的。在你的.env文件中
BONGATECH_USER_ID=
BONGATECH_PASSWORD=
BONGATECH_SENDER_ID=
BONGATECH_CALL_BACK_URL=
初始化SMS类
初始化
$sms = new \VMosoti\BongaTech\SMS();
或者简单地使用魔法辅助函数
sms() // you have the SMS object
收件人和消息
它们都是数组的数组。即
$recipients = array( array( 'MSISDN' => '0722123456', 'LinkID' => '', 'SourceID' => 'your source id here' ), array( 'MSISDN' => '0775345678', 'LinkID' => '', 'SourceID' => 'source id for this here' ) );
和消息
$messages = array( array( 'Text' => 'Message 1 goes here' ), array( 'Text' => 'Message 2 goes here' ) );
向单个收件人发送
$message = array( array( 'Text' => 'This message is for a single recipient' ) ); $recipient = array( array( 'MSISDN' => '0722123456', 'LinkID' => '', 'SourceID' => 'your source id here' ) ); $response = $sms->bulk()->toOne()->send($recipient, $message);
或者使用辅助函数
$response = sms()->bulk()->toOne()->send($recipient, $message);
上面的代码返回一个单一的 Response 对象
向多个收件人发送相同的短信
$message = array( array( 'Text' => 'This message goes to many recipients' ) ); $recipients = array( array( 'MSISDN' => '0722123456', 'LinkID' => '', 'SourceID' => 'source id for recipient 1' ), array( 'MSISDN' => '0713678900', 'LinkID' => '', 'SourceID' => 'source id for recipient 2' ), ); $responses = $sms->bulk()->toMany()->send($recipients, $message);
向每个收件人发送不同的短信
$messages = array( array( 'Text' => 'This is message for recipient 1' ), array( 'Text' => 'This is message for recipient 2' ) ); $recipients = array( array( 'MSISDN' => '0722123456', 'LinkID' => '', 'SourceID' => 'source id for recipient 1' ), array( 'MSISDN' => '0713678900', 'LinkID' => '', 'SourceID' => 'source id for recipient 2' ), ); $responses = $sms->bulk()->toMany()->send($recipients, $messages);
上面的两个示例返回一个包含 Response 对象的数组。因此
foreach($responses as $response){ $response->getCode(); ------ }
查询短信单元余额
$response = SMS::getBalance();
或者直接在辅助函数中使用
get_balance();
$response
是 Response 对象。因此
$response->getBalance()
投递报告
在你的回调中
$response = \VMosoti\BongaTech\DeliveryReport::get();
它返回 Response 对象,
因此
$response->getReport();
$response->getMessageID();
$response->getCorrelator();
$response->getSourceID();
在此处查看所有可能的报告 这里
异常
捕获 \VMosoti\BongaTech\Exceptions\BongaTechException;
更新日志
请参阅 CHANGELOG 了解最近更改的更多信息。
贡献
建议、拉取请求、错误报告和代码改进都欢迎。请随时联系。
安全性
如果您发现任何与安全性相关的错误,请通过电子邮件 vincent@vmosoti.com 联系。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件。