Skip to content

koriUA/php-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP SDK for FastSMS API.

PHP library to access FastSMS api. Thank you for choosing FastSMS
Latest Stable Version Total Downloads Latest Unstable Version License Build Status DIRECTORY STRUCTURE

src/                 core wrapper code
tests/               tests of the core wrapper code

REQUIREMENTS

The minimum requirement by FastSMS wrapper is that your Web server supports PHP 5.4.

DOCUMENTATION

FastSMS has a Knowledge Base and a Developer Zone which cover every detail of FastSMS API.

INSTALLATION

Add to composer

"require": {
    ...
    "fastsms/sdk:": "*",
    ...
}

USAGE

Init SDK

Your token (found in your settings within NetMessenger)

$FastSMS = new FastSMS\Client('your token');

or

use FastSMS\Client;
...
$FastSMS = new Client('your token');
...

Wrap errors

List all API codes found in docs

use FastSMS\Client;
use FastSMS\Exception\ApiException;
...
$client = new Client('your token');
try {
    $credits = $client->credits->getBalance();
} catch (ApiException $aex) {
    echo 'API error #' . $aex->getCode() . ': ' . $aex->getMessage();
} catch (Exception $ex) {
    echo $ex->getMessage();
}

Actions

Credits

Checks your current credit balance.

$credits = $client->credits->balance; //return float val
echo number_format($credits, 2); //example show 1,000.00

Send

Sends a message. More information read this

...
use FastSMS\Model\Message;
...
// Init Message data
$data = [
    //set
    'destinationAddress' => 'Phone number or multiple numbers in array',
    //or
    'list' => 'Your contacts list',
    //or
    'group' => 'Your contacts group'

    'sourceAddress' => 'Your Source Address',
    'body' => 'Message Body', //Note: max 459 characters
    //optionals
    'scheduleDate' => time() + 7200, //now + 2h
    'validityPeriod' => 3600 * 6, //maximum 86400 = 24 hours
];
$result = $client->message->send($data);

Check message status

Check send message status. More information read this

$result = $client->message->status($messageId);// Message Id must be integer

Create User

Create new child user. Only possible if you are an admin user. More information read this

...
use FastSMS\Model\User;
// Init user data
$data = [
    'childUsername' => 'Username',
    'childPassword' => 'Password',
    'accessLevel' => 'Normal', //or 'Admin'
    'firstName' => 'John',
    'lastName' => 'Doe',
    'email' => '[email protected]',
    'credits' => 100,
    //optionals
    'telephone' => 15417543010, // integer
    'creditReminder' => 10,
    'alert' => 5, //5 days
];
$result = $client->user->create($data);

Update Credits

Transfer credits to/from a child user. Only possible if you are an admin user. More information read this

...
use FastSMS\Model\User;
// Init update user data
$data = [
    'childUsername' => 'Exist Username',
    'quantity' => -5, //The amount of credits to transfer.
];
$user = new User($data);
$result = $client->user->update($user);

Reports

Retrieve the data from a report. More information read this Aviable types:

  • ArchivedMessages
  • ArchivedMessagesWithBodies
  • ArchivedMessagingSummary
  • BackgroundSends
  • InboundMessages
  • KeywordMessageList
  • Messages
  • MessagesWithBodies
  • SendsByDistributionList
  • Usage
...
use FastSMS\Model\Report;
...
// Init Report params
$data = [
    'reportType' => 'Messages',
    'from' => time() - 3600 * 24 * 30,
    'to' => time()
];
// Get report
$result = $client->report->get($data);

Add contact(s)

Create contact(s). More information read this

...
use FastSMS\Model\Contact;
...
// Init Contacts data
$data = [
    'contacts' => [
        ['name' => 'John Doe 1', 'number' => 15417543011, 'email' => '[email protected]'],
        ['name' => 'John Doe 2', 'number' => 15417543012, 'email' => '[email protected]'],
        ['name' => 'John Doe 3', 'number' => 15417543013, 'email' => '[email protected]'],
    ],
    'ignoreDupes' => false,
    'overwriteDupes' => true
];
// Get report
$result = $client->contact->create($data);

Delete All Contacts

More information read this

...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->contact->deleteAll();

Delete All Groups

More information read this

...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->deleteAll();

Empty Group

Remove all contacts from the specified group. More information read this

...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->empty('Group Name');

Delete Group

Delete the specified group. More information read this

...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->delete('Group Name');

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%