<?php
define('XML_PAYLOAD', '<?xml version="1.0" encoding="UTF-8"?>
<sms>
<credential>
<username>username</username>
<password>password or API key</password>
</credential>
<message>
<sender>mycompany</sender>
<def_time>2016-12-31 23:59:00</def_time>
<recipients>
<recipient>
<id>121</id>
<unicode>0</unicode>
<phone>421911123456</phone>
<text>Text first SMS</text>
</recipient>
<recipient>
<id>122</id>
<send_time>2017-12-31 23:59:00</send_time>
<unicode>1</unicode>
<phone>421944123456</phone>
<text>Text SMS 2 unicode čžýáíáť</text>
</recipient>
<recipient>
<id>123</id>
<name>Janko Hraško</name>
<idc>12345</idc>
<send_time></send_time>
<unicode>0</unicode>
<phone>42190512346</phone>
<text>Text 3</text>
</recipient>
</recipients>
</message>
<optional>
<callback>https://www.domain.com/sms/callback.php</callback>
</optional>
</sms>');
define('XML_POST_URL', 'https://www.affilsms.com/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
-
status: status=delivered, undelivered
id: id=123456