src/ core wrapper code
tests/ tests of the core wrapper code
The minimum requirement by FastSMS wrapper is that your Web server supports PHP 5.4.
FastSMS has a Knowledge Base and a Developer Zone which cover every detail of FastSMS API.
Add to composer
"require": {
...
"fastsms/sdk:": "*",
...
}
Your token (found in your settings within NetMessenger)
$FastSMS = new FastSMS\Client('your token');
or
use FastSMS\Client;
...
$FastSMS = new Client('your token');
...
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();
}
Checks your current credit balance.
$credits = $client->credits->balance; //return float val
echo number_format($credits, 2); //example show 1,000.00
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 send message status. More information read this
$result = $client->message->status($messageId);// Message Id must be integer
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);
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);
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);
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);
More information read this
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->contact->deleteAll();
More information read this
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->deleteAll();
Remove all contacts from the specified group. More information read this
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->empty('Group Name');
Delete the specified group. More information read this
...
use FastSMS\Model\Contact;
...
// Get report
$result = $client->group->delete('Group Name');