ossycodes/nigeriabulksms-php

用于PHP的Nigeriabulksms REST API客户端

v1.1.0 2023-09-21 17:58 UTC

This package is auto-updated.

Last update: 2024-09-21 20:43:50 UTC


README

此仓库包含Nigeriabulksms API的PHP开源客户端。文档可以在以下地址找到:https://nigeriabulksms.com/sms-gateway-api-in-nigeria/

Latest Version on Packagist Total Downloads GitHub Actions

要求

  • 注册 免费Nigeriabulksms账户
  • 注册后,您的用户名和密码将用于API的验证
  • Nigeriabulksms PHP API客户端需要PHP >= 7.4。

安装

Composer安装

  • 下载Composer
  • 运行 composer require ossycodes/nigeriabulksms-php

手动安装

当您不使用Composer时。您可以git checkout或下载此仓库并手动包含Nigeriabulksms API客户端。

用法

我们在src/Examples目录中放置了一些自解释的示例,但以下是快速了解其工作原理的概述。首先,您需要设置一个Nigeriabulksms\Client。请确保将YOUR_USERNAMEYOUR_PASSWORD替换为您的真实凭证。

require 'autoload.php';

$config = \Ossycodes\Nigeriabulksms\Configuration::getDefaultConfiguration()
            ->setUsername('YOUR_USERNAME')
            ->setPassword('YOUR_PASSWORD')
            ->setTimeout(10) //optional defaults to 10
            ->setConnectionTimeout(2); //optional defaults to 2

$client = new \Ossycodes\Nigeriabulksms\Client($config);

这很简单。现在我们可以查询服务器以获取信息。让我们以获取您的余额概览为例

try {

    // Get your balance
    $balance = $client->balance->read();

    var_dump($balance);
    
} catch (\Ossycodes\Nigeriabulksms\Exceptions\AuthenticateException $e) {

    // That means that your username and/or password is incorrect
    echo 'invalid credentials';

}
catch (\Ossycodes\Nigeriabulksms\Exceptions\BalanceException $e) {

    // That means that your balance is insufficient
    echo 'insufficient balance';

}
catch (\Exception $e) {
 
 var_dump($e->getMessage());

}

发送文本短信消息

require_once(__DIR__ . '/../autoload.php');

$config = \Ossycodes\Nigeriabulksms\Configuration::getDefaultConfiguration()
    ->setUsername('YOUR_USERNAME')
    ->setPassword('YOUR_PASSWORD')
    ->setTimeout(10) //optional defaults to 10
    ->setConnectionTimeout(2); //optional defaults to 2

$client = new \Ossycodes\Nigeriabulksms\Client($config);

try {

    $message = new \Ossycodes\Nigeriabulksms\Objects\TextMessage();
    $message->sender = 'YOUR_SENDER_NAME';
    $message->recipients = '2342222222222';
    $message->body =  'body of text message goes in here'; //should be less than 160 characters
    
    //send the text sms message
    $response = $client->message->send($message);
    
    var_dump($response);

} catch (\Ossycodes\Nigeriabulksms\Exceptions\AuthenticateException $e) {

    // That means that your username and/or password is incorrect
    echo 'invalid credentials';

} catch (\Ossycodes\Nigeriabulksms\Exceptions\BalanceException $e) {

    // That means that your balance is insufficient
    echo 'insufficient balance';

} catch (\Ossycodes\Nigeriabulksms\Exceptions\RequestDeniedException $e) {

    // That means that you do not have permission to perform this action
    echo 'this action is not permitted';

} catch (\Exception $e) {

    var_dump($e->getMessage());

}

文档

完整文档、说明和示例可在以下地址找到:https://nigeriabulksms.com/sms-gateway-api-in-nigeria/

测试

composer test

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全

如果您发现任何安全相关的问题,请通过电子邮件osaigbovoemmanuel1@gmail.com而不是使用问题跟踪器。

致谢

许可协议

MIT许可协议(MIT)。有关更多信息,请参阅许可文件

如何表达感谢?

请给我买杯咖啡https://www.paypal.com/paypalme/osaigbovoemmanuel,留下一个星星并在Twitter上关注我。