承接 fowitech/laravel-sms 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fowitech/laravel-sms

Composer 安装命令:

composer require fowitech/laravel-sms

包简介

Persistent sms package for Laravel

README 文档

README

GitHub License Latest Version on Packagist GitHub Tests Action Status Total Downloads

This is a Laravel Package for SMS Gateway Integration. Now Sending SMS is easy.

List of supported gateways:

📦 Install

Via Composer

$ composer require fowitech/laravel-sms

⚡ Configure

Publish the config file

$ php artisan vendor:publish --tag="sms"

In the config file you can set the default driver to use for all your SMS. But you can also change the driver at runtime.

Choose what gateway you would like to use for your application. Then make that as default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.

// Eg. if you want to use Netgsm.
 'driver' => env('SMS_DRIVER', 'netgsm'),

Then fill the credentials for that gateway in the drivers array.

// Eg. for Netgsm.
'netgsm' => [
    'transport' => \Fowitech\Sms\Drivers\Netgsm::class,
    'sender' => env('NETGSM_SENDER', ''),
    'username' => env('NETGSM_USERNAME', ''),
    'password' => env('NETGSM_PASSWORD', ''),
    'options' => [
        // some options
    ]
],

🔥 Usage

In your code just use it like this.

# On the top of the file.
use Sms;

...

# In your Controller.
Sms::message("this message")->to(['Number 1', 'Number 2'])->send();

# If you want to use a different driver.
Sms::via('gateway')->message("this message")->to(['Number 1', 'Number 2'])->send();

# If you want to use options array
$options = [
    'send_date' => now()->addHour()
];
Sms::via('gateway')->message("this message")->to(['Number 1', 'Number 2'])->send($options);

# If you are not a Laravel's facade fan, you can use sms helper:
sms()->message("this message")->to(['Number 1', 'Number 2'])->send();

# If you want to use a different driver.
sms()->via('gateway')->message("this message")->to(['Number 1', 'Number 2'])->send();

😍 Channel Usage

First you have to create your notification using php artisan make:notification command. then SmsChannel::class can be used as channel like the below:

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Fowitech\Sms\Channels\SmsChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class InvoicePaid extends Notification
{
    use Queueable;

    /**
     * Get the notification channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return [SmsChannel::class];
    }

    /**
     * Get the recipients and body of the notification.
     *
     * @param  mixed  $notifiable
     * @return Builder
     */
    public function toSms($notifiable)
    {
        return "Sms message";
    }
}

Custom Made Driver, How To:

First you have to name your driver in the drivers array and also you can specify any config params you want.

'my_driver' => [
    'transport' => \App\Packages\SMSDriver\MyDriver::class,
    'sender' => env('MYDRIVER_SENDER', ''),
    'username' => env('MYDRIVER_USERNAME', ''),
    'password' => env('MYDRIVER_PASSWORD', ''),
    'options' => [
        // some options
    ]
    ... # Your Config Params here.
]

Ex. You created a class : App\Packages\SMSDriver\MyDriver.

namespace App\Packages\SMSDriver;

use Fowitech\Sms\Drivers\Driver;

class MyDriver extends Driver 
{
    public function __construct($options = [])
    {
        $this->sender = config('sms.my_driver.sender');
        $this->username = config('sms.my_driver.username');
        $this->password = config('sms.my_driver.password');
        $this->client = $this->getInstance();
    }

    public function send($options = [])
    {
        # Main logic of Sending SMS.
    }
}

🔬 Testing

composer test

统计信息

  • 总下载量: 260
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 0
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固