Dies ist eine PHP-Client-Bibliothek für die REST-API von SMSGlobal, um SMS-Funktionen in Ihre PHP-Anwendung zu integrieren.
Eröffnen Sie noch heute ein kostenloses SMSGlobal-Konto und erhalten Sie Ihren API-Schlüssel von unserer fortschrittlichen SMS-Plattform MXT. Genießen Sie außerdem unbegrenzte kostenlose Entwickler-Sandbox-Tests, um Ihre API vollständig auszuprobieren!
Um die PHP-Client-Bibliothek in Ihrem Projekt zu installieren, empfehlen wir die Verwendung von Composer.
composer require smsglobal/smsglobal-php
Schauen Sie sich examples
an
SMS senden
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ sms = new SMSGlobal Resource Sms ();
try {
$ response = $ sms -> sendToOne ( ' DESTINATION_NUMBER ' , ' This is a test message. ' );
print_r ( $ response [ ' messages ' ]);
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
OTP senden
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> send ( ' DESTINATION_NUMBER ' , ' {*code*} is your SMSGlobal verification code. ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
Die folgende JSON-Antwort wird vom Server zurückgegeben:
{
"requestId" : " 404372541683674336263499 " ,
"validUnitlTimestamp" : " 2020-11-18 16:24:51 " ,
"createdTimestamp" : " 2020-11-18 16:22:51 " ,
"lastEventTimestamp" : " 2020-11-18 16:22:51 " ,
"destination" : " 61400000000 " ,
"status" : " Sent "
}
OTP überprüfen
Der von Ihrem Benutzer eingegebene OTP-Code kann entweder mithilfe requestId
oder destination number
überprüft werden. Im Folgenden finden Sie Beispiele für jede Methode:
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> verifyByRequestId ( ' request Id ' , ' OTP code enterted by your user. ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> verifyByDestination ( ' destination number ' , ' OTP code enterted by your user. ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
Die folgende JSON-Antwort wird vom Server zurückgegeben, wenn die Überprüfung erfolgreich ist:
{
"requestId" : " 404372541683674336263499 " ,
"validUnitlTimestamp" : " 2020-11-18 16:24:51 " ,
"createdTimestamp" : " 2020-11-18 16:22:51 " ,
"lastEventTimestamp" : " 2020-11-18 16:22:51 " ,
"destination" : " 61400000000 " ,
"status" : " Verified "
}
OTP abbrechen
Die OTP-Anfrage kann abgebrochen werden, wenn ein OTP noch nicht abgelaufen und verifiziert ist. Dies kann entweder durch die Verwendung von requestId
oder destination number
erfolgen. Im Folgenden finden Sie Beispiele für jede Methode:
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> cancelByRequestId ( ' request Id ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> cancelByDestination ( ' destination number ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
Die folgende JSON-Antwort wird vom Server zurückgegeben, wenn der Abbruch erfolgreich war:
{
"requestId" : " 404372541683674336263499 " ,
"validUnitlTimestamp" : " 2020-11-18 16:24:51 " ,
"createdTimestamp" : " 2020-11-18 16:22:51 " ,
"lastEventTimestamp" : " 2020-11-18 16:22:51 " ,
"destination" : " 61400000000 " ,
"status" : " Cancelled "
}
Entwicklungsabhängigkeiten installieren
composer require smsglobal/smsglobal-php
Führen Sie Unit-Tests durch
./vendor/bin/phpunit tests
Mit Abdeckung (erfordert Erweiterung pcov oder xdebug)
./vendor/bin/phpunit --coverage-text tests
Eine Liste der verfügbaren Ressourcen finden Sie in der REST-API-Dokumentation.
Bei Fragen kontaktieren Sie uns