click-captcha-server
服务端(Nodejs)的文字点选行为验证码生成/验证器(仅可验证点选坐标是否正确),可自定义背景,字体,文字集等。
无前端sdk支持(demo有前端的代码示例)
源码:/rojer95/click-captcha-server 求Star~
预览 / Preview
安装 / Install
$ yarn add click-captcha-server
快速开始 / Quickstart
import ClickCaptcha from "click-captcha-server";const clickCaptcha = new ClickCaptcha();// 生成验证码图片与答案区域const {img, front, answer, count } = await clickCaptcha.generate();// 验证点选位置const input = ctx.body; // input 来自用户点选的坐标集合const pass = clickCaptcha.check(input, answer);console.log(pass ? '验证成功': '验证失败');
参数 / Options
关于ClickCaptcha
的参数说明如下:
// 需要在全局初始化保持单例const clickCaptcha = new ClickCaptcha({bg: (width, height)=> 'http://xxx.xxx.xx/bg.png', // 返回一个背景图片的 url 【可选】character: ['你','我','他','等'], // 显示的字符集合,是一个字符数组预设 【可选】width: 300, // 宽 【可选】height: 200, // 高 【可选】fontMinSize: 26, // 字体大小-最小值 【可选】fontMaxSize: 34, // 字体大小-最大值 【可选】count: 3, // 正确答案数量 【可选】confuseCount: 2, // 迷惑项数量 【可选】});// 导入字体(路径),一样在全局执行一次即可。会扫描路径下的所有ttf格式的字体,且以字体文件名作为font family导入到node-canvasclickCaptcha.registerFontByPath(path.join(__dirname, "./fonts"));
案例 / Example
git clone /rojer95/click-captcha-server.gitcd click-captcha-server# 安装依赖yarn install# 构建yarn build# 运行exampleyarn example# 打开 http://localhost:3000/ 体验
node-canvas 依赖说明 / About Canvas Dependence
By default, binaries for macOS, Linux and Windows will be downloaded. If you want to build from source, usenpm install --build-from-source
and see theCompilingsection below.
The minimum version of Node.js required is6.0.0.
Compiling
If you don’t have a supported OS or processor architecture, or you use--build-from-source
, the module will be compiled on your system. This requires several dependencies, including Cairo and Pango.
For detailed installation information, see the wiki. One-line installation instructions for common OSes are below. Note that libgif/giflib, librsvg and libjpeg are optional and only required if you need GIF, SVG and JPEG support, respectively. Cairo v1.10.0 or later is required.
Mac OS X v10.11+:If you have recently updated to Mac OS X v10.11+ and are experiencing trouble when compiling, run the following command:xcode-select --install
. Read more about the problem on Stack Overflow.
If you have xcode 10.0 or higher installed, in order to build from source you need NPM 6.4.1 or higher.
LICENSE
MIT