GithubHelp home page GithubHelp logo

seungmun / laravel-sens Goto Github PK

View Code? Open in Web Editor NEW
40.0 3.0 10.0 43 KB

NCloud SENS notification channels for Lovely Laravel. NCP 문자 전송 모듈

License: MIT License

PHP 100.00%
laravel laravel-notifications ncloud-sens ncloud sens laravel-sms mms notification php notifications

laravel-sens's Introduction

NCLOUD SENS notifications channel for Laravel

Latest Stable Version Total Downloads License Build Status

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 seungmun/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

laravel-sens's People

Contributors

cable8mm avatar evans-kim avatar mo-zang avatar seungmun avatar shaul1991 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-sens's Issues

http 전송을 Laravel의 Http를 이용해서 할 수 있도록 수정 가능할까요?

ncloud의 경우 발송한 메세지, 알림톡의 리스트에 접근할 수 있는 권한을 주지 않다보니
내용을 직접 저장을 해야하는데,
Guzzle을 사용해서 전송되다보니 전송하고 받는 것을 저장할 방법이 없습니다.

Http를 사용하면 이벤트로 처리를 하거나
전송하는 값과 전송 결과를 접근할 수 있는 방법을 마련해주시거나 하면 좋겠습니다.

테스트는 해봤는데,
아래 부분을

            $this->httpClient()->post($endpoint['url'], [
                'headers' => $this->prepareRequestHeaders(
                    $endpoint['method'],
                    $endpoint['path']
                ),
                'body' => json_encode($params),
            ]);

아래와 같이 변경만 해도 간단하게 해결이 가능하긴 합니다.

            Http::withHeaders($this->prepareRequestHeaders(
                $endpoint['method'],
                $endpoint['path']
            ))->post($endpoint['url'], $params);

[URGENT ACTION REQUIRED] StyleCI Payment Details

StyleCI is migrating to a new payment system, and you must re-enter your payment information as soon as possible to continue using the StyleCI Monthly Solo plan. Please re-enter your payment details on the StyleCI account settings page, or directly by clicking here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.