async captcha() { const key = this.query('key'); const rule = { key: { type: 'string', min: 36, max: 36 }, }; try { this.ctx.validate(rule, { key }); } catch (err) { this.error(400, '请求参数不合法'); return; } const captcha = svgCaptcha.create({ size: 4, // 字符数量 noise: 4, // 干扰线数量 color: true, // 彩色显示 ignoreChars: '0o1i', // 忽略的字符 background: '#f8f8f9', // 背景色 }); await this.app.cache.set(key, captcha.text.toLowerCase()); this.ctx.set('Content-Type', 'image/svg+xml'); this.ctx.body = captcha.data; }
const captchaCache = await this.app.cache.get(key); console.log(captchaCache, captcha); if (!captchaCache || captchaCache !== captcha.toLowerCase()) {