12345678910111213141516171819202122232425262728293031323334 |
- 'use strict';
- const Service = require('egg').Service;
- const svgCaptcha = require('svg-captcha');
- /**
- * 验证码
- */
- class CaptchaService extends Service {
- /**
- * [get 获取验证码]
- * @author szjcomo
- * @createTime 2020-09-07
- * @param {Object} options [description]
- * @return {[type]} [description]
- */
- get(options = {}) {
- let defaults = {fontSize:50,color:false,noise:2,width:100,height:25};
- const captcha = svgCaptcha.createMathExpr(Object.assign(defaults,options));
- return captcha;
- }
- /**
- * [validate 验证验证码]
- * @author szjcomo
- * @createTime 2020-09-07
- * @param {[type]} text [description]
- * @return {[type]} [description]
- */
- validate(text,session_text) {
- return text == session_text;
- }
- }
- module.exports = CaptchaService;
|