https://github.com/produck/svg-captcha
npm install --save svg-captcha
验证码细节
用redis存验证码值
前台点击二维码,要刷新;刷新页面验证码也要刷新
https://www.codeleading.com/article/29115579333/
https://www.1024sou.com/article/440263.html
https://www.jianshu.com/p/0865b692cc71
https://blog.csdn.net/xuelang532777032/article/details/118677831
Controller
/app/controller/captcha.js
'use strict';const svgCaptcha = require('svg-captcha');const {Controller} = require('egg');class CaptchaController extends Controller {async index() {const captcha = svgCaptcha.create({size: 4,fontSize: 50,ignoreChars: 'Ooli',width: 100,height: 40,noise: 3,color: true,background: '#cc9966',});this.ctx.session.captcha = captcha.text;this.ctx.response.type = 'image/svg+xml';this.ctx.body = captcha.data;}}module.exports = CaptchaController;
router.js 新增路由
浏览器运行http://127.0.0.1:7001/captcha 就可以看到对应的图形验证码
router.get('/captcha', controller.captcha.index);
