ghasedak sms gateway package for PHP

v2.1.3 2022-09-18 12:12 UTC

This package is auto-updated.

Last update: 2024-09-18 17:02:02 UTC


README


Logo

Ghasedak PHP SDK

Easy-to-use SDK for implementing Ghasedak SMS API in your PHP projects.
Explore the docs »

Web Service Documents · REST API . Report Bug · Request Feature


contributors forks stars issues license

English Document | مستندات فارسی

Table of Contents

Install

The easiest way to install is by using Composer:

composer require ghasedak/php  

Composer is a dependency manager for PHP which allows you to declare the libraries your project depends on, and it will manage (install/update) them for you. If you are not familiar with Composer, you can read its documentations and download it via getcomposer.org.

Alternatively you can download Ghasedak SDK from here and extract it in your project and follow the rest of the instructions below. Also there is an Example folder inside the package which you can use to understand the procedure.

usage

To use the API, you need an API key. To get that you should have a Ghasedak account. Register and get your API key.

Then require the file autoload.php to get all classes and dependencies loaded.

require __DIR__ . '/vendor/autoload.php';

Create an instance from Ghasedak class with your API key:

$api = new \Ghasedak\GhasedakApi( 'your_api_key');  

Don't forget to change your_api_key with the key you have got from your Ghasedak account.

Send a sms:

$api->SendSimple(  
 "09xxxxxxxxx", // receptor
 "Hello World!", // message
 "3000xxxxx" // choose a line number from your account
);  

Parameters

Example

Here is a sample code for sending SMS. Please note that you must specify linenumber if you don't have a dedicated line.

require __DIR__ . '/vendor/autoload.php';
 
try{  
 $message = "Hello, World!";
 $lineNumber = null; // If you do not have a dedicated line, you must specify the line number  
 $receptor = "09xxxxxxxxx";
 $api = new \Ghasedak\GhasedakApi('api_key');
 $api->SendSimple($receptor,$message,$lineNumber);  
}
catch(\Ghasedak\Exceptions\ApiException $e){  
 echo $e->errorMessage();  
}  
catch(\Ghasedak\Exceptions\HttpException $e){  
 echo $e->errorMessage();  
}  

One-Time Passwords (OTP)

The One-Time-Password (OTP) Interface is used to perform a mobile authentication or to implement Two-Factor-Authentication (2FA).
You can pass up to 10 param to Verify method;

$api->setVerifyType(GhasedakApi::VERIFY_TEXT_TYPE)->Verify(  
 "09xxxxxxxxx",  // receptor
 "my-template",  // name of the template which you've created in you account 
 "param1",       // parameters (supporting up to 10 parameters) 
 "param2", 
 "param3");

Parameters

Example

require __DIR__ . '/vendor/autoload.php';  

try{  
 $receptor = "09xxxxxxxxx";
 $type = 1;
 $template = "my-template";
 $param1 = '123456';
 $api = new \Ghasedak\GhasedakApi('api_key');
 $api->Verify($receptor, $type, $template, $param1);
}  
catch(\Ghasedak\Exceptions\ApiException $e){  
 echo $e->errorMessage();  
}  
catch(\Ghasedak\Exceptions\HttpException $e){  
 echo $e->errorMessage();  
}  

:)

License

Freely distributable under the terms of the MIT license.

فهرست مطالب

نصب

ساده‌ترین راه برای نصب این پکیج استفاده از Composer است:

composer require ghasedak/php  

Composer سامانه‌ای برای مدیریت بسته‌های زبان PHP است که به شما امکان مدیریت (نصب / به روزرسانی) پکیج‌های نوشته شده در این زبان را می‌دهد. اگر با کامپوزر آشنایی ندارید، می‌توانید از طریق سایت getcomposer.org مستندات آن را مطالعه و اقدام به بارگیری و نصب آن کنید.

در صورت عدم تمایل به استفاده از کامپوزر، می‌توانید پکیج Ghasedak PHP را از اینجا دانلود کرده و محتویات فایل زیپ را درون پروژه‌ی خود استفاده کنید. همچنین پوشه‌ای با نام Example درون پکیج وجود دارد که می‌توانید از آن برای یادگیری استفاده‌ی صحیح از پکیج استفاده کنید.

نحوه استفاده

برای استفاده از این پکیج می‌بایست API key داشته باشید. جهت دریافت ابتدا در سایت قاصدک ثبت‌نام کنید و از پنل کاربری‌تان API key دریافت کنید.

سپس باید فایل autoload را به پروژه‌ی خود اضافه کنید:

require __DIR__ . '/vendor/autoload.php';

یک instance از کلاس Ghasedak با API key خود بسازید:

$api = new \Ghasedak\GhasedakApi( 'your_api_key');  

به خاطر داشته باشید که your_api_key را با کلید دریافتی از حساب قاصدک خود جایگزین کنید.

پیامک دلخواه‌تان را ارسال کنید:

$api->SendSimple(  
	"09xxxxxxxxx",  // receptor 
	"Hello World!", // message 
	"3000xxxxx" 	// choose a line number from your account
 );

پارامترها

نمونه کد

کد زیر نمونه‌ای از متد ارسال تکی پیامک می‌باشد. لطفا توجه کنید که در صورت نداشتن خط اختصاصی می‌بایست حتما linenumber را وارد کنید.

require __DIR__ . '/vendor/autoload.php';  
try{  
 $message = "Hello, World!";
 $lineNumber = null; // If you do not have a dedicated line, you must specify the line number  
 $receptor = "09xxxxxxxxx";
 $api = new \Ghasedak\GhasedakApi('api_key');
 $api->SendSimple($receptor,$message,$lineNumber);  
}  
catch(\Ghasedak\Exceptions\ApiException $e){  
 echo $e->errorMessage();  
}  
catch(\Ghasedak\Exceptions\HttpException $e){  
 echo $e->errorMessage();  
}  

رمز عبور یکبار مصرف (OTP)

رمز عبور یک‌بار مصرف برای اعتبارسنجی از طریق تلفن همراه و یا برای ورود دو مرحله‌ای (2FA) استفاده می‌شود.

با استفاده از متد Verify می‌توانید تا سقف 10 param را ارسال کنید:

$api->setVerifyType(GhasedakApi::VERIFY_TEXT_TYPE)->Verify( 
 "09xxxxxxxxx", // receptor 
 "my-template", // name of the template which you've created in you account 
 "param1",      // parameters (supporting up to 10 parameters) 
 "param2", 
 "param3");

پارامترها

نمونه کد

require __DIR__ . '/vendor/autoload.php';  
try{  
 $receptor = "09xxxxxxxxx";
 $type = 1;
 $template = "my-template";
 $param1 = '123456';
 $api = new \Ghasedak\GhasedakApi('api_key');
 $api->Verify($receptor, $type, $template, $param1);  
}  
catch(\Ghasedak\Exceptions\ApiException $e){  
 echo $e->errorMessage();  
}  
catch(\Ghasedak\Exceptions\HttpException $e){  
 echo $e->errorMessage();  
}  

مجوز

این پکیج تحت مجوز MIT منتشر شده است.