1、安装引入验证码模块
npm install --save svg-captcha
2、生成随机数验证码
router.get('/code',async (ctx) => {
var captcha = svgCaptcha.create({ //这种生成的是随机数验证码
size:4, //验证码长度
fontSize:50, //字体大小
width:100,
height:40,
background:'#cc8801'
});
console.log(captcha.text);
ctx.response.type = 'image/svg+xml';
ctx.body = captcha.data;
});
3、生成加法验证码:
svgCaptcha.createMathExpr()