lbhurtado/missive 问题修复 & 功能扩展

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

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

lbhurtado/missive

Composer 安装命令:

composer require lbhurtado/missive

包简介

Add SMS domain to a Laravel project - route, models, migrations, jobs, notifications, etc.

README 文档

README

Latest Version on Packagist Build Status Quality Score Total Downloads

Add SMS domain to a Laravel project - route, models, migrations, events, jobs, actions, etc.

Installation

You can install the package via composer:

composer require lbhurtado/missive

publish vendor files:

php artisan vendor:publish --provider="LBHurtado\Missive\MissiveServiceProvider"
php artisan notifications:table
php artisan migrate

optionally, if you want sms charging:

composer dumpautoload
php artisan db:seed --class=AirtimeSeeder

then uncomment the middleware in missive.php

inherit models:

namespace App;

use LBHurtado\EngageSpark\Traits\HasEngageSpark;
use LBHurtado\Missive\Models\Contact as BaseContact;

class Contact extends BaseContact
{
    use HasEngageSpark;
}

customize the tables and classes e.g. App\Contact:

[
	'table_names' => [
		'smss'     => 's_m_s_s',
		'contacts' => 'contacts',
		'relays'   => 'relays',
        'topups'   => 'topups',
	],
    'classes' => [
            'models' => [
                'airtime' => \LBHurtado\Missive\Models\Airtime::class,
                'contact' => \App\Contact::class,
                'relay' => \LBHurtado\Missive\Models\Relay::class,
                'sms' => \LBHurtado\Missive\Models\SMS::class
            ],
            'commands' => [
                'sms' => [
                    'create' => \LBHurtado\Missive\Commands\CreateSMSCommand::class
                ]
            ],
            'handlers' => [
                'sms' => [
                    'create' => \LBHurtado\Missive\Handlers\CreateSMSHandler::class
                ]
            ],
            'middlewares' => [
                'sms' => [
                    'relay' => [
                        \LBHurtado\Missive\Validators\CreateSMSValidator::class,
                        \LBHurtado\Missive\Responders\CreateSMSResponder::class,
    //                \LBHurtado\Missive\Actions\Middleware\ChargeSMSMiddleware::class,
                    ],
                    'verify' => [
                        \LBHurtado\Missive\Validators\CreateSMSValidator::class,
                        \LBHurtado\Missive\Responders\CreateSMSResponder::class,
                        \LBHurtado\Missive\Actions\Middleware\VerifyContactHandler::class,
    //                    \LBHurtado\Missive\Actions\Middleware\ChargeSMSMiddleware::class,
                    ],
                    'topup' => [
                        \LBHurtado\Missive\Validators\CreateSMSValidator::class,
                        \LBHurtado\Missive\Responders\CreateSMSResponder::class,
                        \LBHurtado\Missive\Actions\Middleware\TopupMobileHandler::class,
    //                    \LBHurtado\Missive\Actions\Middleware\ChargeSMSMiddleware::class,
                    ],
                ],
            ]
        ]
]

customize the routes in routes/sms.php:

use LBHurtado\EngageSpark\Notifications\Adhoc;

$router = resolve('missive:router');

$router->register('LOG {message}', function (string $path, array $values) use ($router) {
    \Log::info($values['message']);
    
    tap($router->missive->getSMS()->origin, function ($contact) use ($values) {
        $message = $values['message'];
        $contact->notify(new Adhoc("{$contact->mobile}: $message"));
    });
});

Usage

use LBHurtado\Missive\Models\SMS;
use LBHurtado\Missive\Jobs\CreateSMS;
use LBHurtado\Missive\Repositories\SMSRepository;

CreateSMS::dispatch($attributes);
$sms = SMS::first();

$smss = app(SMSRepository::class);
$sms = $smss->first();
use LBHurtado\Missive\Models\Contact;
use LBHurtado\Missive\Jobs\CreateContact;
use LBHurtado\Missive\Repositories\ContactRepository;

CreateContact::dispatch($mobile);
$contact = Contact::first();

$contacts = app(ContactRepository::class);
$contact = $contacts->first();
use LBHurtado\Missive\Models\Relay;
use LBHurtado\Missive\Jobs\CreateRelay;
use LBHurtado\Missive\Repositories\RelayRepository;

CreateRelay::dispatch($mobile);
$relay = Relay::first();

$relays = app(RelayRepository::class);
$relay = $relays->first();

add otp verification to your contacts:

use LBHurtado\Missive\Traits\HasOTP;
use LBHurtado\Missive\Models\Contact;

$contact = Contact::find(1);
$otp = $contact->challenge()->now();
//default period for OTP is 360 seconds
//modify it in .env i.e. DEFAULT_OTP_PERIOD=1000


if ($contact->verify($otp) == true) {
    //code here
}

sms relay

curl -X POST \
  http://laravel.app/api/sms/relay \
  -H 'Accept: */*' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Host: laravel.app' \
  -d '{
    "secret": "CFAWG4KCE44XWACTZZX24Z7LPW99XTWT",
    "from": "+639171234567",
    "to": "+639187654321",
    "message": "LOG test message"
}'

sms OTP verification

curl -X POST \
  http://laravel.app/api/sms/verify \
  -H 'Accept: */*' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Host: laravel.app' \
  -d '{
    "secret": "CFAWG4KCE44XWACTZZX24Z7LPW99XTWT",
    "from": "+639171234567",
    "to": "+639187654321",
    "message": "123456"
}'

sms topup

curl -X POST \
  http://laravel.app/api/sms/topup \
  -H 'Accept: */*' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Host: laravel.app' \
  -d '{
    "secret": "CFAWG4KCE44XWACTZZX24Z7LPW99XTWT",
    "from": "+639171234567",
    "to": "+639187654321",
    "message": "09171234567 25"
}'

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email lester@hurtado.ph instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固