digitaltunnel/otakit 问题修复 & 功能扩展

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

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

digitaltunnel/otakit

最新稳定版本:v1.0.1

Composer 安装命令:

composer create-project digitaltunnel/otakit

包简介

OtaKit is a Laravel package designed to facilitate the generation and validation of One-Time Passwords (OTPs) within Laravel applications.

README 文档

README

Otakit

Otakit

Latest Version on Packagist Total Downloads

OtaKit is a Laravel package designed to facilitate the generation and validation of One-Time Passwords (OTPs) within Laravel applications.

1. Installation

You can install the package via Composer:

composer require digitaltunnel/otakit

2. Publish Provider

After installing the package, publish its service provider and configuration file using the following Artisan command:

php artisan vendor:publish --provider="DigitalTunnel\Otakit\Providers\OtakitServiceProvider"

This will publish the configuration file (config/otakit.php) to your application's config directory. You can customize the OTP length and expiration time in this file.

3. Usage

3.1 Prepare Model

To use the OtaKit package, you need to add the Otakit trait to the model you want to generate OTPs for. This trait provides the necessary methods to generate and validate OTPs. Model can be any model in your application, such as User, Customer ..., extended from the Illuminate\Database\Eloquent\Model class.

    use DigitalTunnel\OtaKit\Traits\Otakit;
    
    class User extends Model
    {
        use Otakit;
    }

3.2 Generate OTP

To generate an OTP for an otpable model, use the GenerateOtp action:

    use App\Models\User;

    $user = User::find(1);
    $otp = $user->generateOtp();

generateOtp can accept two optional parameters: length and ttl. The length parameter specifies the length of the OTP to generate, while the ttl parameter specifies the time to live for the OTP in minutes.

    $otp = $user->generateOtp(length: 6, ttl: 10);

or you can use the generateOtp action directly:

    use App\Models\Customer;
    use DigitalTunnel\Otakit\Actions\GenerateOtp;
    
    $otpable = Customer::find(1);
    
    $otp = (new GenerateOtp)->handle(
        otpable :$otpable,
        length :4,
        ttl: 5 // Time to live in minutes
    )

3.3 Validate OTP

To validate an OTP, use the validateOtp method on the otpable model:

    use App\Models\User;

    $user = User::find(1);
    $isValid = $user->validateOtp(
        otp: 123456
    );

or you can use the validateOtp action directly:

    use App\Models\Customer;
    use DigitalTunnel\Otakit\Actions\ValidateOtp;
    
    $otpable = Customer::find(1);
    
    $isValid = (new ValidateOtp)->handle(
        otpable :$otpable,
        otp: 123456
    )

4. Listen to Events

The Otakit package fires events when an OTP is generated and when an OTP is validated. You can listen to these events in your application by adding event listeners to your EventServiceProvider.

    protected $listen = [
        OtpGenerated::class => [
            // you listeners
            // send otp though sms or email or any other channel
            // log the otp generated
            // etc...
        ],
        
        OtpValidationSuccess::class => [
            // you listeners
            // log the otp validation success
            // etc...
        ],
        
        OtpValidationFailed::class => [
            // you listeners
            // log the otp validation failed
            // etc...
        ],
    ];

5. Tests

This package is thoroughly tested using Pest. To run the tests, use the following command:

    ./vendor/bin/pest

Test Coverage

OTP generation and storage.
OTP verification (valid, invalid, and expired cases).
Event dispatching for OTP lifecycle events.

6. License

This package is open-source software licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome!.

Security Vulnerabilities

If you discover a security vulnerability within this package, please send an e-mail to hey@digitaltunnel.net. All security vulnerabilities will be promptly addressed.

Credits

This package is developed and maintained by Digital Tunnel.

Support

If you encounter any issues or have questions, please open an issue on the GitHub repository.

digitaltunnel/otakit 适用场景与选型建议

digitaltunnel/otakit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 digitaltunnel/otakit 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-07