Ini adalah perpustakaan Klien PHP untuk REST API SMSGlobal untuk mengintegrasikan kemampuan SMS ke dalam aplikasi PHP Anda.
Daftar akun SMSGlobal gratis hari ini dan dapatkan Kunci API Anda dari platform SMS canggih kami, MXT. Selain itu, nikmati pengujian sandbox pengembang gratis tanpa batas untuk mencoba API Anda secara penuh!
Untuk menginstal perpustakaan klien PHP ke proyek Anda, kami sarankan menggunakan Komposer.
composer require smsglobal/smsglobal-php
Lihat folder examples
Kirim SMS
<?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 ();
}
Kirim OTP
<?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 ();
}
Respons json berikut akan dikembalikan oleh server:
{
"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 "
}
Verifikasi OTP
Kode OTP yang dimasukkan oleh pengguna Anda dapat diverifikasi menggunakan requestId
atau destination number
. Berikut adalah contoh masing-masing metode:
<?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 ();
}
Respons json berikut akan dikembalikan oleh server jika verifikasi berhasil:
{
"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 "
}
Batalkan OTP
Permintaan OTP dapat dibatalkan jika OTP belum habis masa berlakunya dan belum terverifikasi. Hal ini dapat dilakukan dengan menggunakan requestId
atau destination number
. Berikut adalah contoh masing-masing metode:
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 ();
}
Respons json berikut akan dikembalikan oleh server jika pembatalan berhasil:
{
"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 "
}
Instal dependensi pengembangan
composer require smsglobal/smsglobal-php
Jalankan pengujian unit
./vendor/bin/phpunit tests
Dengan cakupan (membutuhkan ekstensi pcov atau xdebug)
./vendor/bin/phpunit --coverage-text tests
Lihat dokumentasi REST API untuk daftar sumber daya yang tersedia.
Untuk pertanyaan apa pun, hubungi kami