fastsms.pro HTTP API - Примеры кода для php

Примеры кода для php

Отправка сообщения методом GET:

$vars = Array (
     'username' => 'yourname',
     'password' => md5 ('password'),
     'sender' => 'tester',
     'numbers' => '79998880001',
     'message' => 'Hi there!'
);

$url = 'http://api.fastsms.pro/send.php?'.http_build_query ($vars);
$file = fopen ($url, 'r');
$result = fread ($file, 1024);
fclose ($file);

if (is_numeric ($result)) {
     $reference = $result;
     echo 'The message is successfully sent. The reference is '.$reference;
} else {
     list ($err, $errcode) = explode (":", $result, 2);
     echo 'ERROR '.$errcode.'! message not sent.';
}

Отправка сообщения методом POST:

$vars = Array (
     'username' => 'yourname',
     'password' => md5 ('password'),
     'sender' => 'tester',
     'numbers' => '79998880001',
     'message' => 'Hi there!'
);

$url = 'http://api.fastsms.pro/send.php';

$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_TIMEOUT, 3);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, http_build_query ($vars));
$result = curl_exec ($curl);
curl_close ($curl);

if (is_numeric ($result)) {
     $reference = $result;
     echo 'The message is successfully sent. The reference is '.$reference;
} else {
     list ($err, $errcode) = explode (":", $result, 2);
     echo 'ERROR '.$errcode.'! message not sent.';
}