Praktische PHP-Beispiele fuer die ASPSMS WebAPI (https://webapi.aspsms.com). Die Gliederung entspricht der WebAPI-Uebersicht.
<?php
function checkCredentials(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/CheckUserCredentials?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
?>
<?php
function getCredits(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/ASPSMSCredits?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function estimateCredits(string $userkey, string $password, array $msisdns): string {
$url = 'https://webapi.aspsms.com/ASPSMSEstimateCreditConsumption?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password
]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($msisdns)
]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function sendSimpleSms(string $userkey, string $password, string $msisdn, string $message, string $originator): string {
$url = 'https://webapi.aspsms.com/SendSimpleSMS?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'MSISDN' => $msisdn,
'Operation' => 'SendTextSMS', 'MessageData' => $message, 'Originator' => $originator
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function sendAdvancedSms(string $userkey, string $password, string $message, string $originator, array $recipients): string {
$url = 'https://webapi.aspsms.com/ASPSMSSendSMS?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$payload = ['Operation' => 'SendTextSMS', 'Originator' => $originator, 'MessageData' => $message, 'Recipients' => $recipients];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($payload)
]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
Gleicher Absender fuer alle, individueller Text (und optional TRN / zeitversetzter Versand) pro Empfaenger.
<?php
function sendPersonalizedSms(string $userkey, string $password, string $originator, array $messages): string {
// $messages z.B.:
// [
// ['PhoneNumber' => '+41791111111', 'TransactionReferenceNumber' => 'ORDER-1001',
// 'MessageData' => 'Hallo Anna, deine Bestellung #1001 ist unterwegs.'],
// ['PhoneNumber' => '+41792222222', 'TransactionReferenceNumber' => 'ORDER-1002',
// 'MessageData' => 'Hallo Bruno, deine Bestellung #1002 ist unterwegs.',
// 'DeferredDeliveryTime' => '2026-10-20T08:00:00'] // optional pro Empfaenger
// ]
$url = 'https://webapi.aspsms.com/ASPSMSSendSMS?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$payload = [
'Operation' => 'SendTextSMS',
'Originator' => $originator, // gleich fuer alle
'RecipientsEx' => $messages // individueller MessageData pro Empfaenger
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($payload)
]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<?php
function deactivateByMsisdn(string $userkey, string $password, array $msisdns): string {
$url = 'https://webapi.aspsms.com/ASPSMSDeactivatePendingSMSWithMSISDN?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($msisdns)]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
<SCTS>, <DSCTS>, <RSN>, <DST>, <TRN>, <RCPNT>, <CREDITS> (max. 200 Zeichen pro URL).<?php
function sendSmsWithWebhooks(string $userkey, string $password, string $message, string $originator, array $recipients): string {
$url = 'https://webapi.aspsms.com/ASPSMSSendSMS?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$payload = [
'Operation' => 'SendTextSMS', 'Originator' => $originator, 'MessageData' => $message, 'Recipients' => $recipients,
'URLBufferedMessageNotification' => 'https://your-domain.com/hook/buffered?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>',
'URLDeliveryNotification' => 'https://your-domain.com/hook/delivered?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>',
'URLNonDeliveryNotification' => 'https://your-domain.com/hook/failed?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>'
];
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($payload)]);
$r = curl_exec($ch); curl_close($ch);
return $r;
}
?>
| Wert | Bedeutung |
|---|---|
| -1 | Noch nicht eingereicht / abgelehnt |
| 0 | Delivered |
| 1 | Buffered |
| 2 | Not Delivered |
Nach Status 1 (Buffered) kommt fast immer ein zweiter Aufruf mit 0 oder 2.
| Code | Bedeutung | Typische Ursache |
|---|---|---|
| 000 | Unknown Subscriber | Nummer existiert nicht |
| 103 | Call Barred | Gesperrt / leere Prepaid-Karte |
| 107 | Absent Subscriber | Handy aus / kein Netz |
| 108 | Delivery Fail | Speicher voll oder endgueltig fehlgeschlagen |
| 110 | Protocol Error | Geraeteprobleme |
| 118 | System fail | Schwere Netz-/Geraeteprobleme |
<?php
function getTrafficStat(string $userkey, string $password, bool $calculateCredits = true): string {
$url = 'https://webapi.aspsms.com/TrafficStat01/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'CalculateCredits' => $calculateCredits ? 'true' : 'false'
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getSendingLog(string $userkey, string $password, int $year, int $month = 0, int $day = 0): string {
$url = 'https://webapi.aspsms.com/SendingStat01/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'Year' => $year, 'Month' => $month, 'Day' => $day
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
// SendingStat02 (MSISDN), SendingStat03 (TRN), SendingStat04 (JobID) – same GET pattern
function getLogByTrn(string $userkey, string $password, string $trn): string {
$url = 'https://webapi.aspsms.com/SendingStat03/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'TransactionReferenceNumber' => $trn
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getReceivedSms(string $userkey, string $password, int $year = 0, int $month = 0, int $day = 0): string {
$url = 'https://webapi.aspsms.com/ReceivingStat01/Get?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'Year' => $year, 'Month' => $month, 'Day' => $day, 'MaxRecords' => 100
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function setReceiveUrl(string $userkey, string $password, string $callbackUrl): string {
$url = 'https://webapi.aspsms.com/ReceiveURL/Set?' . http_build_query([
'Userkey' => $userkey, 'Password' => $password, 'URL' => $callbackUrl
]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getMsisdnDlrStat(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/MSISDNDLRStat/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getPhonebook(string $userkey, string $password, ?string $msisdn = null): string {
$params = ['Userkey' => $userkey, 'Password' => $password];
if ($msisdn) $params['MSISDN'] = $msisdn;
$url = 'https://webapi.aspsms.com/PhoneNumbers/Read?' . http_build_query($params);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getGroups(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/Groups/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getAllGroupRelations(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/GroupRelationsAll/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
Versandaktionen dokumentieren. Beim Senden JobID mitgeben; spaeter per SendingStat04 abfragen.
<?php
function getJobs(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/Jobs/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>
<?php
function getTemplates(string $userkey, string $password): string {
$url = 'https://webapi.aspsms.com/Templates/Get?' . http_build_query(['Userkey' => $userkey, 'Password' => $password]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch); curl_close($ch); return $r;
}
?>