UNPKG

http-captcha

Version:

验证码小物件

28 lines (27 loc) 1.04 kB
/** * 随机生成验证码 * @returns Object */ function create(){ let str = '0123456789abcdeJKNBVfghiFYTUGIHKkdsfFHGHKJas' let one = Math.floor( Math.random() * (str.length-1-0+1)+0 ) let two = Math.floor( Math.random() * (str.length-1-0+1)+0 ) let three = Math.floor( Math.random() * (str.length-1-0+1)+0 ) let four = Math.floor( Math.random() * (str.length-1-0+1)+0 ) let text = '' + str[one] + str[two] + str[three] + str[four] return { text, data: `<svg xmlns="http://www.w3.org/2000/svg" version="1.1">             <defs>                 <filter id="f1" x="0" y="0">                 <feGaussianBlur in="SourceGraphic" stdDeviation="15" />                 </filter>             </defs>             <rect width="100" height="50" stroke="green" stroke-width="3"  fill="yellow" filter="url(#f1)" />             <text x="40" y="35" fill="blue">${text}</text>         </svg>` } } module.exports = { create, }