能不能有个轻便易用的图形验证码包啊
能不能有个轻便易用的图形验证码包啊, ccap那个好难安装成功,对node版本也有限制,有什么别的好用的吗
14 回复
页面
img#vcimg.pull-right(src='/picvc?width=100&height=26', alt='#{lang.change}', title='#{lang.change}')
JS
$('#vcimg').click(function () {
$("#vcimg").attr('src', '/picvc?width=100&height=30&time= ' +(new Date()).getTime());
});
Route
get('/picvc', userController.getPicVC);
controller
exports.getPicVC = function (req, res) {
var width = !isNaN(parseInt(req.query.width)) ? parseInt(req.query.width) : 100;
var height = !isNaN(parseInt(req.query.height)) ? parseInt(req.query.height) : 30;
var code = parseInt(Math.random() * 9000 + 1000);
req.session.picVCode = code;
var p = new captchapng(width, height, code);
p.color(180, 180, 180, 100); // First color: background (red, green, blue, alpha)
p.color(parseInt(Math.random() * 255), parseInt(Math.random() * 255), parseInt(Math.random() * 255), 255);
var img = p.getBase64();
var imgbase64 = new Buffer(img, 'base64');
res.writeHead(200, {
'Content-Type': 'image/png'
});
res.end(imgbase64);
};
大致这样,你可以参考一下 @wang-weifeng