<?php
define('XML_PAYLOAD', '<?xml version="1.0" encoding="UTF-8"?>
<sms>
<credential>
<username>test</username>
<password>heslo</password>
</credential>
<message>
<sender>mojafirma</sender>
<def_time>2021-12-31 23:59:00</def_time>
<recipients>
<recipient>
<id>121</id>
<unicode>0</unicode>
<phone>421944385600</phone>
<text>Doporucujeme odcervit psa - SONKA - po polroku. MVDr. Brcko</text>
</recipient>
<recipient>
<id>122</id>
<unicode>1</unicode>
<phone>421948700708</phone>
<text>Dnes uplynie 12 týždňov od podania BRAVECTO tbl. Vášmu psovi - - proti kliešťom a blchám.</text>
</recipient>
</recipients>
</message>
<optional>
<callback>https://www.domena.sk/sms/callback.php</callback>
</optional>
</sms>');
define('XML_POST_URL', 'https://www.123sms.sk/api/sms-xml/');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
$result = curl_exec($ch);
if (curl_errno($ch) )
{
$result = 'ERROR -> ' . curl_errno($ch) . ':' . curl_error($ch);
}
else
{
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
switch($returnCode)
{
case 200: $xmlObject = new SimpleXMLElement($result);
$status = $xmlObject->status;
$balance = $xmlObject->balance;
$errorsms = $xmlObject->errorsms;
$failedsms = $xmlObject->failedsms;
break;
case 404:
$result = 'ERROR -> 404';
break;
default:
}
}
curl_close($ch);
?>
Odpoveď XML
<response>
<status>1</status>
<balance>64.2454</balance>
<sentsms>3</sentsms>
<errorsms></errorsms>
<failedsms></failedsms>
</response>
status -
1 prijaté volanie
- 1 chybné prihlasovacie údaje
sentsms - počet úspešne prijatých SMS do systému
errorsms - počet neodoslaných SMS z dôvodu chybných čísiel
failedsms - počet neodoslaných SMS z dôvodu nízkeho kreditu
Doručenky -
status: status=delivered, undelivered
id customer: idc=123456