vkey-captcha
Version:
验证码
35 lines (32 loc) • 1.21 kB
JavaScript
/**
* 随机生成svg验证码
* @returns object
*/
function create(){
// 随机生成验证码(四位)
let str = '0123456789zxcvbnmasdfghjklqwertyuiopZAQWSXCDERFVBGTYHNUJMIKMLOP'
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>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<!-- <ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" /> -->
<rect width="80" height="30" style="fill:url(#grad1);stroke-width:1;" />
<text x="20" y="20" fill="#FFF">MtUr</text>
</svg>`
}
}
// 导出
module.exports = {
create
}