PHP code example of smsfactor / smsfactor-php-sdk

1. Go to this page and download the library: Download smsfactor/smsfactor-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

smsfactor / smsfactor-php-sdk example snippets




\SMSFactor\SMSFactor::setApiToken('your token');

$response = \SMSFactor\Message::send([
	'to' => '33601000000',
	'text' => 'Did you ever dance whith the devil in the pale moonlight ?'
]);
print_r($response->getJson());

$response = \SMSFactor\Account::credits();

$response = \SMSFactor\Account::get();

$response = \SMSFactor\Account::subAccounts();

$response = \SMSFactor\Account::create([
	'account' => [
		"firstname" => "firstname",
		"lastname" => "lastname",
		"city" => "city",
		"phone" => "phone",
		"address1" => "address",
		"zip" => "zip",
		"country_code" => "country code",
		"isChild" => 0, //Is the account a subaccount ?
		"unlimited" => 0, //If isChild, should the subaccount use the parent's credits
		'email' => '[email protected]',
		'password' => 'password'
	]
]);

$delay = date('Y-m-d H:i:s', strtotime('+1 hour')); // now + 1 hour
$response = \SMSFactor\Campaign::send([
    'sms' => [
	    'message' => [
		    'text' => 'test skd php',
		    'pushtype' => 'alert', //alert(default) or marketing
		    'sender' => 'SDK', //Optional
		    'delay' => $delay //Optional. Omit for immediate send
	    ],
	    'recipients' => [
		    'gsm' => [
			    [
				    'value' => '33601000000'
			    ]
		    ]
	    ]
    ]
], false); // True to simulate the campaign (no SMS sent)

$delay = date('Y-m-d H:i:s', strtotime('+1 hour')); // now + 1 hour
$response = \SMSFactor\Campaign::sendToLists([
    'sms' => [
	    'message' => [
		    'text' => 'test skd php',
		    'pushtype' => 'alert', //alert(default) or marketing
		    'sender' => 'SDK', //Optional
		    'delay' => $delay //Optional. Omit for immediate send
	    ],
	    'lists' => [
		    [
			    'value' => 'your_list_id'
		    ]
	    ]
    ]
], false); // True to simulate the campaign (no SMS sent)

$response = \SMSFactor\Campaign::get($response->ticket);

$response = \SMSFactor\Campaign::cancel($response->ticket);

$response = \SMSFactor\Campaign::history(['length' => 5]); //Get the last 5 campaigns

$response = \SMSFactor\ContactList::create([
    'list' => [
	    'name' => 'Your list name',
	    'contacts' => [
		    'gsm' => [
			    [
				    'value' => '33600000001',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ],
			    [
				    'value' => '33600000002',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ]
		    ]
	    ]
    ]
]);
$list_id = $response->id

$response = \SMSFactor\ContactList::addContacts([
    'list' => [
	    'list_id' => $list_id
	    'contacts' => [
		    'gsm' => [
			    [
				    'value' => '33600000003',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ],
			    [
				    'value' => '33600000004',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ]
		    ]
	    ]
    ]
]);

$response = \SMSFactor\ContactList::get($list_id);

$response = \SMSFactor\ContactList::removeContact($contact_id); //use Get list to get contact id

$response = \SMSFactor\ContactList::deduplicate($list_id);

$response = \SMSFactor\ContactList::all();

$response = \SMSFactor\ContactList::delete($list_id);

 $response = \SMSFactor\ContactList::addToBlacklist([
	'blacklist' => [
		'contacts' => [
			'gsm' => [
				[
					'value' => '33600000003'
				],
				[
					'value' => '33600000004'
				]
			]
		]
	]
]);

$response = \SMSFactor\ContactList::blacklist();

$response = \SMSFactor\ContactList::addToNpai([
	'npai' => [
		'contacts' => [
			'gsm' => [
				[
					'value' => '33600000003'
				],
				[
					'value' => '33600000004'
				]
			]
		]
	]
]);

$response = \SMSFactor\ContactList::npai();

$response = \SMSFactor\Token::create([
    'token' => [
	    'name' => 'token sdk'
    ]
]);
$token = $response->token;
$token_id = $response->token_id;

$response = \SMSFactor\Token::all();

$response = \SMSFactor\Token::delete($token_id);

$response = \SMSFactor\Webhook::create([
	'webhook' => [
		'type' => 'DLR',
		'url' => 'https://yourserverurl.com'
	]
]);
$webhook_id = $response->webhook->webhook_id;

$response = \SMSFactor\Webhook::all();

$response = \SMSFactor\Webhook::update($webhook_id, [
    'webhook' => [
	    'type' => 'MO',
	    'url' => 'https://yourserverurl.net'
    ]
]);

$response = \SMSFactor\Webhook::delete($webhook_id);