corean/laravel-sens
Composer 安装命令:
composer require corean/laravel-sens
包简介
NCloud SENS notification channels for Lovely Laravel.
关键字:
README 文档
README
This package makes it easy to send notification using ncloud sens with Laravel.
And We are working on an unofficial sdk development public project so that ncloud sens can be used in php more flexibly.
You can check the project here. (https://github.com/seungmun/sens-php)
Official Community
Prerequisites
Before you get started, you need the following:
- PHP >= 7.2 (9.x also compatible)
- Laravel (9.x / 8.x / 7.x / 6.x)
Installation
You can install the package via composer:
composer require corean/laravel-sens
The package will automatically register itself.
You can publish the config with:
php artisan vendor:publish --provider="Seungmun\Sens\SensServiceProvider" --tag="config"
Also, you can use it without publish the config file can be used simply by adding environment variables with:
SENS_ACCESS_KEY=your-sens-access-key SENS_SECRET_KEY=your-sens-secret-key SENS_SERVICE_ID=your-sens-service-id SENS_ALIMTALK_SERVICE_ID=your-alimtalk-service-id SENS_PlUS_FRIEND_ID=your-plus-friend-id
If you want to put the sms_from value in your .env,
config/services.php
/* |-------------------------------------------------------------------------- | SMS "From" Number |-------------------------------------------------------------------------- | | This configuration option defines the phone number that will be used as | the "from" number for all outgoing text messages. You should provide | the number you have already reserved within your Naver Cloud Platform | /sens/sms-calling-number of dashboard. | */ 'sens' => [ 'services' => [ 'sms' => [ 'sender' => env('SENS_SMS_FROM'), ], ], ],
.env:
SENS_SMS_FROM=1234567890
Usage
This package can be used using with the Laravel default notification feature.
1) Request to send a SMS
php artisan make:notification SendPurchaseReceipt
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Seungmun\Sens\Sms\SmsChannel; use Seungmun\Sens\Sms\SmsMessage; use Illuminate\Notifications\Notification; class SendPurchaseReceipt extends Notification { use Queueable; /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [SmsChannel::class]; } /** * Get the sens sms representation of the notification. * * @param mixed $notifiable * @return SmsMessage */ public function toSms($notifiable) { return (new SmsMessage) ->to($notifiable->phone) ->from('055-000-0000') ->content('Welcome: https://open.kakao.com/o/g3dWlf0') ->contentType('AD')// You can ignore it (default: COMM) ->type('SMS'); // You can ignore it (default: SMS) } }
use App\User; use App\Notifications\SendPurchaseReceipt; User::find(1)->notify(new SendPurchaseReceipt);
2) Request to send MMS
php artisan make:notification SendPurchaseInvoice
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Seungmun\Sens\Sms\SmsChannel; use Seungmun\Sens\Sms\SmsMessage; use Illuminate\Http\UploadedFile; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Filesystem\FileNotFoundException; class SendPurchaseInvoice extends Notification { use Queueable; /** @var UploadedFile */ private $image; /** * Create a new notification instance. * * @param UploadedFile $image */ public function __construct(UploadedFile $image) { $this->image = $image; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [SmsChannel::class]; } /** * Get the sens sms representation of the notification. * * @param mixed $notifiable * @return SmsMessage * @throws FileNotFoundException */ public function toSms($notifiable) { return (new SmsMessage) ->type('MMS') ->to($notifiable->phone) ->from('055-000-0000') ->content('This is your invoice.\nCheck out the attached image.') /* file's path string or UploadedFile object of Illuminate are allowed */ ->file('filename.jpg', $this->image); } }
<?php use App\User; use App\Notifications\SendPurchaseReceipt; // In this case, you should only pass UploadedFile object as a parameter. // If when you need to pass a file path string as a parameter, change your notification class up. User::find(1)->notify(new SendPurchaseReceipt(request()->file('image')));
Now User id: 1 which has own phone attribute would receive a sms or mms message soon.
3) Request send AlimTalk
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Seungmun\Sens\AlimTalk\AlimTalkChannel; use Seungmun\Sens\AlimTalk\AlimTalkMessage; class SendPurchaseInvoice extends Notification { use Queueable; /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [AlimTalkChannel::class]; } /** * Get the sens sms representation of the notification. * * @param mixed $notifiable * @return \Seungmun\Sens\AlimTalk\AlimTalkMessage */ public function toAlimTalk($notifiable) { return (new AlimTalkMessage()) ->templateCode('TEMPLATE001') // required ->to($notifiable->phone) // required ->content('Evans, Your order is shipped.') //required ->countryCode('82') // optional ->addButton(['type' => 'DS', 'name' => 'Tracking of Shipment']) // optional ->setReserved('2020-05-31 14:20', 'Asia/Seoul'); // optional } }
Features
- SMS(LMS) and MMS
- Kakao Alimtalk
corean/laravel-sens 适用场景与选型建议
corean/laravel-sens 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-sms」 「sens」 「ncloud」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 corean/laravel-sens 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 corean/laravel-sens 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 corean/laravel-sens 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A mobile phone number validation solution based on laravel
NCloud SENS notification channels for Lovely Laravel.
TurboSMS for Laravel 5+
SMS sent, never so simple.
Provides BluedotSms notification channel for Laravel
Alfabank REST API integration
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-15