captcha.js 820 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. const svgCaptcha = require('svg-captcha');
  4. /**
  5. * 验证码
  6. */
  7. class CaptchaService extends Service {
  8. /**
  9. * [get 获取验证码]
  10. * @author szjcomo
  11. * @createTime 2020-09-07
  12. * @param {Object} options [description]
  13. * @return {[type]} [description]
  14. */
  15. get(options = {}) {
  16. let defaults = {fontSize:50,color:false,noise:2,width:100,height:25};
  17. const captcha = svgCaptcha.createMathExpr(Object.assign(defaults,options));
  18. return captcha;
  19. }
  20. /**
  21. * [validate 验证验证码]
  22. * @author szjcomo
  23. * @createTime 2020-09-07
  24. * @param {[type]} text [description]
  25. * @return {[type]} [description]
  26. */
  27. validate(text,session_text) {
  28. return text == session_text;
  29. }
  30. }
  31. module.exports = CaptchaService;