更新于 07-17 23:56

This commit is contained in:
root
2021-07-17 23:56:28 -04:00
parent ef6654ebd1
commit d95dd733c0
2 changed files with 347 additions and 707 deletions

View File

@ -4,7 +4,8 @@ const stream = require('stream');
const zlib = require('zlib');
const vm = require('vm');
const PNG = require('png-js');
const UA = require('./USER_AGENTS.js').USER_AGENT;
let UA = require('./USER_AGENTS.js').USER_AGENT;
const validatorCount = process.env.JDJR_validator_Count ? process.env.JDJR_validator_Count : 100
Math.avg = function average() {
@ -209,11 +210,12 @@ class JDJRValidator {
this.data = {};
this.x = 0;
this.t = Date.now();
this.count = 0;
}
async run(scene = 'cww') {
async run(scene = 'cww', eid='') {
const tryRecognize = async () => {
const x = await this.recognize(scene);
const x = await this.recognize(scene, eid);
if (x > 0) {
return x;
@ -229,6 +231,7 @@ class JDJRValidator {
// console.log(pos[pos.length-1][2] -Date.now());
// await sleep(4500);
await sleep(pos[pos.length - 1][2] - Date.now());
this.count++;
const result = await JDJRValidator.jsonp('/slide/s.html', {d, ...this.data}, scene);
if (result.message === 'success') {
@ -236,26 +239,32 @@ class JDJRValidator {
console.log('JDJR验证用时: %fs', (Date.now() - this.t) / 1000);
return result;
} else {
console.count("验证失败");
// console.count(JSON.stringify(result));
await sleep(300);
return await this.run(scene);
console.log(`验证失败: ${this.count}/${validatorCount}`);
// console.log(JSON.stringify(result));
if(this.count >= validatorCount){
console.log("JDJR验证次数已达上限退出验证");
return result;
}else{
await sleep(300);
return await this.run(scene, eid);
}
}
}
async recognize(scene) {
const data = await JDJRValidator.jsonp('/slide/g.html', {e: ''}, scene);
async recognize(scene, eid) {
const data = await JDJRValidator.jsonp('/slide/g.html', {e: eid}, scene);
const {bg, patch, y} = data;
// const uri = 'data:image/png;base64,';
// const re = new PuzzleRecognizer(uri+bg, uri+patch, y);
const re = new PuzzleRecognizer(bg, patch, y);
// console.log(JSON.stringify(re))
const puzzleX = await re.run();
if (puzzleX > 0) {
this.data = {
c: data.challenge,
w: re.w,
e: '',
e: eid,
s: '',
o: '',
};
@ -278,6 +287,7 @@ class JDJRValidator {
}
console.log('验证成功: %f\%', (count / n) * 100);
console.clear()
console.timeEnd('PuzzleRecognizer');
}
@ -290,11 +300,11 @@ class JDJRValidator {
const headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip,deflate,br',
'Accept-Language': 'zh-CN,en-US',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
'Host': SERVER,
'Host': "iv.jd.com",
'Proxy-Connection': 'keep-alive',
'Referer': 'https://h5.m.jd.com/babelDiy/Zeus/2wuqXrZrhygTQzYA7VufBEpj4amH/index.html',
'Referer': 'https://h5.m.jd.com/',
'User-Agent': UA,
};
@ -386,7 +396,7 @@ function getCoordinate(c) {
return b.join("")
}
const HZ = 60;
const HZ = 20;
class MousePosFaker {
constructor(puzzleX) {
@ -491,7 +501,8 @@ class MousePosFaker {
}
}
function injectToRequest(fn,scene = 'cww') {
function injectToRequest(fn,scene = 'cww', ua = '') {
if(ua) UA = ua
return (opts, cb) => {
fn(opts, async (err, resp, data) => {
if (err) {
@ -500,7 +511,14 @@ function injectToRequest(fn,scene = 'cww') {
}
if (data.search('验证') > -1) {
console.log('JDJR验证中......');
const res = await new JDJRValidator().run(scene);
let arr = opts.url.split("&")
let eid = ''
for(let i of arr){
if(i.indexOf("eid=")>-1){
eid = i.split("=") && i.split("=")[1] || ''
}
}
const res = await new JDJRValidator().run(scene, eid);
opts.url += `&validate=${res.validate}`;
fn(opts, cb);

1004
jd_test.js

File diff suppressed because one or more lines are too long