SLOONO.de-API Account: Kontostand
Aus SLOONO.de-API
Es können jetzt Informationen zum Konto wie Kontostand, Anzahl der Nachrichten im Postausgang und Anzahl der Nahcrichten im Archiv ausgelesen werden.
Inhaltsverzeichnis |
API
Anfrage
Adresse: http://www.sloono.de/API/httpkonto.php
| Parameter | Typ | Beschreibung | Standard |
|---|---|---|---|
| user | Text | Username | |
| password | Text | MD5-Hashwert des Passworts | |
| httphead | Zahl | Wenn httphead auf 1 gesetzt wird, so werden bei Fehlern HTTP-Header ungleich 200 gesendet. Beim Wert 0 muss der Fehler aus der Antwort abgelesen werden. | 1 |
Alle Variablen, die keinen Standartwert haben müssen gesetzt werden!
Antwort
Eine Vorauswahl wird bereits mit dem HTTP-Header der Antwort getroffen. Wenn etwas anderes als HTTP 1/1 200 OK als Antwort empfangen wird ist ein Fehler aufgetreten. Zurückgegeben wird ein Fehlercode, ein Fehlertext und Informationen (falls vorhanden).
<p>An sonsten werden die Kontodaten im Infobereich der Antwort zurückgegeben.| Zeile | Inhalt |
|---|---|
| Kontostand: | Kontostand als Text. |
| SMS: | Anzahl der gesendeten Nachrichten insgesammt. |
| Postausgang: | Anzahl der Nachrichten, die sich im Postausgang befinden. |
| Archiv: | Anzahl der Nachrichten, die sich im Archiv befinden. |
Beispiele
So kann eine GET-Anfrage aussehen:
http://www.sloono.de/API/httpkonto.php?user=musteruser&password=e16b2ab8d12314bf4efbd6203906ea6c
So kann eine Textantwort aussehen:
101
Erfolgreiche Abfrage
Kontostand: 4,578
SMS: 1234
Postausgang: 0
Archiv: 20
Quellcodebeispiele
PHP
Beispiel 1:
<?phpmb_internal_encoding("UTF-8");
echo "<pre>";
//////////////////////////////////////////////////////////////////////////////////// Einstellungen für Account und SMS /////////////////////////////////////////////////////////////////////////////////////// ÄNDERN! ////////////////////////////////////////////////////////////////////////////////////$suser = "Username"; // Nickname
$spw = "Passwort"; // Accountpasswort
//////////////////////////////////////////////////////////////////////////////////// Beispielfunktionen /////////////////////////////////////////////////////////////////////////////////////// NICHT ÄNDERN! /////////////////////////////////////////////////////////////////////////////////////*** XML-Objekt in Array umwandeln.** Diese Funktion wandelt ein SimpleXMLElement {@link http://www.php.net/manual/de/class.simplexmlelement.php}* in ein normales mehrdimensionales Array um.** @param SimpleXMLElement XML-Objekt welches konvertiert werden soll*/function simpleXMLToArray($xml) {
$return = array();
if(!($xml instanceof SimpleXMLElement)) return $return;
$name = $xml->getName();
$_value = trim((string)$xml);
if(mb_strlen($_value) == 0) $_value = null;
if($_value !== null) $return = html_entity_decode($_value);
$children = array();
$first = true;
foreach($xml->children() as $elementName => $child) {
$value = simpleXMLToArray($child);
if(isset($children[$elementName])) {
if($first) {
$temp = $children[$elementName];
unset($children[$elementName]);
$children[$elementName][] = $temp;
$first = false;
}$children[$elementName][] = $value;
} else
$children[$elementName] = $value;
}if(count($children) > 0) $return = array_merge($return,$children);
$attributes = array();
foreach($xml->attributes() as $name=>$value){
$attributes[$name] = trim($value);
}if(count($attributes) > 0) $return = array_merge($return, $attributes);
return $return;
}/*** Webseite als String zurückgeben.** Diese Funktion lädt eine Webseite via CURL {@link http://www.php.net/manual/de/book.curl.php} herunter.** @param string Adresse der Webseite* @param mixed URL-konforme Daten für POST-Anfrage oder FALSE wenn GET verwendet werden soll*/function curlhttp($url,$post = false) {
if($url == "") return false;
$VersionArray = curl_version();
$Optionen = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => 0, CURLOPT_USERAGENT => "PHP ".phpversion()." + cURL ".$VersionArray["version"], CURLOPT_TIMEOUT => 30);
if($post != false) {
$Optionen[CURLOPT_POST] = 1;
$Optionen[CURLOPT_POSTFIELDS] = $post;
}$s = curl_init($url);
foreach($Optionen as $CURLCONST => $Wert) curl_setopt($s,$CURLCONST,$Wert);
$Quellcode = curl_exec($s);
$StatusArray = curl_getinfo($s);
$HttpHead = array(100 => "Continue", 101 => "Switching Protocols", 200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information",
204 => "No Content", 205 => "Reset Content", 206 => "Partial Content", 300 => "Multiple Choices", 301 => "Moved Permanently",
302 => "Found", 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy", 306 => "(Unused)", 307 => "Temporary Redirect",
400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed",
406 => "Not Acceptable", 407 => "Proxy Authentication Required", 408 => "Request Timeout", 409 => "Conflict", 410 => "Gone",
411 => "Length Required", 412 => "Precondition Failed", 413 => "Request Entity Too Large", 414 => "Request-URI Too Long",
415 => "Unsupported Media Type", 416 => "Requested Range Not Satisfiable", 417 => "Expectation Failed", 500 => "Internal Server Error",
501 => "Not Implemented", 502 => "Bad Gateway", 503 => "Service Unavailable", 504 => "Gateway Timeout", 505 => "HTTP Version Not Supported");
return array("HTTP_Code" => $StatusArray["http_code"], "HTTP_Text" => $HttpHead[$StatusArray["http_code"]], "HTTP_Body" => $Quellcode);
}//////////////////////////////////////////////////////////////////////////////////// Das Ergebnis der Konstoabfrage als Array ausgeben ////////////////////////////////////////////////////////////////////////////////////$ret = curlhttp("http://www.sloono.de/API/httpkonto.php?user=".urlencode($suser)."&password=".$spw."&httphead=0&return=xml");
print_r(simpleXMLToArray(simplexml_load_string($ret["HTTP_Body"])));
echo "</pre>";
?>
Beispiel 2:
<?phpfunction Kontoinformationen($User,$Password) {
if(strlen($User) == 0) return false;
if(strlen($Password) == 0) return false;
$url = "http://www.sloono.de/API/httpkonto.php?user=".urlencode($User);
$url .= "&password=".md5($Password)."&httphead=0";
$Antwort = @file($url);
if($Antwort == false) return false;
if(trim($Antwort[0]) != 101) return false;
return array("Kontostand" => substr($Antwort[3],12),
"Gesendet" => substr($Antwort[4],5),
"Postausgang" => substr($Antwort[5],13),
"Archiv" => substr($Antwort[6],8));
}?><?php$sloonoapi = Kontoinformationen("Max","PW von Max");
if($sloonoapi == false)
echo "Fehler!";
else {
foreach($sloonoapi as $var => $wert) echo $var.": ".$wert."<br>\n";
}?>