Skip to content
Mateusz Drost edited this page Aug 10, 2015 · 19 revisions

Examples

Sending messages

Sends an SMS message

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('login');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsapi = new \SMSApi\Api\SmsFactory();
$smsapi->setClient($client);

try {

    $actionSend = $smsapi->actionSend();

    $actionSend->setTo('600xxxxxx'); // Numer odbiorcy w postaci 48xxxxxxxxx lub xxxxxxxxx
    $actionSend->setText('Treść wiadomości w UTF-8');
    $actionSend->setSender('Nazwa Nadawcy'); // Nazwa musi zostać pierw dodana przez panel, wpisując ECO zostanie wysłana wiadomość ECO

    $response = $actionSend->execute();

    foreach( $response->getList() as $status ) {
        echo  $status->getNumber() . ' ' . $status->getPoints() . ' ' . $status->getStatus();
    }
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Sends an MMS message

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsapi = new \SMSApi\Api\MmsFactory();
$smsapi->setClient($client);

try {

    $actionSend = $smsapi->actionSend();

	$smil= '<smil><head><layout><root-layout height="600" width="425"/> <region
		id="Image" top="0" left="0" height="100%" width="100%"
		fit="meet"/></layout></head><body><par dur="5000ms"><img
		src="http://www.smsapi.pl/assets/img/mms.jpg" region="Image"></img></par></body></smil>';


    $actionSend->setTo('Numer odbiorcy'); // numer odbiorczy w postaci 48xxxxxxxxx lub xxxxxxxxx
    $actionSend->setSubject('Temat MMS-a'); //Tekst powinien być podowany w kodowaniu UTF-8
	$actionSend->setSmil($smil); //Wiadomość MMS w formacie SMIL

    $response = $actionSend->execute();

    foreach( $response->getList() as $status ) {
        echo  $status->getNumber() . ' ' . $status->getPoints() . ' ' . $status->getStatus();
    }
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Sends an VMS message

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsapi = new \SMSApi\Api\VmsFactory();
$smsapi->setClient($client);

try {

    $actionSend = $smsapi->actionSend();

    $actionSend->setTo('Numer odbiorcy'); // numer odbiorczy w postaci 48xxxxxxxxx lub xxxxxxxxx
		//$actionSend->setFrom('Numer Nadawcy'); // Musi być aktywny w Panelu SMSAPI
    $actionSend->setTts('Treść komunikatu'); //Tekst powinien być podowany w kodowaniu UTF-8
	$actionSend->setTry('1'); //Ilość prób połączenia min 1 max 6
	$actionSend->SetTtsLector('maja'); // Określa nazwę lektora czytającego tekst. Dostępne wartości: agnieszka, ewa, jacek, jan, maja.

    $response = $actionSend->execute();

    foreach( $response->getList() as $status ) {
        echo  $status->getNumber() . ' ' . $status->getPoints() . ' ' . $status->getStatus();
    }

} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Sender names

Retrieving all of a sender names and their status

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\SenderFactory();
$smsApi->setClient($client);

try {
    $actionList = $smsApi->actionList();
    $response = $actionList->execute();

		foreach( $response->getList() as $status ) {
			echo  $status->getName() . ' - ' . $status->getStatus() . '<br />';

} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Phone book

Create a new contact to phone book

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\PhonebookFactory();
$smsApi->setClient($client);

try {
    $actionAdd = $smsApi->actionContactAdd();
    $actionAdd->setFirstName('Imię');
    $actionAdd->setLastName('Nazwisko');
    $actionAdd->setInfo('Informacja');
    $actionAdd->setEmail('Adres E-mail');
    $actionAdd->setBirthday('Data urodzin DD-MM-RRR');
    $actionAdd->setCity('Miasto');
    $actionAdd->setGroup('Grupa');
    $actionAdd->setNumber('Numer telefonu');

    $response = $actionAdd->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Retrieving all of a contacts from phone book

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\PhonebookFactory();
$smsApi->setClient($client);

try {
    $actionList = $smsApi->actionContactList();
    $response = $actionList->execute();

    foreach( $response->getList() as $status ) {
        echo  $status->getNumber().'<br>';
    }
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Create a new group to phone book

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\PhonebookFactory();
$smsApi->setClient($client);

try {
    $actionAdd = $smsApi->actionGroupAdd();
    $actionAdd->setName('Nazwa Grupy');
    $actionAdd->setInfo('Opis Grupy ');

    $response = $actionAdd->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Retrieving all of a groups from phone book

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\PhonebookFactory();
$smsApi->setClient($client);

try {
    $actionGet = $smsApi->actionGroupList();
    $response = $actionGet->execute();

    foreach( $response->getList() as $status ) {
        echo  $status->getName(). $status->getFirstName() . $status->getLastName() .'<br>';
    }
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Contacts

Create a new contact by email

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionAdd = $smsApi->actionContactAddFromEmail('Adres E-mail')
        ->setBirthdayDate('Data urodzin DD-MM-RRR')
        ->setDescription('Opis')
        ->setFirstName('Imię')
        ->setLastName('Nazwisko')
        ->setPhoneNumber('Numer telefonu') //opcjonalne, jeśli podano email
        ->setCity('Miasto')
        ->setSource('Źródło kontaktu')
        ->setGenderAsMale();

    $response = $actionAdd->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Create a new contact by phone number

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionAdd = $smsApi->actionContactAddFromPhoneNumber('Numer telefonu')
        ->setBirthdayDate('Data urodzin DD-MM-RRR')
        ->setDescription('Opis')
        ->setFirstName('Imię')
        ->setLastName('Nazwisko')
        ->setEmail('Adres E-mail') //opcjonalne, jeśli podano numer telefonu
        ->setCity('Miasto')
        ->setSource('Źródło kontaktu')
        ->setGenderAsMale();

    $response = $actionAdd->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Get contact by id

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionContactGet = $smsApi->actionContactGet('Numer id kontaktu');
    $response = $actionContactGet->execute();

    echo $response->getFirstName().'<br>';
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Find contacts by email

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionContactList = $smsApi->actionContactList()
        ->setEmail('Adres E-mail');
    $response = $actionContactList->execute();
    $contacts = $response->getCollection();

    foreach ( $contacts as $contact ) {
        echo $contact->getId().'<br>';
    }
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Find contacts by phone number

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionContactList = $smsApi->actionContactList()
        ->setPhoneNumber('Numer telefonu');
    $response = $actionContactList->execute();
    $contacts = $response->getCollection();

    foreach ( $contacts as $contact ) {
        echo $contact->getId().'<br>';
    }
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Find unique contact by email and phone number

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionContactList = $smsApi->actionContactList()
        ->setEmail('Adres E-mail')
        ->setPhoneNumber('Numer telefonu');
    $response = $actionContactList->execute();

    if ( $response->getSize() === 1 ) {
        $contact = $response->getCollection()[0];
        echo $contact->getId().'<br>';
    }
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Edit contact

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionContactEdit = $smsApi->actionContactEdit('Numer id kontaktu')
        ->setPhoneNumber('Numer telefonu')
        ->setBirthdayDate('Data urodzin DD-MM-RRR')
        ->setDescription('Opis')
        ->setFirstName('Imię')
        ->setLastName('Nazwisko')
        ->setEmail('Adres E-mail')
        ->setCity('Miasto')
        ->setSource('Źródło kontaktu')
        ->setGenderAsMale();

    $response = $actionContactEdit->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Create a new group

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionGroupAdd = $smsApi->actionGroupAdd('Nazwa grupy');
    $response = $actionGroupAdd->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Edit existing group

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionGroupEdit = $smsApi->actionGroupEdit('Numer id grupy');
        ->setName('Nazwa grupy')
        ->setDescription('Opis')
        ->setIdx('Nowy numer id');

    $response = $actionGroupEdit->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Get group

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionGroupGet = $smsApi->actionGroupGet('Numer id grupy');
    $response = $actionGroupGet->execute();

    echo $response->getName().'<br>';
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Add contact to group

require_once 'smsapi/Autoload.php';

$client = new \SMSApi\Client('Login_API');
$client->setPasswordHash( ('Haslo_API_w_md5') );

$smsApi = new \SMSApi\Api\ContactsFactory();
$smsApi->setClient($client);

try {
    $actionContactGroupAdd = $smsApi->actionContactGroupAdd('Numer id kontaktu', 'Numer id grupy');
    $response = $actionContactGroupAdd->execute();
} catch ( \SMSApi\Exception\SmsapiException $e ) {
    echo 'ERROR: ' . $e->getMessage();
}

Clone this wiki locally