ghasedak/laravel

Easy-to-use SDK for implementing Ghasedak SMS API in your Laravel projects.

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

This package is not auto-updated.

Last update: 2024-09-17 12:23:26 UTC


README


Logo

Ghasedak Laravel SDK

Easy-to-use SDK for implementing Ghasedak SMS API in your Laravel 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/laravel

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.

Update

Set this line to Composer.json file in your project:

"ghasedak/laravel": "*"

Then run following command to update using composer

composer update 

Composer update the required packages on your local machine.

usage

To use the package, you need an API key. To get that you should have a Ghasedak account. Register and get your API key.
Copy the following variable into your project's .env file and change your_api_key to the key you have got from your Ghasedak account.

GHASEDAKAPI_KEY=your_api_key

Use GhasedakFacade on top of your controller or wherever you want:

use Ghasedak\Laravel\GhasedakFacade;

then you can use GhasedakApi methods statically, to use SendSimple

$response = GhasedakFacade::SendSimple($receptor, $message, $lineNumber = null, $sendDate = null, $checkId = null);

####OR

$response = Ghasedak\Laravel\GhasedakFacade::SendSimple($receptor, $message, $lineNumber = null, $sendDate = null, $checkId = null);

Parameters

Example

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

$receptor = '09xxxxxxxxx';
$message = 'Hello, World!';
$lineNumber = '3000xxxxx'; 

$response = Ghasedak\Laravel\GhasedakFacade::SendSimple($receptor, $message, $lineNumber);

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:

$response = Ghasedak\Laravel\GhasedakFacade::setVerifyType(Ghasedak\Laravel\GhasedakFacade::VERIFY_MESSAGE_TEXT)
->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

$receptor = "09xxxxxxxxx";
$type = Ghasedak\Laravel\GhasedakFacade::VERIFY_MESSAGE_TEXT;
$template = "my-template";
$param1 = '123456';

$response = Ghasedak\Laravel\GhasedakFacade::setVerifyType($type)->Verify($receptor, $template, $param1);

:)

License

Freely distributable under the terms of the MIT license.

فهرست مطالب

نصب

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

composer require ghasedak/laravel

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

به روزرسانی

خط زیر را در فایل composer.json به صورت زیر تغییر دهید :

"ghasedak/laravel": "*"

سپس خط فرمان زیر را اجرا نمایید :

composer update 

کامپوزر با اجرای این خط فرمان پکیج و نیازمندی های آن را در برنامه شما به روزرسانی خواهد کرد.

نحوه استفاده

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

متغیر زیر را درون فایل .env پروژه‌ی خود کپی کرده و به جای your_api_key کلید دریافتی از حساب قاصدک خود را قرار دهید.

GHASEDAKAPI_KEY=your_api_key
در بالای کنترلر یا هر جایی از پروژه GhasedakApi را استفاده کنید:
use Ghasedak\Laravel\GhasedakFacade;
سپس شما میتوانید از متد های GhasedakApi به صورت استاتیک استفاده کنید برای استفاده از SendSimple
$response = GhasedakFacade::SendSimple($receptor, $message, $lineNumber = null, $sendDate = null, $checkId = null);

####یا

$response = Ghasedak\Laravel\GhasedakFacade::SendSimple($receptor, $message, $lineNumber = null, $sendDate = null, $checkId = null);

:))

پارامترها

نمونه کد

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

$receptor = '09xxxxxxxxx';
$message = 'Hello, World!';
$lineNumber = '3000xxxxx';

$response = Ghasedak\Laravel\GhasedakFacade::SendSimple($receptor, $message, $lineNumber);

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

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

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

$response = Ghasedak\Laravel\GhasedakFacade::setVerifyType(Ghasedak\Laravel\GhasedakFacade::VERIFY_MESSAGE_TEXT)
->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"
);  

پارامترها

نمونه کد

$receptor = "09xxxxxxxxx";
$type = Ghasedak\Laravel\GhasedakFacade::VERIFY_MESSAGE_TEXT;
$template = "my-template";
$param1 = '123456';

$response = Ghasedak\Laravel\GhasedakFacade::setVerifyType($type)->Verify($receptor, $template, $param1);

مجوز

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