承接 alexgeno/phone-verification-laravel 相关项目开发

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

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

alexgeno/phone-verification-laravel

Composer 安装命令:

composer require alexgeno/phone-verification-laravel

包简介

A library for phone verification via Laravel notification channels. Any notification channel can be used as a sender, and Redis or MongoDB can be used as a storage.

README 文档

README

Build Status Build Status Build Status Coverage Status

Signing in or signing up on a modern website or mobile app typically follows these steps:

  • A user initiates verification by submitting a phone number
  • The user receives an SMS or a call with a one-time password (OTP)
  • The user completes verification by submitting the OTP

This library is built on top of alexeygeno/phone-verification-php and allows to set this up

Supported features

  • Easy switching between different storages and notification channels
  • Configurable length and expiration time for OTP
  • Configurable rate limits
  • Localization
  • Usage with different Laravel approaches: automatic injection, facade, and commands
  • Logging notifications instead of sending real ones, beneficial for non-production environments
  • Out-of-the-box routes for quick start

Requirements

Installation

composer require alexgeno/phone-verification-laravel predis/predis laravel/vonage-notification-channel

Note: Redis as a storage and Vonage as a notification channel are defaults in the configuration

Usage

Automatic injection

public function initiate(\AlexGeno\PhoneVerification\Manager\Initiator $manager)
{
    $manager->initiate('+15417543010');
}
public function complete(\AlexGeno\PhoneVerification\Manager\Completer $manager)
{
    $manager->complete('+15417543010', 1234);
}

Facade

\AlexGeno\PhoneVerificationLaravel\Facades\PhoneVerification::initiate('+15417543010');
\AlexGeno\PhoneVerificationLaravel\Facades\PhoneVerification::complete('+15417543010', 1234);

Commands

php artisan phone-verification:initiate --to=+15417543010
php artisan phone-verification:complete --to=+15417543010 --otp=1234

Routes

curl -d "to=+15417543010" localhost/phone-verification/initiate
{"ok":true,"message":"Sms has been sent. Check your Phone!"}
curl -d "to=+15417543010&otp=1234" localhost/phone-verification/complete
{"ok":true,"message":"The verification is done!"}

Note: The package routes are available by default. To make them unavailable without redefining the service provider, change the bool key phone-verification.sender.to_log in the configuration

Configuration

[
    'storage' => [
        'driver' => 'redis', // 'redis' || 'mongodb'
        'redis' => [
            'connection' => 'default',
            // the key settings - normally you don't need to change them
            'settings' => [
                'prefix' => 'pv:1',
                'session_key' => 'session',
                'session_counter_key' => 'session_counter',
            ],
        ],
        'mongodb' => [
            'connection' => 'mongodb',
            // the collection settings - normally you don't need to change them
            'settings' => [
                'collection_session' => 'session',
                'collection_session_counter' => 'session_counter',
            ],
        ],
    ],
    'sender' => [
        'driver' => 'vonage', // 'vonage' || 'twilio' || 'messagebird' and many more https://github.com/laravel-notification-channels
        'channel' => \Illuminate\Notifications\Channels\VonageSmsChannel::class, // \Illuminate\Notifications\Channels\VonageSmsChannel::class || \NotificationChannels\Twilio\TwilioChannel::class || \NotificationChannels\Messagebird\MessagebirdChannel::class and many more https://github.com/laravel-notification-channels
        'to_log' => false, // if enabled: instead of sending a real notification, debug it to the app log
    ],
    'routes' => true, // managing the availability of the package routes without redefining the service provider
    'manager' => [
        'otp' => [
            'length' => env('PHONE_VERIFICATION_OTP_LENGTH', 4), // 1000..9999
        ],
        'rate_limits' => [
            'initiate' => [ // for every 'to' no more than 10 initiations over 24 hours
                'period_secs' => env('PHONE_VERIFICATION_RATE_LIMIT_INITIATE_PERIOD_SECS', 86400),
                'count' => env('PHONE_VERIFICATION_RATE_LIMIT_INITIATE_COUNT', 10),
            ],
            'complete' => [ // for every 'to' no more than 5 failed completions over 5 minutes
                'period_secs' => env('PHONE_VERIFICATION_RATE_LIMIT_COMPLETE_PERIOD_SECS', 300), // this is also the expiration period for OTP
                'count' => env('PHONE_VERIFICATION_RATE_LIMIT_COMPLETE_COUNT', 5),
            ],
        ],
    ],
];

Different storages and notification channels

To switch between available storages and notifications channels, install the respective package and update the configuration. For example, to use Mongodb as a storage and Twilio as a notification channel:

composer require jenssegers/mongodb laravel-notification-channels/twilio
[
    'storage' => [
        'driver' => 'mongodb',
        // ... 
    ],
    'sender' => [
        'driver' => 'twilio',
        'channel' => \NotificationChannels\Twilio\TwilioChannel::class,
        // ... 
    ],
    // ... 
]

If the available options are not sufficient, you can redefine the service provider and add a custom storage (implementing \AlexGeno\PhoneVerification\Storage\I) or/and a sender (implementing \AlexGeno\PhoneVerification\Sender\I)

Publishing

Config

php artisan vendor:publish --tag=phone-verification-config

Localization

php artisan vendor:publish --tag=phone-verification-lang

Migrations

php artisan vendor:publish --tag=phone-verification-migrations

Note: Only the MongoDB storage driver requires migrations

alexgeno/phone-verification-laravel 适用场景与选型建议

alexgeno/phone-verification-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.6k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2023 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 alexgeno/phone-verification-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.6k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-04