定制 overtrue/laravel-qcloud-captcha 二次开发

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

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

overtrue/laravel-qcloud-captcha

Composer 安装命令:

composer require overtrue/laravel-qcloud-captcha

包简介

腾讯云验证码服务

README 文档

README

CI Latest Stable Version Latest Unstable Version Total Downloads License

腾讯云验证码是为网页、App 及小程序开发者提供的安全验证服务,目前网页及 App 支持以 Web 前端接入、App 端接入(iOS 和 Android)方式接入验证码服务,小程序开发者可以使用 小程序插件接入 方式接入验证码服务,基于腾讯多年的大数据积累和人工智能决策引擎,构建智能分级验证模型,最大程度保护业务安全的同时,提供更精细化的用户体验。

Sponsor me

Installing

$ composer require overtrue/laravel-qcloud-captcha -vvv

Config

请在 config/services.php 中配置以下内容:

    //...
    // 验证码服务
    'captcha' => [
        // 腾讯云 API 秘钥:SecretId,SecretKey
        // https://console.cloud.tencent.com/cam/capi
        'secret_id' => env('CAPTCHA_SECRET_ID'),
        'secret_key' => env('CAPTCHA_SECRET_KEY'),
        
        // 验证码服务秘钥:CaptchaAppId,AppSecretKey
        'app_id' => env('CAPTCHA_APP_ID'), 
        'app_secret_key' => env('CAPTCHA_APP_SECRET_KEY'),
        
        // 以下非必填
        'channel' =>  'web', // 渠道:web/miniapp,默认 web
        'endpoint' => env('CAPTCHA_ENDPOINT'), // 默认: captcha.tencentcloudapi.com
    ],

或者配置成多场景:

    //...
    // 验证码服务
    'captcha' => [
        // 默认 app 名称
        'default' => 'login',
        
        // app 配置
        'apps' => [
            'login' => [
                'secret_id' => env('CAPTCHA_LOGIN_SECRET_ID'),
                'secret_key' => env('CAPTCHA_LOGIN_SECRET_KEY'),
                'app_id' => env('CAPTCHA_LOGIN_APP_ID'), 
                'app_secret_key' => env('CAPTCHA_LOGIN_APP_SECRET_KEY'),
            ],
            'register' => [
                'secret_id' => env('CAPTCHA_REGISTER_SECRET_ID'),
                'secret_key' => env('CAPTCHA_REGISTER_SECRET_KEY'),
                'app_id' => env('CAPTCHA_REGISTER_APP_ID'), 
                'app_secret_key' => env('CAPTCHA_REGISTER_APP_SECRET_KEY'),
            ],
            //...
        ],
    ],

API

获取检查结果

调用对应 API 返回 ticket 校验结果,返回值结构请参考官方 API 文档。

接口请求频率限制:1000次/秒。

use Overtrue\LaravelQcloudCaptcha\Captcha;

array Captcha::validate(string $ticket, ?string $app = null, ?string $nonce = null);
array Captcha::validateWebTicket(string $ticket, ?string $app = null, ?string $nonce = null);
array Captcha::validateMiniAppTicket(string $ticket, ?string $app = null);

验证失败将抛出以下异常:

  • Overtrue\LaravelQcloudCaptcha\InvalidTicketException
    • $ticket - (string) 被检测的 ticket
    • $response - (array) API 原始返回值

使用表单校验规则

$this->validate($request, [
	'ticket' => 'required|captcha:randstr',
	'avatar' => 'required|url|ims',
	'description' => 'required|tms:strict',
	'logo_url' => 'required|url|ims:logo',
]);

规则参数

Web 类型验证码校验时需要传入回调时的 前端回调函数返回的随机字符串 对应的表单名称,例如请求后端时使用 randstr 作为表单名称提交随机字符串:

// 请求内容
[
    'ticket' => 'xxxxxxxxx',
    'randstr' => 'xxxxxxxxx',
],

//1. 使用默认应用,并以请求中 `randstr` 作为随机字符串校验
'ticket' => 'required|captcha:randstr', 

//2. 使用 `login` 应用,并以请求中 `randstr` 作为随机字符串校验
'ticket' => 'required|captcha:login,randstr',

小程序 验证码没有随机字符串参数:

// 请求内容
[
    'ticket' => 'xxxxxxxxx',
],

//1. 使用默认应用
'ticket' => 'required|captcha', 

//2. 使用 `login` 应用
'ticket' => 'required|captcha:login',

❤️ Sponsor me

Sponsor me

如果你喜欢我的项目并想支持它,点击这里 ❤️

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

overtrue/laravel-qcloud-captcha 适用场景与选型建议

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

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

围绕 overtrue/laravel-qcloud-captcha 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-08