承接 haosheng0211/laravel-captcha 相关项目开发

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

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

haosheng0211/laravel-captcha

最新稳定版本:v1.0.1

Composer 安装命令:

composer require haosheng0211/laravel-captcha

包简介

A Laravel package providing unified captcha verification with support for reCAPTCHA, Turnstile, and hCaptcha

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package that provides a unified API for integrating multiple captcha services, including Google reCAPTCHA (v2 & v3), Cloudflare Turnstile, and hCaptcha. Easily switch between providers with minimal code changes.

Installation

You can install the package via composer:

composer require haosheng0211/laravel-captcha

You can publish the config file with:

php artisan vendor:publish --tag="captcha-config"

This is the contents of the published config file:

return [

    'enabled' => env('CAPTCHA_ENABLED', true),

    'default' => env('CAPTCHA_DRIVER', 'recaptcha'),

    'providers' => [
        'recaptcha' => [
            'version' => env('RECAPTCHA_VERSION', 'v2'),
            'site_key' => env('RECAPTCHA_SITE_KEY'),
            'secret_key' => env('RECAPTCHA_SECRET_KEY'),
            'score' => 0.5,
        ],
        'turnstile' => [
            'site_key' => env('TURNSTILE_SITE_KEY'),
            'secret_key' => env('TURNSTILE_SECRET_KEY'),
        ],
        'hcaptcha' => [
            'site_key' => env('HCAPTCHA_SITE_KEY'),
            'secret_key' => env('HCAPTCHA_SECRET_KEY'),
        ],
    ],

];

Configuration

Add the following environment variables to your .env file based on the captcha provider you want to use:

# Global settings
CAPTCHA_ENABLED=true
CAPTCHA_DRIVER=recaptcha

# Google reCAPTCHA
RECAPTCHA_VERSION=v2
RECAPTCHA_SITE_KEY=your-site-key
RECAPTCHA_SECRET_KEY=your-secret-key

# Cloudflare Turnstile
TURNSTILE_SITE_KEY=your-site-key
TURNSTILE_SECRET_KEY=your-secret-key

# hCaptcha
HCAPTCHA_SITE_KEY=your-site-key
HCAPTCHA_SECRET_KEY=your-secret-key

Usage

Using the Facade

use MrJin\Captcha\Facades\Captcha;

// Verify using the default driver
$result = Captcha::verify($request->input('captcha_token'), $request->ip());

// Verify using a specific driver
$result = Captcha::driver('turnstile')->verify($token, $ip);

// Check if captcha is enabled
if (Captcha::isEnabled()) {
    // ...
}

Using the Validation Rule

use MrJin\Captcha\Rules\CaptchaRule;

$request->validate([
    'captcha_token' => ['required', new CaptchaRule],
]);

// With a specific driver
$request->validate([
    'captcha_token' => ['required', new CaptchaRule('turnstile')],
]);

Supported Drivers

Driver Provider Versions
recaptcha Google reCAPTCHA v2, v3
turnstile Cloudflare Turnstile -
hcaptcha hCaptcha -

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固