承接 tookantech/chapaar 相关项目开发

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

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

tookantech/chapaar

最新稳定版本:1.8.4

Composer 安装命令:

composer require tookantech/chapaar

包简介

This package provides a flexible way to send and verify messages through various SMS providers. It offers integration with multiple drivers, making it easy to use different SMS service providers without getting locked into a specific one.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Chapaar offers flexible message sending and verification through multiple SMS providers, with easy integration and no lock-in to any specific provider.

Available Drivers

Installation

You can install the package via Composer:

composer require tookantech/chapaar

Configuration

You can publish the config file with:

php artisan vendor:publish --tag="chapaar-config"

This will create a chapaar.php configuration file in your config directory, where you can set the default driver and configure driver-specific settings.

This is the contents of the published config file:

return [
    'default' => env('CHAPAAR_DRIVER', 'kavenegar'),

    'drivers' => [
        'kavenegar' => [
            'url' => 'https://api.kavenegar.com/v1/',
            'api_key' => '',
            'line_number' => ''
        ],
        'smsir' => [
            'url' => 'https://api.sms.ir/v1/',
            'api_key' => '',
            'line_number' => '',
        ],
        'ghasedak' => [
            'url'         => 'https://api.ghasedak.me/v2/',
            'api_key'     => '',
            'line_number' => '',
        ],
    ],
];

Usage

Using the Chapaar Facade

If you want to use the Chapaar package without Laravel's built-in notification system, you can utilize the Chapaar facade directly. This allows you to send and verify messages using different SMS providers.

Sending a Simple Message

use TookanTech\Chapaar\Facades\Chapaar;
use TookanTech\Chapaar\SmsMessage;

$message = (new SmsMessage())->driver()
    ->setFrom('12345678')
    ->setTo('0912111111')
    ->setContent('Hello, this is a test message.');

$response = Chapaar::send($message);

Sending With Template Message

use TookanTech\Chapaar\Facades\Chapaar;
use TookanTech\Chapaar\SmsMessage;

#Kavenegar
$message =(new SmsMessage())
    ->driver()
    ->setTemplate("invoice-paid")
    ->setTo('09121111111')
    ->setTokens([
        '123', // token
        '456', // token2
        '789', // token3
        '111', // token10, with 4 space
        '222', // token20, with 8 space
    ]);
    
# SmsIr
$message =(new SmsMessage())
    ->driver()
    ->setTemplate('invoice-paid')
    ->setTo('09121111111')
    ->setTokens([
        'code' => '123' // 'variable_name' => 'value'
    ]);
    
# Ghasedak
$message =(new SmsMessage())
    ->driver()
    ->setTemplate("invoice-paid")
    ->setTo('09121111111')
    ->setTokens([
        'test1', // param1
        'test2'  // param2
    ]);

$response = Chapaar::verify($message);

Sending Without using default driver

use TookanTech\Chapaar\Facades\Chapaar;
use TookanTech\Chapaar\SmsMessage;
use TookanTech\Chapaar\Enums\Drivers;

$message = (new SmsMessage())
    ->driver(Drivers::SMSIR)
    ->setFrom('12345678')
    ->setTo('0912111111')
    ->setContent('Hello, this is a test message.');

$response = Chapaar::send($message);

Get Latest Outbox messages it automatically get the latest sent messages for default driver

$response = Chapaar::outbox(100);

Using In Notifications

Please review laravel notifications on how use notifications in laravel.

use TookanTech\Chapaar\SmsChannel;
class InvoicePaid extends KavenegarBaseNotification
{
    public function via($notifiable): array
    {
        return [SmsChannel::class];
    }
    public function toSms($notifiable)
    {
        return (new SmsMessage)->driver()
        ->setTemplate('verify')
        ->setTokens([123],[456])
    }
}

class User extends Authenticatable
{
    use Notifiable;

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

}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-23