Commit ab6e1e62 by 马玮

Captcha image delete

parent 90933a4e
......@@ -23,8 +23,9 @@ sudo yum install redis
- [x] 功能:抓取三天内线索信息并输出
- [x] 功能:每次抓取增加随机间隔
- [x] 功能:捕获程序错误及异常
- [ ] 功能:线索入库
- [ ] 功能:线索入库前对数据进行基础校验,所有字段入库前检查去空格
- [x] 功能:线索入库
- [x] 功能:验证码解析完毕删除
- [ ] 功能:线索入库前对数据进行基础校验,所有字段入库前检查去空格(50%)
- [ ] 功能:Cluster分布式进程调度
- [ ] 功能:增加日志系统
- [ ] 功能:增加随机userAgent
......
const fs = require('fs');
const config = require('config');
const ruokuai = require('./ruokuai');
const captcha = exports;
captcha.decode = function (captchaType, imageFile, callback) {
captcha.decode = async (captchaType, imageFile) => {
console.info('captchaType:', captchaType);
console.info('imageFile:', imageFile);
const typeids = config.get('CAPTCHA.RUOKUAI.TYPEIDS');
typeid = typeids[captchaType];
return new Promise(function (resolve, reject) {
ruokuai.decode(typeid, imageFile).then(function (captchaText) {
resolve(captchaText);
}).catch(function (error) {
reject(error);
});
});
const captchaText = ruokuai.decode(typeid, imageFile);
return captchaText;
}
captcha.decodeBase64 = async (captchaType, base64Text) => {
// const imageFile = 'captcha2.png';
const imageFile = 'tmp/' + (new Date) . getTime() + '.gif';
const writeStream = fs.createWriteStream(imageFile);
// data:image/png;base64, + base64Text
writeStream.write(base64Text, 'base64');
console.info('captchaType:', captchaType);
console.info('imageFile:', imageFile);
if (fs.existsSync(imageFile) && fs.statSync(imageFile).isFile()) {
const typeids = config.get('CAPTCHA.RUOKUAI.TYPEIDS');
typeid = typeids[captchaType];
const captchaText = ruokuai.decode(typeid, imageFile);
// fs.unlinkSync(imageFile);
return captchaText;
} else {
throw new Error(`${imageFile} is not a file`);
}
}
......@@ -9,7 +9,7 @@ const errors = require('../errors');
const ruokuai = exports;
ruokuai.decode = async function (typeid, imageFile) {
ruokuai.decode = async (typeid, imageFile) => {
const ruokuaiInfo = config.get('CAPTCHA.RUOKUAI');
const formData = new FormData();
......
......@@ -125,26 +125,18 @@ class AutoHome {
});
// 验证码存储到磁盘
const imageFile =
const base64Text =
await
horseman
.screenshot('m1.png')
.crop('#imgValidCodeDealer', 'captcha1.png')
.cropBase64('#imgValidCodeDealer', 'PNG')
.then((base64Text) => {
// const imageFile = 'tmp/' + (new Date) . getTime() + '.gif';
const imageFile = 'captcha2.png';
const writeStream = fs.createWriteStream(imageFile);
// data:image/png;base64, + base64Text
writeStream.write(base64Text, 'base64');
return imageFile;
});
.cropBase64('#imgValidCodeDealer', 'PNG');
// 验证码解码
let captchaText;
try {
const captchaType = config.get(this.params.webname)['CAPTCHA_TYPE'];
captchaText = await captcha.decode(captchaType, imageFile);
captchaText = await captcha.decodeBase64(captchaType, base64Text);
console.info('captchaText:', captchaText);
} catch (e) {
console.log(e.toString());
......
......@@ -98,6 +98,7 @@ class EasyPass {
console.log(e.message);
}
loginSuccess = 0;
if (loginSuccess) {
console.log('尝试登录成功');
return;
......@@ -122,26 +123,18 @@ class EasyPass {
console.log('打开了登录页');
// 验证码存储到磁盘
const imageFile =
const base64Text =
await
horseman
.crop('#imgVerificationCode', 'captcha1.png')
.cropBase64('#imgVerificationCode', 'PNG')
.then((base64Text) => {
// const imageFile = 'tmp/' + (new Date) . getTime() + '.gif';
const imageFile = 'captcha2.png';
const writeStream = fs.createWriteStream(imageFile);
// data:image/png;base64, + base64Text
writeStream.write(base64Text, 'base64');
return imageFile;
});
.cropBase64('#imgVerificationCode', 'PNG');
console.log('验证码准备完毕');
// 验证码解码
let captchaText;
try {
const captchaType = config.get(this.params.webname)['CAPTCHA_TYPE'];
captchaText = await captcha.decode(captchaType, imageFile);
captchaText = await captcha.decodeBase64(captchaType, base64Text);
console.info('captchaText:', captchaText);
} catch (e) {
console.log(e.toString());
......
......@@ -8,6 +8,10 @@ const moment = require('moment');
const day = moment().subtract(3, 'days').format('YYYY.MM.DD');
const axios = require('axios');
console.log(fs.existsSync('/tmp/a') && fs.statSync('/tmp/a').isFile());
return;
// console.log(moment().subtract(30, 'days').format('YYYY.MM.DD'));
// return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment