承接 va/smart-sms 相关项目开发

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

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

va/smart-sms

Composer 安装命令:

composer require va/smart-sms

包简介

A package to send sms notification in laravel apps.

README 文档

README

GitHub issues GitHub stars GitHub forks GitHub license

Sms Notification service and channel for send sms with smartsms.ir

How to install and config va/smart-sms package?

Installation


composer require va/smart-sms

Publish Config file


php artisan vendor:publish --tag=smart-sms

Where is the config file? In config/smart-sms.php


'line_number' => env('SMS_LINE_NUMBER'),
'user_id' => env('SMS_USER_ID'),
'password' => env('SMS_PASSWORD'),
'default_sms_rcpt' => env('SMS_DEFAULT_SMS_RCPT'),
'mobile_field_name' => env('SMS_MOBILE_FIELD_NAME', 'mobile')

Set You're private configs in .env file, for example


SMS_LINE_NUMBER=10001010
SMS_USER_ID=12345
SMS_PASSWORD=123456789
SMS_DEFAULT_SMS_RCPT=0901***1020 // You're phone number for test on local mode or (.env => APP_ENV=local)
SMS_MOBILE_FIELD_NAME=mobile // Name of the mobile field in you're User model or users migration or users table

How to use va/smart-sms package?

Default Facade for send message and it's methods


// The default message:

$message = 'You're message;

// If we want to send a message to $user:

$user->notify(SmsNotificationFacade::message($message)); // mobile = $user->mobile, message = $message
or
$request->user->notify(SmsNotificationFacade::message($message)); // mobile = $user->mobile, message = $message

// If we want to send a mesage to another mobile number:

$user->notify(SmsNotificationFacade::message($message)->mobile('0901***1020')); // mobile = 0901***1020, message = $message

// If we want to send a message to another mobile numbers (Send Group message):

$user->notify(SmsNotificationFacade::message($message)->group(['0901***1020', '0901***3040']));

Create a custom sms notification and use this

  • Make a new notification

    php artisan make:sms-notification SendActivationNotification
    
  • In which directory was this class made?

    app/Notifications/Message/SendActivationNotification.php
    
  • Content of this Notification

    <?php
    
    namespace App\Notifications\Message;
    
    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;
    use Va\SmartSms\Channels\SmartSmsChannel;
    
    class SendActivationNotification extends Notification
    {
        use Queueable;
    
        public $message;
        public $mobile;
        public $group;
    
        /**
         * SendActivationNotification constructor.
         * @param string|null $message
         * @param string|null $mobile
         * @param array $group
         */
        public function __construct(string $message = null, string $mobile = null, array $group = [])
        {
            $this->message = $message;
            $this->mobile = $mobile;
            $this->group = $group;
        }
    
        /**
         * Get the notification's delivery channels.
         *
         * @param  mixed  $notifiable
         * @return array
         */
        public function via($notifiable)
        {
            return [SmartSmsChannel::class];
        }
    
        public function toChannel()
        {
            return [
                'text' => "You're message" OR $this->message, // You're default (text of message)
                'mobile' => $this->mobile,
                'group' => $this->group
            ];
        }
    }
    
    
  • Use this Notification for send message

    // If we want to send a message with this notification
    
    $user->notify(new SendActivationNotification()); // mobile = $user->mobile, message = (Default meassge in notification)
    
    // If we want to send a message to another mobile number:
    
    $user->notify(new SendActivationNotification(null, '0901***1020')); // mobile = $user->mobile, message = (Default meassge in notification)
    
    // If we want to send a message to another mobile numbers (Send Group message):
    
    $user->notify(new SendActivationNotification(null, null, ['0901***1020', '0901***3040'])); // mobile = array, message = (Default meassge in notification)
    
    // If we want to push a message to notification class
    
    $message = "You're message";
    $user->notify(new SendActivationNotification($message)); // mobile = $user->mobile, message = $message
    

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固