PHPackages                             godruoyi/laravel-tencent007-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. godruoyi/laravel-tencent007-captcha

ActiveLibrary

godruoyi/laravel-tencent007-captcha
===================================

Laravel 腾讯防水墙

1.1.1(4y ago)6874MITPHP

Since Jun 14Pushed 4y agoCompare

[ Source](https://github.com/godruoyi/laravel-tencent007-captcha)[ Packagist](https://packagist.org/packages/godruoyi/laravel-tencent007-captcha)[ Docs](https://github.com/godruoyi/laravel-tencent007-captcha)[ RSS](/packages/godruoyi-laravel-tencent007-captcha/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (6)Versions (12)Used By (0)

 laravel tencent captcha
=========================

[](#-laravel-tencent-captcha-)

 [![StyleCI](https://camo.githubusercontent.com/fb88bea94c1c09e4132db5b0d14f8256776c944c95b4cb884b85097636082326/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3139313931373539352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/191917595) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/7419d0e4e77998126a7727918e65cfebacccf69f7e1f789a8cfb39107df74302/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676f6472756f79692f6c61726176656c2d74656e63656e743030372d636170746368612f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/godruoyi/laravel-tencent007-captcha/?branch=master) [![tencent captcha](https://camo.githubusercontent.com/854290f42eb27aca65ad858ca6b7cd596c47b5d2e66079213e93d4ccadf29495/68747470733a2f2f706f7365722e707567782e6f72672f676f6472756f79692f6c61726176656c2d74656e63656e743030372d636170746368612f762f737461626c65)](https://packagist.org/packages/godruoyi/laravel-tencent007-captcha) [![tencent captcha](https://camo.githubusercontent.com/e85321c4a8994af15179db8091ebd75e667d4f1d65b41e2b75410e352f3ef3df/68747470733a2f2f706f7365722e707567782e6f72672f676f6472756f79692f6c61726176656c2d74656e63656e743030372d636170746368612f646f776e6c6f616473)](https://packagist.org/packages/godruoyi/laravel-tencent007-captcha) [![tencent captcha](https://camo.githubusercontent.com/f50567c47fe79dd6934bd013ca5145b302d2ca476753847fa725941c94b4b0d0/68747470733a2f2f706f7365722e707567782e6f72672f676f6472756f79692f6c61726176656c2d74656e63656e743030372d636170746368612f6c6963656e7365)](https://packagist.org/packages/godruoyi/laravel-tencent007-captcha)

安装
--

[](#安装)

```
$ composer require godruoyi/laravel-tencent007-captcha -vvv
```

使用
--

[](#使用)

[查看 Demo](https://projects.godruoyi.com/007-demo/)

1. 发布腾讯云防水墙配置文件。

```
php artisan vendor:publish --provider="Godruoyi\Tencent007\ServiceProvider"
```

2. 修改应用根目录下的 `config/007.php` 中对应的参数。

接入
--

[](#接入)

在使用 SDK 前，最好到 [腾讯云防水墙](https://007.qq.com/) 了解验证码接入的基本流程。

### 客户端接入

[](#客户端接入)

1. 在 Head 标签中加入以下代码，引入验证 JS 文件（建议直接在 html 中引入）：

```

```

2. 在你想要激活验证码的 DOM 元素（eg. button、div、span）内加入以下 id 及属性：

```

验证
```

3. 为验证码创建回调函数，注意函数名要与 data-cbfn 相同：

```
window.callback = function(res){
    console.log(res)
    // res（用户主动关闭验证码）= {ret: 2, ticket: null}
    // res（验证成功） = {ret: 0, ticket: "String", randstr: "String"}
    if(res.ret === 0){
        alert(res.ticket)   // 票据
        // 将这里的 ticket randstr 一起随接口提交给后端 API
    }
}
```

完成以上操作后，点击激活验证码的元素，即可弹出验证码。

> 以上客户端接入文档来自腾讯防水墙，更多相关配置请前往 [腾讯云防水墙](https://007.qq.com/)

### 服务端使用

[](#服务端使用)

你可以通过客户端提供的 ticketVerify 方法来快速验证用户。

```
class UserRegisterController extends Controller
{
    public function __invoke(Request $request)
    {
        $response = app('007')->ticketVerify($request->ticket, $request->randstr);

        if (!$response->success()) {
            // 不可信用户
        }
    }
}
```

它将返回一个类型为 `Godruoyi\Tencent007\Response` 响应，并提供了一些有用的方法。

```
// bool 是否验证成功
$response->success();

// string 验证错误信息
$response->message();

// array|null 请求返回的原始数据
$response->getOriginal();

// int 用户恶意等级
$response->level();
```

我们还提供了一个请求频率限制的中间件 `ThrottleRequests`，它继承了 Laravel 默认的 ThrottleRequests 中间件， 可以用它来快速实现 `一分钟请求超过 60 次出现滑块验证` 的效果 —— [Demo](https://projects.godruoyi.com/007-demo/)

为了使用该中间件，你需要在 `app/Http/Kernel.php` 中添加配置。

```
protected $routeMiddleware = [
    // ...
    'throttle.007' => \Godruoyi\Tencent007\Middlewares\ThrottleRequests::class,
];
```

然后在你的路由文件中使用该中间件即可（throttle.007:60,1 —— 表示 1 分钟请求超过 60 次，出现滑块验证）。

```
Route::post('users/register', 'UserRegisterController')->middleware('throttle.007:60,1');
```

其实查看源码你就知道，当请求太多需要滑块验证时，我们会抛出一个 Exception。

```
use Symfony\Component\HttpKernel\Exception\HttpException;

class NeedCaptchaAuthException extends HttpException
{
    public function __construct($statusCode = 429, $message = 'Need tencent captcha certification.')
    {
        parent::__construct($statusCode, $message);
    }
}
```

该 Exception 继承自 HttpException，Laravel 默认会返回一个状态码为 429 的响应。

```
HTTP/1.1 429 Too Many Requests
Server: nginx/1.11.9
Content-Type: application/json
Transfer-Encoding: chunked
Cache-Control: no-cache, private
Date: Sun, 24 Jun 2018 10:15:52 GMT
Connection: keep-alive

{"message":"Too Many Requests"}
```

如果你想自定义返回类型，你可在 `App\Exceptions\Handler.php` 中捕获并处理。

```
namespace App\Exceptions;

use Exception;
use Godruoyi\Tencent007\Exceptions\NeedCaptchaAuthException;
use Godruoyi\Tencent007\Exceptions\RequestNotPassedException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    public function render($request, Exception $exception)
    {
        if ($exception instanceof NeedCaptchaAuthException) {
            return response()->json([
                'code' => -429,
                'msg'  => '请先通过滑块验证'
            ]);
        } elseif ($exception instanceof RequestNotPassedException) {
            return response()->json([
                'code' => -403,
                'msg'  => '非法用户'
            ]);
        }

        return parent::render($request, $exception);
    }
}
```

前端需要根据接口返回的状态码做出相应处理。

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity66

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~72 days

Recently: every ~177 days

Total

11

Last Release

1805d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5520e5d6782001b3417724a0d5942bb9bfc6885f5aac48d5e69891ef3240141d?d=identicon)[godruoyi](/maintainers/godruoyi)

---

Tags

tencent captchaqq 007 captcha

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/godruoyi-laravel-tencent007-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/godruoyi-laravel-tencent007-captcha/health.svg)](https://phpackages.com/packages/godruoyi-laravel-tencent007-captcha)
```

###  Alternatives

[vemcogroup/laravel-sparkpost-driver

SparkPost driver to use with Laravel 6.x|7.x|8.x|9.x|10.x

421.7M1](/packages/vemcogroup-laravel-sparkpost-driver)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.6k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
