Skip to content
smsapi edited this page Dec 1, 2014 · 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();
}

Clone this wiki locally