Giter VIP home page Giter VIP logo

kavenegar-laravel's Introduction

Kavenegar Laravel

First of all you will ned an API Key . You can get one Here.

Supported Laravel Versions:
  • V.4
  • V.5
  • V.6
  • V.7
  • V.8
  • V.9
  • V.10

    We highly recomment you to always use the latest version of laravel

Installation

Step 1 - Install the package

  • Method 1: You can install kavenegar/laravel with Composer directly in your project:
composer require kavenegar/laravel
  • Method 2: Add this line to Composer.json file in your project
"kavenegar/php": "*"

Then run following command to download extension using composer

$ composer update

Step 2

Head to config/app.php and add this line to the end of providers Array:

Kavenegar\Laravel\ServiceProvider::class,

So that array must me something like this:

'providers' => [
		/*
		* Laravel Framework Service Providers...
		*/
		.
		.
		.
		Kavenegar\Laravel\ServiceProvider::class
]

Then in the config/app.php and add this line to the end of aliases Array:

'Kavenegar' => Kavenegar\Laravel\Facade::class,

Step 3 - Publish

Run this command in your project dirctory:

php artisan vendor:publish

In the message appear, find the number of Kavenegar, enter the related number then hit Enter. for Example in the below case you must enter 9 then enter:

Which provider or tag files would you like to publish?:
[0 ] Publish files from all providers and tags listed below
[1 ] Provider: Facade\Ignition\IgnitionServiceProvider
[2 ] Provider: Fideloper\Proxy\TrustedProxyServiceProvider
[3 ] Provider: Fruitcake\Cors\CorsServiceProvider
[4 ] Provider: Illuminate\Foundation\Providers\FoundationServiceProvider
[5 ] Provider: Illuminate\Mail\MailServiceProvider
[6 ] Provider: Illuminate\Notifications\NotificationServiceProvider
[7 ] Provider: Illuminate\Pagination\PaginationServiceProvider
**_ [8 ] Provider: Kavenegar\Laravel\ServiceProviderLaravel9_**
.
.
.

Step 4 - Api-Key

Now you must define your API Key to project. for this head to config/kavenegar.php then put your API KEY in the code:

<?php
return [
    'apikey' => ' ',
];

All Set

Usage

You can use the package where ever you want.

  • First use the class:
use Kavenegar;

Then use this pattern to send SMS:

try{
    $sender = "10004346";		//This is the Sender number

    $message = "خدمات پیام کوتاه کاوه نگار";		//The body of SMS

    $receptor = array("09361234567","09191234567");			//Receptors numbers

    $result = Kavenegar::Send($sender,$receptor,$message);
    if($result){
        foreach($result as $r){
            echo "messageid = $r->messageid";
            echo "message = $r->message";
            echo "status = $r->status";
            echo "statustext = $r->statustext";
            echo "sender = $r->sender";
            echo "receptor = $r->receptor";
            echo "date = $r->date";
            echo "cost = $r->cost";
        }
    }
}
catch(\Kavenegar\Exceptions\ApiException $e){
    // در صورتی که خروجی وب سرویس 200 نباشد این خطا رخ می دهد
    echo $e->errorMessage();
}
catch(\Kavenegar\Exceptions\HttpException $e){
    // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد
    echo $e->errorMessage();
}catch(\Exceptions $ex){
   // در صورت بروز خطایی دیگر
    echo $ex->getMessage()
}

Use this pattern to send VerifyLookup SMS:

try{
    $receptor = "09123456789";
    $token = "123";
    $token2 = "456";
    $token3 = "789";
    $template="verify";
    //Send null for tokens not defined in the template
    //Pass token10 and token20 as parameter 6th and 7th
    $result = Kavenegar::VerifyLookup($receptor, $token, $token2, $token3, $template, $type = null);
    if($result){
        foreach($result as $r){
            echo "messageid = $r->messageid";
            echo "message = $r->message";
            echo "status = $r->status";
            echo "statustext = $r->statustext";
            echo "sender = $r->sender";
            echo "receptor = $r->receptor";
            echo "date = $r->date";
            echo "cost = $r->cost";
        }
    }
}
catch(\Kavenegar\Exceptions\ApiException $e){
    // در صورتی که خروجی وب سرویس 200 نباشد این خطا رخ می دهد
    echo $e->errorMessage();
}
catch(\Kavenegar\Exceptions\HttpException $e){
    // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد
    echo $e->errorMessage();
}

You can find all the Error handlings and API parameters and Usage methods in the KaveNegar website.

Usage in Notifications

Also you can use KavengarChannel for your notification:

create your notification:

php artisan make:notification InvoicePaid

extend your notification from KavenegarBaseNotification:

class InvoicePaid extends KavenegarBaseNotification
{

}

overide the toKavengar function:

class InvoicePaid extends KavenegarBaseNotification
{

   public function __construct(Invoice $invoice)
   {
       $this->invoice = $invoice;
   }

    public function toKavenegar($notifiable)
    {
        return (new KavenegarMessage("فاکتور شما به شماره $invoice->id پرداخت شد."))->from('10004346');
    }
}

you should add Notifiable trait and routeNotificationForKavenegar method in your model

class User extends Authenticatable
{
    use Notifiable;

    public function routeNotificationForKavenegar($driver, $notification = null)
    {
        return $this->mobile;
    }

}

** Notice: IF you DO NOT add routeNotificationForKavenegar in your notifiable model then you should set your receiver in your notification : **

class InvoicePaid extends KavenegarBaseNotification
{

    public function toKavenegar($notifiable)
    {
        return (new KavenegarMessage('فاکتور شما به شماره ۱۲۳۴ پرداخت شد.'))->from('10004346')->to('092100000');
    }
}

for send verify lookup message you should use verifyLookup method for set method name and tokens:

class InvoicePaid extends KavenegarBaseNotification
{

    public function toKavenegar($notifiable)
    {
        return (new KavenegarMessage())
            ->verifyLookup('verify_first',['token1','token2']);
    }
}

Contribution

Bug fixes, docs, and enhancements welcome! Please let us know [email protected]

## راهنما

معرفی سرویس کاوه نگار

کاوه نگار یک وب سرویس ارسال و دریافت پیامک و تماس صوتی است که به راحتی میتوانید از آن استفاده نمایید.

ساخت حساب کاربری

اگر در وب سرویس کاوه نگار عضو نیستید میتوانید از لینک عضویت ثبت نام و اکانت آزمایشی برای تست API دریافت نمایید.

مستندات

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

راهنمای فارسی

در صورتی که مایل هستید راهنمای فارسی کیت توسعه کاوه نگار را مطالعه کنید به صفحه کد ارسال پیامک مراجعه نمایید.

اطالاعات بیشتر

برای مطالعه بیشتر به صفحه معرفی وب سرویس اس ام اس کاوه نگار مراجعه نمایید .

اگر در استفاده از کیت های سرویس کاوه نگار مشکلی یا پیشنهادی داشتید ما را با یک Pull Request یا ارسال ایمیل به [email protected] خوشحال کنید.

http://kavenegar.com

kavenegar-laravel's People

Contributors

alissn avatar amirmehrabi avatar arashjafari avatar ariaieboy avatar aryasadeghy avatar beaumind avatar bgsrb avatar hosseinrezaei188 avatar masihjay-z avatar mhyeganeh avatar mikeelahi avatar mohsenk avatar p-shakibafar avatar pooyabe avatar saeedsajadi avatar sajaddp avatar sinadotnut avatar yonessaeedi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kavenegar-laravel's Issues

multi kavenegar token support

I need to have multi-token support to send notifications from another account

we have multi-branded startups here in our holding

and our messaging service to send SMS in all of the microservices should implement by me

I want to have multi-account support by multi token support

problem with laravel 9

hi.
i work with laravel 9.19
i run composer require kavenegar/laravel and version 1.2 installed
then i added Kavenegar\Laravel\ServiceProvider::class, to providers array in config/app.php
but when i run php artisan vendor:publish i get this Class "Kavenegar\Laravel\ServiceProvider" not found
can anyone help me about this problem??

Laravel 8 is not supported

when installing in laravel 8 ,

Your version of Laravel is not supported

please add support for laravel 8.

L5.4 error

[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Foundation\Application::share()

documentation

thanks for this library

but i need more samples about this line:

Kavenegar::Send($sender,$receptor,$message)

if we want to call another rest api and another method we need to know about optional and required fields.

how to send templatename in verify method

if possible give us more samples

or add a sample for each method

thanks in advanced

Laravel 10 support

please add laravel 10 support!
in ServiceProvider getProvider method switchcase for laravel version it has only untile laravel 9!

Driver [kavenegar] not supported.

I am using the latest version (1.3.2) but there is still the same error, please fix this problem faster.

Laravel v8.43.0 (PHP v8.0.3)

Problem with publishing the config file

Hi,
This command php artisan vendor:publish --provider="Kavenegar\Laravel\ServiceProviderLaravel5" in L56 returns Publishing complete. But does not create the kavenegar.php at config directory.

What should I do now?

Laravel 9 Support

Hey there.
Please consider updating the package to support Laravel 9.
Thank you.

Invoice dependency injection

There is no Invoice class:

public function __construct(Invoice $invoice) { $this->invoice = $invoice; }

What should i do?

Laravel 8.* is not Supported

Hey,

Please fix these issues for latest version of Laravel as soon as possible:
php Class Kavenegar\Laravel\Notification\KavenegarBaseNotification & Kavenegar\Laravel\Channel\KavenegarChannel does not comply with psr-4 autoloading standard, It will not autoload anymore in Composer v2.0.

Appreciatively

Send token10 and token20 via verifyLookup method

Hello.

As you know, in addition to %token, %token2 and %token3 there is %token10 and %token20 which is suitable for sending strings containing space charachter such as user's name and company's title.
In this situations, it's not possible to use just %token or %token2 or %token3.

In KavenegarApi class -as you can see below- it's possible to send %token10 & %token20 as 6th and 7th arguments and it works properly:

class KavenegarApi
{

    public function VerifyLookup($receptor, $token, $token2, $token3, $template, $type = null)
    {
        $path   = $this->get_path("lookup", "verify");
        $params = array(
            "receptor" => $receptor,
            "token" => $token,
            "token2" => $token2,
            "token3" => $token3,
            "template" => $template,
            "type" => $type
        );
        if(func_num_args()>5){
            $arg_list = func_get_args();
            if(isset($arg_list[6]))
                $params["token10"]=$arg_list[6];
            if(isset($arg_list[7]))
                $params["token20"]=$arg_list[7];
        } 
        return $this->execute($path, $params);
    }
}  

I'm wondering how it's possible to do so using this package and notificaiton methods:

class InvoicePaid extends KavenegarBaseNotification
{

    public function toKavenegar($notifiable)
    {
        return (new KavenegarMessage())
            ->verifyLookup('verify_first',['token1','token2']);
    }
}
class KavenegarMessage
{

    public function verifyLookup($method, $tokens)
    {
        $this->method = $method;
        $this->tokens = is_array($tokens) ? $tokens : [$tokens];
        return $this;
    }

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.