定制 ivansotelo/twilio-verify 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ivansotelo/twilio-verify

Composer 安装命令:

composer require ivansotelo/twilio-verify

包简介

Verify Phone Numbers in a Laravel PHP Application with Twilio Verify

README 文档

README

Build Status Total Downloads Latest Stable Version License

Introduction

TwilioVerify makes it easier and safer than custom verification systems to verify a user’s phone number. It ensures that the phone number is valid by sending a short code via SMS to the number during registration. This can help reduce the number of fake accounts created and failure rates when sending SMS notifications to users.

This package use Twilio notifications channel.

Contents

Installation

You can install the package via composer:

composer require ivansotelo/twilio-verify

In app/config/app.php add the following :

IvanSotelo\TwilioVerify\TwilioVerifyServiceProvider::class,

Configuration

Add your Twilio Account SID, Auth Token, and From Number (optional) to your .env:

TWILIO_USERNAME=XYZ # optional when using auth token
TWILIO_PASSWORD=ZYX # optional when using auth token
TWILIO_AUTH_TOKEN=ABCD # optional when using username and password
TWILIO_ACCOUNT_SID=1234 # always required
TWILIO_FROM=100000000 # otional default from
TWILIO_ALPHA_SENDER=HELLO # optional
TWILIO_DEBUG_TO=23423423423 # Set a number that call calls/messages should be routed to for debugging

Advanced configuration

Run php artisan vendor:publish --provider="IvanSotelo\TwilioVerify\TwilioVerifyServiceProvider" --tag=config

/config/twilio-verify.php

To run the migrations from this package use the following command:

php artisan migrate --path="/vendor/ivansotelo/twilio-verify/database/migrations"

The package by default use the App\User:class to get the table name.

To customize the migration, publish it with the following command:

php artisan vendor:publish --provider="IvanSotelo\TwilioVerify\TwilioVerifyServiceProvider" --tag="migrations"

Twilio Verify assumes your MustVerifyPhone trait will be the App\User class that ships with Laravel. If you wish to change this you can specify a different model in your .env file:

TWILIO_VERIFY_MODEL=App\User

Usage

Add the MustVerifyPhone trait to your model definition. This trait provides various methods to allow you to send verification phone code.

use IvanSotelo\TwilioVerify\Traits\MustVerifyPhone;
use IvanSotelo\TwilioVerify\Contracts\MustVerifyPhoneContract;

class User extends Authenticatable implements MustVerifyPhoneContract
{
    use MustVerifyPhone, Notifiable;

    /**
     * Route notifications for the Twilio channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForTwilio()
    {
        return $this->phone_number;
    }

}

On EventServiceProvider attach SendPhoneVerificationNotification to the Illuminate\Auth\Events\Registered event:

namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Verified;
use Illuminate\Auth\Events\Registered;
use IvanSotelo\TwilioVerify\Listeners\SendPhoneVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class => [
            SendPhoneVerificationNotification::class,
        ],
        Verified::class => [
            // You can attach some listener
        ],
    ];
}

To register the default middleware add the following lines to the $routeMiddleware array within the app/Http/Kernel.php file:

protected $routeMiddleware = [
    // …
    'isVerified' => \IvanSotelo\TwilioVerify\Http\Middleware\EnsurePhoneIsVerified::class,

Apply the middleware on your routes:

Route::group(['middleware' => ['isVerified']], function () {
    // …

By default this packages ships with two routes.

Route::get('phone/verify/{code}', 'VerificationController@verify')->name('verification.verify');
Route::post('phone/resend', 'VerificationController@resend')->name('verification.resend');

To customize the translations you may publish the files to your resources/lang/vendor folder using the following command:

php artisan vendor:publish --provider="IvanSotelo\TwilioVerify\TwilioVerifyServiceProvider" --tag="translations"

License

TwilioVerify is open-sourced software licensed under the MIT license.

ivansotelo/twilio-verify 适用场景与选型建议

ivansotelo/twilio-verify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.23k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ivansotelo/twilio-verify 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 25.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-30