1 Star 1 Fork 0

fish / drag-captcha

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Drag-Captcha

拖拽图形验证,简单易用, 只需要绑定按钮即可使用。 english
composer require rlofls/drag-captcha

show 示例

功能介绍

自定义背景

先设置 Resources::$customBg 数组值,一定要是 png 图片, 存放的是图片路径。 eg:

//设置自定义背景
Resources::$customBg = [
  __DIR__ . '/customBg/1.png',
  __DIR__ . '/customBg/2.png',
  __DIR__ . '/customBg/3.png',
  //...
];

添加干扰混淆

能够使目标不那么明显,会随机对目标进行扩展/剪切,在调用 generate() 方法时候, 传入true 值即可。 eg: $drag->generate(true);

  • expand:

    expand

  • cut

    expand

运行示例

  1. 切换到此目录下
  2. composer install
  3. php -S 127.0.0.1:8087
  4. 浏览器访问 http://127.0.0.1:8087

实践

参考 index.php index.html
复制 dragCaptcha.css dragCaptcha.js 到自己项目应用
参考 html

<body>
    
    <button id="show">show</button>
</body>
<script type="module">
    import {DragCaptcha} from "./dragCaptcha.js";
    //设置要绑定的按钮
    let btn = document.getElementById("show")

    //1.设置 请求数据api 地址, 默认: /dragData
    //DragCaptcha.prototype.apiDataUrl = '/dragData'
    //2.设置 请求验证api 地址, 默认: /dragVerify
    //DragCaptcha.prototype.apiVerifyUrl = '/dragVerify'

    //3.设置语言 默认 zh:中文, en:英文
    //DragCaptcha.prototype.lang = 'en'

    //4.设置debug  默认 true 会打印日志
    //DragCaptcha.prototype.debug = false

    //5.设置验证成功 callback
    DragCaptcha.prototype.cbSuccess = function(drag) {
        console.log("验证通过 cid:", drag.cid)
        //处理自己业务逻辑 提交表单 ...

        //如果业务逻辑失败。需要重新添加点击事件, 因为在验证成功时候会取消点击事件
        //console.log("业务逻辑失败,重新绑定点击事件")
        //drag.addClickEventListener()
    }
    //6. 设置验证失败 callback
    DragCaptcha.prototype.cbFail = function(drag) {
        console.log("验证失败")
    }
    let drag = new DragCaptcha(btn);

</script>

api

  • Rlofls\DragCaptcha\Drag

    • generate 生成渲染数据 dst, data
    • verify 验证匹配结果
  • 服务器api 要求, Content-Type: application/json

    • /dragData---[GET]---获取验证码数据
      响应数据格式:
      {
        "status": "success" // error 表示失败
        "data": {
          //一次验证 事务id 用户自己生成
          "cid": "drag-captcha63c0c18566074"
          //以下数据由 Rlofls\DragCaptcha\Drag::generate 生成
          "bgBase64": "data:image/png;base64,iV..."
          "bgH": 160
          "bgW": 250
          "maskBase64": "data:image/png;base64,..."
          "maskLeft": 114
          "maskPath": "M 15.27429..."
          "maskTop": 0
          "maskViewBox": 15.875
          "maskWH": 57
        }
      
      }
    • /dragVerify---[POST]---进行验证码验证
      请求参数
      {
        "cid": "drag-captcha63c0c1881db17"
        "mask": {
          "left": 149, 
          "top": 76
        }
      }
      响应数据格式:
      {"status": "error"}

todo

  • 欢迎提交 issuse
MIT License Copyright (c) 2022 RLOFLS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

拖拽验证码、简单引用,只需绑定按钮即可 展开 收起
PHP 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/mayuntym/drag-captcha.git
git@gitee.com:mayuntym/drag-captcha.git
mayuntym
drag-captcha
drag-captcha
main

搜索帮助