shabayek/laravel-sms 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

shabayek/laravel-sms

最新稳定版本:v1.3.5

Composer 安装命令:

composer require shabayek/laravel-sms

包简介

Laravel Package For SMS Sending

README 文档

README

Github Status Styleci Status Packagist version mit Packagist PHP Version Support Packagist Downloads

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

List of supported gateways:

Install

Via Composer

composer require shabayek/laravel-sms

Usage

  • Publish the config file
php artisan vendor:publish --provider="Shabayek\Sms\SmsServiceProvider"
  • 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.
'default' => 'smseg',
  • Then fill the credentials for that gateway in the drivers array.
SMS_CONNECTION=smseg
SMS_USERNAME=username
SMS_PASSWORD=password
SMS_SENDER_ID=sender
SMS_SERVICE=normal
  • Send normal sms message
use Shabayek\Sms\Facades\Sms;
    
$sms = Sms::send('0120000000', 'Hello world');
  • Send otp sms message

if you set sms service normal it's will send via sms message if you set sms service otp it's will send via sms message

use Shabayek\Sms\Facades\Sms;

$sms = Sms::sendOtp('0120000000');
  • Verify phone number
use Shabayek\Sms\Facades\Sms;

$phone = '09121234567'; // phone number
$otp = '123456'; // otp that you sent to phone
$actualOtp = '123456'; // this is the actual otp that you sent to the user

$verify = Sms::verify($phone, $otp, $actualOtp); // third params is optional with service otp
  • You can set language for the OTP sms message.

en: For English ar: For Arabic

use Shabayek\Sms\Facades\Sms;

$sms = Sms::setLanguage('ar');
        ->sendOtp('0120000000');

Adding Custom Cache Drivers

  • Writing The Driver

To create our custom sms driver, we first need to implement the Shabayek\Sms\Contracts\SmsGatewayContract contract. So, a new SMS gateway implementation might look something like this:

namespace Shabayek\Sms\Contracts;

class CustomSms implements SmsGatewayContract
{
    public function send($phone, $message): array;

    public function sendOtp($phone, $message = null);

    public function verify(string $phone, int $otp, $actualOtp = null): bool;

    public function balance() { }
}

Then, we need to add a new config for our custom sms driver. in sms config within connections key

'connections' => [
    ...
    'custom' => [
        'driver' => 'custom',
        'username' => 'username',
        'password' => 'password',
        'sender_id' => 'sender',
        'service' => 'normal',
    ],
    ...
],

we can finish our custom driver registration by calling the Sms facade's extend method:

Sms::extend('custom', function ($app) {
    return new CustomSms(config());
});

Testing

composer test

Security Vulnerabilities

If you've found a bug regarding security please mail esmail.shabayek@gmail.com instead of using the issue tracker.

License

The Laravel SMS Gateway package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-16