承接 cca-bheath/laravel-sms-clicksend 相关项目开发

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

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

cca-bheath/laravel-sms-clicksend

Composer 安装命令:

composer require cca-bheath/laravel-sms-clicksend

包简介

ClickSend Notifications channel for Laravel 5.8+

README 文档

README

This package makes it easy to send notifications using clicksend.com with Laravel 5.6+. Uses ClickSend PHP API wrapper [https://github.com/ClickSend/clicksend-php]

Contents

Installation

Install the package via composer:

composer require cca-bheath/laravel-sms-clicksend

Add the service provider to config/app.php:

...
'providers' => [
    ...
    NotificationChannels\ClickSend\ClickSendServiceProvider::class,
],
...

Publish the clicksend config file config/clicksend.php:

php artisan vendor:publish --provider="NotificationChannels\ClickSend\ClickSendServiceProvider" --tag="config"

Usage

Use ClickSendChannel in via() method inside your notification classes. Example:

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use NotificationChannels\ClickSend\ClickSendMessage;
use NotificationChannels\ClickSend\ClickSendChannel;

class ClickSendTest extends Notification
{

    public $token;

    /**
     * Create a notification instance.
     *
     * @param string $token
     */
    public function __construct($token)
    {
        $this->token = $token;
    }
    
    /**
     * Required
     */
    public function via($notifiable)
    {
        return [ClickSendChannel::class];
    }

    /**
     * Required
     */
    public function getMessage($notifiable)
    {  	
       	return "SMS test to user #{$notifiable->id} with token {$this->token} by ClickSend";
    }
    
    /**
     * Optional
     */
    public function updateClickSendMessage($message)
    {
        $message->setFrom('+15555555555');

        return $message;
    }
}

In notifiable model (User), include method routeNotificationForClickSend() that returns recipient mobile number:

...
public function routeNotificationForClickSend()
{
    return $this->phone;
}
...

Optional

If you want to use a custom notification route instead:

Notification::route('notification_for_click_send', '+15555555555')
              ->notify(new ClickSendTest());

From controller then send notification standard way:

$user = User::find(1);

try {
	$user->notify(new ClickSendTest('ABC123'));
}
catch (\Exception $e) {
	// do something when error
	return $e->getMessage();
}

Events

Following events are triggered by Notification. By default:

  • Illuminate\Notifications\Events\NotificationSending
  • Illuminate\Notifications\Events\NotificationSent

and this channel triggers one when submission fails for any reason:

  • Illuminate\Notifications\Events\NotificationFailed

To listen to those events create listener classes in app/Listeners folder e.g. to log failed SMS:

namespace App\Listeners;
	
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use NotificationChannels\ClickSend\ClickSendChannel;
	
class NotificationFailedListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Notification failed event handler
     *
     * @param  NotificationFailed  $event
     * @return void
     */
    public function handle(NotificationFailed $event)
    {
        // Handle fail event for ClickSend
        //
        if($event->channel == ClickSendChannel::class) {
	
            echo 'failed'; dump($event);
            
            $logData = [
            	'notifiable'    => $event->notifiable->id,
            	'notification'  => get_class($event->notification),
            	'channel'       => $event->channel,
            	'data'      => $event->data
            	];
            	
            Log::error('Notification Failed', $logData);
         }
         // ... handle other channels ...
    }
}

Then register listeners in app/Providers/EventServiceProvider.php

...
protected $listen = [

	'Illuminate\Notifications\Events\NotificationFailed' => [
		'App\Listeners\NotificationFailedListener',
	],

	'Illuminate\Notifications\Events\NotificationSent' => [
		'App\Listeners\NotificationSentListener',
	],

	'Illuminate\Notifications\Events\NotificationSending' => [
		'App\Listeners\NotificationSendingListener',
	],
];
...

API Client

To access the rest of ClickSend API you can get client from ClickSendApi:

$client = app(ClickSendApi::class)->getClient();
	
// then get for eaxample yor ClickSend account details:
$account =  $client->getAccount()->getAccount();
	
// or list of countries:
$countries =  $client->getCountries()->getCountries();

Config

  • CLICKSEND_DRIVER
    • clicksend or log
    • Setting to log will send the SMS message to the log file and not try to send it
  • CLICKSEND_ENABLED
    • If set to false the channel will not run and return true. This is good for testing
  • CLICKSEND_USERNAME
    • Username on ClickSend
    • You can see this information by click on the API Credentials link at the top of the dashboard
  • CLICKSEND_API_KEY
    • API Key on ClickSend
    • You can see this information by click on the API Credentials link at the top of the dashboard
  • CLICKSEND_SMS_FROM
    • Override the FROM on SMS and MMS messages
    • Can leave blank
  • CLICKSEND_PREFIX
    • Enforce that all to have this prefix
    • For example +1
    • This should only be used if you are sure that all to must have this prefix

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

Incomplete

$ composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

cca-bheath/laravel-sms-clicksend 适用场景与选型建议

cca-bheath/laravel-sms-clicksend 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.3k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「sms」 「notifications」 「laravel」 「ClickSend」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 cca-bheath/laravel-sms-clicksend 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cca-bheath/laravel-sms-clicksend 我们能提供哪些服务?
定制开发 / 二次开发

基于 cca-bheath/laravel-sms-clicksend 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-16