atymic/sms-broadcast

用于SMS Broadcast API的PHP客户端

1.1.1 2019-07-15 05:14 UTC

This package is auto-updated.

Last update: 2024-09-15 17:03:59 UTC


README

Build Status StyleCI Latest Stable Version License

这是一个用于SMS Broadcast的简单API客户端。

您可以在这里查看他们的API文档。

安装

composer require atymic/sms-broadcast

使用方法

创建客户端

$client = \Atymic\SmsBroadcast\Factory\ClientFactory::create(
    'username',
    'password',
    '0412345678' // Default sender, optional
);

向单个收件人发送消息

try {
    $response = $client->send('0487654321', 'This is an sms message');
} catch (\Atymic\SmsBroadcast\Exception\SmsBroadcastException $e) {
    echo 'Failed to send with error: ' . $e->getMessage();
}

echo 'SMS sent, ref: ' . $response->getSmsRef();

向多个收件人发送消息

$to = ['0487654321', '0487654322', '0487654323']
$responses = $client->sendMultiple($to, 'This is an sms message');

foreach ($responses as $response) {
    echo $response->hasError()
        ? 'Failed to send SMS: ' . $response->getError()
        : 'SMS sent, ref: ' . $response->getSmsRef();
}

检查短信余额

echo $client->getBalance(); // int(1222)

测试

默认情况下,只运行单元测试。如果您想运行集成测试,将phpunit.dist.xml文件复制到phpunit.xml,并在文件中提供您的SMS Broadcast凭据以及要发送短信的电话号码。

警告 - 集成测试将发送真实的短信消息,所以在CI中不要运行它们。

composer test

待办事项

  • 支持传入消息webhook