kickstartph/semaphore-client

访问 Semaphore SMS API 的包装器

0.5 2015-07-15 14:56 UTC

README

Semaphore Client 是一个用于访问 Semaphore SMS API 的 PHP 包装器

目录

安装

composer require kickstartph/semaphore-client

基本使用

发送消息

<?php
    require_once( 'vendor/autoload.php' );

    use Semaphore\SemaphoreClient;
    $client = new SemaphoreClient( '{YOUR_API_KEY}', '{OPTIONAL_SENDER_NAME}' ); //Sender Name defaults to SEMAPHORE
    echo $client->send( '09991234567', 'Your message' );

发送命令也可以通过客户端覆盖发送者 ID

    echo $client->send( '09991234567', 'Your message', '{NEW_SENDER_ID}' );

批量消息(最多 1,000 个号码)也可以通过相同的 API 调用发送,只需提供以逗号分隔的号码集

    echo $client->send( '09991234567,09997654321,', 'Your message' );

响应将包含每个发送消息的记录

[
  {
    "message_id": 1234567,
    "user_id": 99556,
    "user": "user@your.org",
    "account_id": 90290,
    "account": "Your Account Name",
    "recipient": "09991234567",
    "message": "The message you sent",
    "sender_name": "SEMAPHORE",
    "network": "Globe",
    "status": "Queued",
    "type": "Single",
    "source": "Api",
    "created_at": "2016-01-01 00:01:01",
    "updated_at": "2016-01-01 00:01:01"
  }
]

检索消息

您一次可以检索最多 100 条发送消息,支持通过传递可选的 $page 变量进行分页

    //Will return the results for page 2 of sent messages
    echo $client->messages( [ 'limit'=> 100 , 'page' => 2 ] ); 

####按日期范围检索消息

    //Use any date format str_to_time() supports
    echo $client->messages( 'startDate' => '2016-10-01, '2016-10-31' );  

####按电信网络检索消息

    //Returns all messages sent to recipients on the Globe network
    echo $client->messages( ['globe'] ); 

####检索消息支持的过滤条件

   $options = [
        'limit' => 100,
        'page' => 1,
        'sendername' => 'SEMAPHORE',
        'startDate' => '2016-01-01',
        'endDate' => '2016-02-01',
        'network' => 'globe',
        'status' => 'success'
   ];

其他功能

以下是可以调用的其他调用:####账户信息

    echo $client->account();
{
  "account_id": 12345,
  "account_name": "Your Organization",
  "status": "Active",
  "credit_balance": 5000
}

####用户

    echo $account->users();
[
  {
    "user_id": 12345,
    "email": "owner@your.org",
    "role": "Owner"
  },
  {
    "user_id": 54321,
    "email": "someguy@your.org",
    "role": "User"
  }
]

####发送者名称

    echo $account->sendernames();
[
  {
    "name":"Semaphore",
    "status":"Active",
    "created":"2016-01-01 00:00:01"
  },
  {
    "name":"Kickstart",
    "status":"Active",
    "created":"2016-01-01 00:00:01""
  }
]

####交易

    echo $account->transactions();