验证码使用(egg)

版权声明:本文为博主原创文章,未经博主允许不得转载,转载请注明地址。 https://blog.csdn.net/qq_33589252/article/details/83114112
import { Service } from 'webrail';
import {captcha} from '@webrail/captcha';

let text:string;
export class CaptchaService extends Service {
	public async create(){
		let createSvg=new captcha().getCaptcha({
			ignoreChars:'o0ilI1',
			noise:2,
			width:100,
			height:30,
			fontSize:37
    });
    text=createSvg.text.toUpperCase();
    console.log('3',createSvg.text.toUpperCase());
    console.log(text);
    return createSvg.data;
  }
  public async validate(captchaText:string){
    console.log('1',text);
    console.log('2',captchaText);
    if(captchaText===text){
      return true;
    }else{
      return false;
    }
  }

}

export default CaptchaService;

猜你喜欢

转载自blog.csdn.net/qq_33589252/article/details/83114112