const ERROR_API = "Error during API call\n";
const ERROR_FILE = "The specified file does not exist\n";
const URL = "https://api.smsmode.com/http/1.6/";
const PATH_SEND_SMS = "sendSMS.do";
const PATH_SEND_SMS_BATCH = "sendSMSBatch.do";
class ExempleClientHttpApi
{
public function sendSmsGet($accessToken, $message, $destinataires, $emetteur, $optionStop)
{
$message = iconv("UTF-8", "ISO-8859-15", $message);
$fields_string = '?accessToken='.$accessToken.'&message='.urlencode($message).'&numero='.$destinataires.'&emetteur='.$emetteur.'&stop='.$optionStop;
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_URL, URL.PATH_SEND_SMS.$fields_string);
$result = curl_exec($ch);
curl_close($ch);
if (!$result) {
return ERROR_API;
}
return $result;
}
public function sendSmsPost($accessToken, $message, $destinataires, $emetteur, $optionStop)
{
$message = iconv("UTF-8", "ISO-8859-15", $message);
$fields_string = 'accessToken='.$accessToken.'&message='.urlencode($message).'&numero='.$destinataires.'&emetteur='.$emetteur.'&stop='.$optionStop;
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_URL, URL.PATH_SEND_SMS);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
if (!$result) {
return ERROR_API;
}
return $result;
}
public function sendSmsBatch($accessToken, $batchFilePath, $optionStop)
{
if (!file_exists($batchFilePath)) {
return ERROR_FILE;
}
$fields_string = '?accessToken='.$accessToken.'&stop='.$optionStop;
$cfile = new CurlFile($batchFilePath, 'text/csv');
$data = array('data-binary' => $cfile);
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'content-type: multipart/form-data'));
curl_setopt($ch,CURLOPT_URL, URL.PATH_SEND_SMS_BATCH.$fields_string);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
if (!$result) {
return ERROR_API;
}
return $result;
}
}