quince/kavenegar-client

用于连接到kavenegar.com API并发送短信的PHP客户端。

1.2.0 2016-04-09 08:56 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:04:02 UTC


README

用于连接到kavenegar.com API并发送短信的PHP客户端。

安装

然后,您必须修改您的 composer.json 文件并运行 composer update 以将最新版本的包包含到项目中。

"require": {
    "quince/kavenegar-client": "~1.0"
}

或者您可以在终端中运行 composer require 命令。

composer require quince/kavenegar-client

用法

<?php

$apiKey = '{API_KEY}';
$senderNumber = '10004346';

$client = Quince\kavenegar\ClientBuilder::build($apiKey, $senderNumber);

$client->send('09123456789', 'سلام چطوری؟');

Laravel集成

此包支持Laravel 5.1及以上版本。

将以下行添加到您的laravel config/app.php

'providers' => [
    //...

    Quince\kavenegar\Providers\ServiceProvider::class,
]

然后在您的命令行中运行以下命令

php artisan vendor:publish --provider="Quince\kavenegar\Providers\ServiceProvider"

名为 kavenegar.php 的配置文件可以在 config 文件夹中找到。如果您想的话,可以配置API密钥和默认发送者号码。

Laravel用法

通过使用laravel服务提供者,您可以在类的构造函数中自动绑定客户端。

use Quince\kavenegar\Client;

class SmsController extend Controller
{

    protected $client;
    
    public function __construct(Client $client)
    {
        $this->client = $client
    }
    
    public function send()
    {
        $this->client->send('09123456789', 'سلام جطوری؟');
    }
    
}

方法描述

Client::send()

向指定的接收者电话号码发送消息。

// Send a message to `09123456789` in 4/9/2016, 1:00:43 AM
$client->send('09123456789', 'The text to send', 1460147443, 0, '12', '30004346');

// Send a message to multiple receptors
$client->send(['09123456789', '09356789124', '09213456789'], 'The text to send', 1460147443, 0, '12', '30004346');

更多信息

Client::bulkSend()

向多个接收者电话号码发送批量消息。

// Send multiple message to multiple receptor
$client->bulkSend(
    ['09123456789', '09356789124', '09213456789'],
    ['Text to send to 09123456789', 'Text to send to 09367891245', 'Text to send to 09213456789'],
    1460147443,
    [0, 1, 2],
    ['12', '13', '14'],
    ['10004346', '20004346', '30004346']
);

更多信息

Client::getMessageStatus()

通过消息ID获取发送消息的状态。

// Get delivery status of a message
$client->getMessageStatus('8792343');

// Get delivery status of multiple messages
$client->getMessageStatus(['8792343', '8792344', '8792345']);

更多信息

Client::getMessageStatusByLocalId()

通过发送时设置的本地ID获取发送消息的状态。

// Get delivery status of a message
$client->getMessageStatus('13');

// Get delivery status of multiple messages
$client->getMessageStatus(['13', '14', '15']);

更多信息

Client::getMessageDetail()

通过消息ID获取消息的详细信息。

// Get details of a message
$client->getMessageDetail('8792343');

// Get details of multiple messages
$client->getMessageDetail(['8792343', '8792344', '8792345']);

更多信息

Client::getOutbox()

获取指定日期范围内的所有已发送消息(最多3000条消息)。

// Get outbox messages sent between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getOutbox(1460140000, 1460147443, 0);

更多信息

Client::getRecentOutbox()

获取最近发送的消息列表(最多3000条消息)。

// Get 20 latest sent messages from all sender numbers
$client->getRecentOutbox(20, 0);

更多信息

Client::getOutboxCount()

获取指定范围内的发送消息数量。

// Get outbox messages count between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getOutboxCount(1460140000, 1460147443, 0);

更多信息

Client::cancelMessage()

取消待发送的消息。

// Cancel sending of message with id of 8792343
$client->cancelMessage('8792343');

更多信息

Client::getInbox()

获取接收消息列表(每个请求100条消息)。

// Get all unread messages sent to all lines
$client->getInbox(false, 0);

更多信息

Client::getInboxCount()

获取收件箱中的消息数量。

// Get inbox messages count between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getInboxCount(1460140000, 1460147443, 0, false);

更多信息

Client::phoneCountByPostalCode()

按运营商分类获取邮编区域内的电话号码数量。

// Get phone count in 11252 postal code area
$client->phoneCountByPostalCode('11252');

更多信息

Client::sendByPostalCode()

向邮编区域内的电话号码发送消息。

// Send a message to all MCI phones and 1000 random MTN phones in 11252 postal code area
// scheduled to send in 4/9/2016, 1:00:43 AM with sender number of 30004346
$client->sendByPostalCode(
    '11252',
    'Testing send by postal code',
    0,
    0,
    -1,
    1000,
    1460147443,
    '30004346'
);

更多信息

Client::getAccountInfo()

获取账户信息。

// Get info of current account
$client->getAccountInfo();

更多信息

Client::getAccountConfigs()

获取账户配置。

// Get current account configuration
$client->getAccountConfigs();

更多信息

Client::setAccountConfigs()

设置账户配置。

// Enable apilogs and daily reports
// and set default sender to 30004346
// and disable resend when failing to send a message
$client->setAccountConfigs([
    'apilogs'       => 'enabled',
    'dailyreport'   => 'enabled',
    'defaultsender' => '30004346',
    'resendfailed'  => 'disabled'
]);

更多信息

Client::sendVerificationCode()

发送验证码、密码、授权码等。

// send a code to 09123456789 with licence_template template
$client->sendVerificationCode('09123456789', 'EA-958423', 'licence_template');

更多信息