First commit

This commit is contained in:
Faker
2022-02-24 11:12:22 +08:00
parent 624e00a8cf
commit 5cadab9349
255 changed files with 98778 additions and 0 deletions

BIN
utils/.DS_Store vendored Normal file

Binary file not shown.

381
utils/JDJRValidator.js Normal file
View File

@@ -0,0 +1,381 @@
const http = require('http');
const stream = require('stream');
const zlib = require('zlib');
const vm = require('vm');
const { createCanvas, Image } = require('canvas');
Math.avg = function average() {
var sum= 0;
var len = this.length;
for (var i = 0; i < len; i++) {
sum += this[i];
}
return sum / len;
};
function sleep(timeout) {
return new Promise((resolve) => setTimeout(resolve, timeout));
}
const canvas = createCanvas();
const PUZZLE_GAP = 8;
const PUZZLE_PAD = 10;
class PuzzleRecognizer {
constructor(bg, patch, y) {
const imgBg = new Image();
const imgPatch = new Image();
imgBg.src = bg;
imgPatch.src = patch;
this.bg = imgBg;
this.patch = imgPatch;
this.y = y;
this.w = imgBg.naturalWidth;
this.h = imgBg.naturalHeight;
this.ctx = canvas.getContext('2d');
}
run() {
const { ctx, w, h } = this;
canvas.width = w;
canvas.height= h;
ctx.clearRect(0, 0, w, h);
ctx.drawImage(this.bg, 0, 0, w, h);
return this.recognize();
}
recognize() {
const { ctx, w: width } = this;
const { naturalHeight, naturalWidth } = this.patch;
const posY = this.y + PUZZLE_PAD + ((naturalHeight - PUZZLE_PAD) / 2) - (PUZZLE_GAP / 2);
const cData = ctx.getImageData(0, posY, width, PUZZLE_GAP).data;
const lumas = [];
for (let x = 0; x < width; x++) {
var sum = 0;
for (let y = 0; y < PUZZLE_GAP; y++) {
var idx = x * 4 + y * (width * 4);
var r = cData[idx];
var g = cData[idx + 1];
var b = cData[idx + 2];
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
sum += luma;
}
lumas.push(sum / PUZZLE_GAP);
}
const n = 2; // minium macroscopic image width (px)
const margin = naturalWidth - PUZZLE_PAD;
const diff = 20; // macroscopic brightness difference
const radius = PUZZLE_PAD;
for (let i = 0, len = lumas.length - 2*4; i < len; i++) {
const left = (lumas[i] + lumas[i+1]) / n;
const right = (lumas[i+2] + lumas[i+3]) / n;
const mi = margin + i;
const mLeft = (lumas[mi] + lumas[mi+1]) / n;
const mRigth = (lumas[mi+2] + lumas[mi+3]) / n;
if (left - right > diff && mLeft - mRigth < -diff) {
const pieces = lumas.slice(i+2,margin+i+2);
const median = pieces.sort((x1,x2)=>x1-x2)[20];
const avg = Math.avg(pieces);
if (median > left || median > mRigth) return;
if (avg > 100) return;
return i+n-radius;
}
}
return -1;
}
}
const DATA = {
"appId": "17839d5db83",
"scene": "cww",
"product": "embed",
"lang": "zh_CN",
};
const SERVER = 'iv.jd.com';
class JDJRValidator {
constructor() {
this.data = {};
this.x = 0;
this.t = Date.now();
this.c = {};
}
async run() {
const tryRecognize = async () => {
const x = await this.recognize();
if (x > 0) {
return x;
}
// retry
return await tryRecognize();
};
const puzzleX = await tryRecognize();
const pos = new MousePosFaker(puzzleX).run();
const d = getCoordinate(pos);
await sleep(pos[pos.length-1][2] - Date.now());
const result = await JDJRValidator.jsonp('/slide/s.html', { d, ...this.data });
if (result.message === 'success') {
this.c = result;
console.log(result);
} else {
console.count(JSON.stringify(result));
await sleep(300);
await this.run();
}
}
async recognize() {
const data = await JDJRValidator.jsonp('/slide/g.html', { e: '' });
const { bg, patch, y } = data;
const uri = 'data:image/png;base64,';
const re = new PuzzleRecognizer(uri+bg, uri+patch, y);
const puzzleX = re.run();
if (puzzleX > 0) {
this.data = {
c: data.challenge,
w: re.w,
e: '',
s: '',
o: '',
};
this.x = puzzleX;
}
return puzzleX;
}
async report(n) {
console.time('PuzzleRecognizer');
let count = 0;
for (let i = 0; i < n; i++) {
const x = await this.recognize();
if (x > 0) count ++;
if (i % 50 === 0) {
console.log('%f\%', (i/n)*100);
}
}
console.log('successful: %f\%', (count/n)*100);
console.timeEnd('PuzzleRecognizer');
}
static jsonp(api, data = {}) {
return new Promise((resolve, reject) => {
const fnId = `jsonp_${String(Math.random()).replace('.', '')}`;
const extraData = { callback: fnId };
const query = new URLSearchParams({ ...DATA, ...extraData, ...data }).toString();
const url = `http://${SERVER}${api}?${query}`;
const headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip,deflate,br',
'Accept-Language': 'zh-CN,en-US',
'Connection': 'keep-alive',
'Host': SERVER,
'Proxy-Connection': 'keep-alive',
'Referer': 'https://h5.m.jd.com/babelDiy/Zeus/2wuqXrZrhygTQzYA7VufBEpj4amH/index.html',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
};
const req = http.get(url, { headers }, (response) => {
let res = response;
if (res.headers['content-encoding'] === 'gzip') {
const unzipStream = new stream.PassThrough();
stream.pipeline(
response,
zlib.createGunzip(),
unzipStream,
reject,
);
res = unzipStream;
}
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => rawData += chunk);
res.on('end', () => {
try {
const ctx = {
[fnId]: (data) => ctx.data = data,
data: {},
};
vm.createContext(ctx);
vm.runInContext(rawData, ctx);
res.resume();
resolve(ctx.data);
} catch (e) {
reject(e);
}
});
});
req.on('error', reject);
req.end();
});
}
}
function getCoordinate(c) {
function string10to64(d) {
var c = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~".split("")
, b = c.length
, e = +d
, a = [];
do {
mod = e % b;
e = (e - mod) / b;
a.unshift(c[mod])
} while (e);
return a.join("")
}
function prefixInteger (a, b) {
return (Array(b).join(0) + a).slice(-b)
}
function pretreatment(d, c, b) {
var e = string10to64(Math.abs(d));
var a = "";
if (!b) {
a += (d > 0 ? "1" : "0")
}
a += prefixInteger(e, c);
return a
}
var b = new Array();
for (var e = 0; e < c.length; e++) {
if (e == 0) {
b.push(pretreatment(c[e][0] < 262143 ? c[e][0] : 262143, 3, true));
b.push(pretreatment(c[e][1] < 16777215 ? c[e][1] : 16777215, 4, true));
b.push(pretreatment(c[e][2] < 4398046511103 ? c[e][2] : 4398046511103, 7, true))
} else {
var a = c[e][0] - c[e - 1][0];
var f = c[e][1] - c[e - 1][1];
var d = c[e][2] - c[e - 1][2];
b.push(pretreatment(a < 4095 ? a : 4095, 2, false));
b.push(pretreatment(f < 4095 ? f : 4095, 2, false));
b.push(pretreatment(d < 16777215 ? d : 16777215, 4, true))
}
}
return b.join("")
}
const HZ = 60;
class MousePosFaker {
constructor(puzzleX) {
this.x = parseInt(Math.random()*20+20, 10);
this.y = parseInt(Math.random()*80+80, 10);
this.t = Date.now();
this.pos = [[this.x, this.y, this.t]];
this.minDuration = parseInt(1000 / HZ, 10);
// this.puzzleX = puzzleX;
this.puzzleX = puzzleX + parseInt(Math.random()*2-1, 10);
this.STEP = parseInt(Math.random()*6+5, 10);
this.DURATION = parseInt(Math.random()*7+14, 10)*100;
// [9,1600] [10,1400]
this.STEP = 9;
// this.DURATION = 2000;
//console.log(this.STEP, this.DURATION);
}
run() {
const perX = this.puzzleX / this.STEP;
const perDuration = this.DURATION / this.STEP;
const firstPos = [this.x-parseInt(Math.random()*6, 10), this.y+parseInt(Math.random()*11, 10), this.t];
this.pos.unshift(firstPos);
this.stepPos(perX, perDuration);
this.fixPos();
const reactTime = parseInt(60+Math.random()*100, 10);
const lastIdx = this.pos.length - 1;
const lastPos = [this.pos[lastIdx][0], this.pos[lastIdx][1], this.pos[lastIdx][2]+reactTime];
this.pos.push(lastPos);
return this.pos;
}
stepPos(x, duration) {
let n = 0;
const sqrt2 = Math.sqrt(2);
for (let i = 1; i <= this.STEP; i++) {
n += 1/i;
}
for (let i = 0; i < this.STEP; i++) {
x = this.puzzleX / (n*(i+1));
const currX = parseInt((Math.random()*30-15)+x, 10);
const currY = parseInt(Math.random()*7-3, 10);
const currDuration = parseInt((Math.random()*0.4+0.8)*duration, 10);
this.moveToAndCollect({
x: currX,
y: currY,
duration: currDuration,
});
}
}
fixPos() {
const actualX = this.pos[this.pos.length - 1][0] - this.pos[1][0];
const deviation = this.puzzleX - actualX;
if (Math.abs(deviation) > 4) {
this.moveToAndCollect({
x: deviation,
y: parseInt(Math.random()*8-3, 10),
duration: 250,
});
}
}
moveToAndCollect({ x, y, duration }) {
let movedX = 0;
let movedY = 0;
let movedT = 0;
const times = duration / this.minDuration;
let perX = x / times;
let perY = y / times;
let padDuration = 0;
if (Math.abs(perX) < 1) {
padDuration = duration / Math.abs(x) - this.minDuration;
perX = 1;
perY = y / Math.abs(x);
}
while (Math.abs(movedX) < Math.abs(x)) {
const rDuration = parseInt(padDuration + Math.random()*16-4, 10);
movedX += perX + Math.random()*2-1;
movedY += perY;
movedT += this.minDuration + rDuration;
const currX = parseInt(this.x + movedX, 10);
const currY = parseInt(this.y + movedY, 10);
const currT = this.t + movedT;
this.pos.push([currX, currY, currT]);
}
this.x += x;
this.y += y;
this.t += Math.max(duration, movedT);
}
}
async function getResult(){
let aaa = new JDJRValidator();
await aaa.run();
return `&validate=${aaa.c['validate']}`;
}
PuzzleRecognizer.getResult = getResult;
module.exports = PuzzleRecognizer;
// new JDJRValidator().report(1000);
//console.log(getCoordinate(new MousePosFaker(100).run())+'1111');

553
utils/JDJRValidator_Pure.js Normal file
View File

@@ -0,0 +1,553 @@
/*
由于 canvas 依赖系统底层需要编译且预编译包在 github releases 上,改用另一个纯 js 解码图片。若想继续使用 canvas 可调用 runWithCanvas 。
添加 injectToRequest 用以快速修复需验证的请求。eg: $.get=injectToRequest($.get.bind($))
*/
const https = require('https');
const http = require('http');
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;
Math.avg = function average() {
var sum = 0;
var len = this.length;
for (var i = 0; i < len; i++) {
sum += this[i];
}
return sum / len;
};
function sleep(timeout) {
return new Promise((resolve) => setTimeout(resolve, timeout));
}
class PNGDecoder extends PNG {
constructor(args) {
super(args);
this.pixels = [];
}
decodeToPixels() {
return new Promise((resolve) => {
try {
this.decode((pixels) => {
this.pixels = pixels;
resolve();
});
} catch (e) {
console.info(e)
}
});
}
getImageData(x, y, w, h) {
const {pixels} = this;
const len = w * h * 4;
const startIndex = x * 4 + y * (w * 4);
return {data: pixels.slice(startIndex, startIndex + len)};
}
}
const PUZZLE_GAP = 8;
const PUZZLE_PAD = 10;
class PuzzleRecognizer {
constructor(bg, patch, y) {
// console.log(bg);
const imgBg = new PNGDecoder(Buffer.from(bg, 'base64'));
const imgPatch = new PNGDecoder(Buffer.from(patch, 'base64'));
// console.log(imgBg);
this.bg = imgBg;
this.patch = imgPatch;
this.rawBg = bg;
this.rawPatch = patch;
this.y = y;
this.w = imgBg.width;
this.h = imgBg.height;
}
async run() {
try {
await this.bg.decodeToPixels();
await this.patch.decodeToPixels();
return this.recognize();
} catch (e) {
console.info(e)
}
}
recognize() {
const {ctx, w: width, bg} = this;
const {width: patchWidth, height: patchHeight} = this.patch;
const posY = this.y + PUZZLE_PAD + ((patchHeight - PUZZLE_PAD) / 2) - (PUZZLE_GAP / 2);
// const cData = ctx.getImageData(0, a.y + 10 + 20 - 4, 360, 8).data;
const cData = bg.getImageData(0, posY, width, PUZZLE_GAP).data;
const lumas = [];
for (let x = 0; x < width; x++) {
var sum = 0;
// y xais
for (let y = 0; y < PUZZLE_GAP; y++) {
var idx = x * 4 + y * (width * 4);
var r = cData[idx];
var g = cData[idx + 1];
var b = cData[idx + 2];
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
sum += luma;
}
lumas.push(sum / PUZZLE_GAP);
}
const n = 2; // minium macroscopic image width (px)
const margin = patchWidth - PUZZLE_PAD;
const diff = 20; // macroscopic brightness difference
const radius = PUZZLE_PAD;
for (let i = 0, len = lumas.length - 2 * 4; i < len; i++) {
const left = (lumas[i] + lumas[i + 1]) / n;
const right = (lumas[i + 2] + lumas[i + 3]) / n;
const mi = margin + i;
const mLeft = (lumas[mi] + lumas[mi + 1]) / n;
const mRigth = (lumas[mi + 2] + lumas[mi + 3]) / n;
if (left - right > diff && mLeft - mRigth < -diff) {
const pieces = lumas.slice(i + 2, margin + i + 2);
const median = pieces.sort((x1, x2) => x1 - x2)[20];
const avg = Math.avg(pieces);
// noise reducation
if (median > left || median > mRigth) return;
if (avg > 100) return;
// console.table({left,right,mLeft,mRigth,median});
// ctx.fillRect(i+n-radius, 0, 1, 360);
// console.log(i+n-radius);
return i + n - radius;
}
}
// not found
return -1;
}
runWithCanvas() {
const {createCanvas, Image} = require('canvas');
const canvas = createCanvas();
const ctx = canvas.getContext('2d');
const imgBg = new Image();
const imgPatch = new Image();
const prefix = 'data:image/png;base64,';
imgBg.src = prefix + this.rawBg;
imgPatch.src = prefix + this.rawPatch;
const {naturalWidth: w, naturalHeight: h} = imgBg;
canvas.width = w;
canvas.height = h;
ctx.clearRect(0, 0, w, h);
ctx.drawImage(imgBg, 0, 0, w, h);
const width = w;
const {naturalWidth, naturalHeight} = imgPatch;
const posY = this.y + PUZZLE_PAD + ((naturalHeight - PUZZLE_PAD) / 2) - (PUZZLE_GAP / 2);
// const cData = ctx.getImageData(0, a.y + 10 + 20 - 4, 360, 8).data;
const cData = ctx.getImageData(0, posY, width, PUZZLE_GAP).data;
const lumas = [];
for (let x = 0; x < width; x++) {
var sum = 0;
// y xais
for (let y = 0; y < PUZZLE_GAP; y++) {
var idx = x * 4 + y * (width * 4);
var r = cData[idx];
var g = cData[idx + 1];
var b = cData[idx + 2];
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
sum += luma;
}
lumas.push(sum / PUZZLE_GAP);
}
const n = 2; // minium macroscopic image width (px)
const margin = naturalWidth - PUZZLE_PAD;
const diff = 20; // macroscopic brightness difference
const radius = PUZZLE_PAD;
for (let i = 0, len = lumas.length - 2 * 4; i < len; i++) {
const left = (lumas[i] + lumas[i + 1]) / n;
const right = (lumas[i + 2] + lumas[i + 3]) / n;
const mi = margin + i;
const mLeft = (lumas[mi] + lumas[mi + 1]) / n;
const mRigth = (lumas[mi + 2] + lumas[mi + 3]) / n;
if (left - right > diff && mLeft - mRigth < -diff) {
const pieces = lumas.slice(i + 2, margin + i + 2);
const median = pieces.sort((x1, x2) => x1 - x2)[20];
const avg = Math.avg(pieces);
// noise reducation
if (median > left || median > mRigth) return;
if (avg > 100) return;
// console.table({left,right,mLeft,mRigth,median});
// ctx.fillRect(i+n-radius, 0, 1, 360);
// console.log(i+n-radius);
return i + n - radius;
}
}
// not found
return -1;
}
}
const DATA = {
"appId": "17839d5db83",
"product": "embed",
"lang": "zh_CN",
};
const SERVER = '61.49.99.122';
class JDJRValidator {
constructor() {
this.data = {};
this.x = 0;
this.t = Date.now();
}
async run(scene) {
try {
const tryRecognize = async () => {
const x = await this.recognize(scene);
if (x > 0) {
return x;
}
// retry
return await tryRecognize();
};
const puzzleX = await tryRecognize();
// console.log(puzzleX);
const pos = new MousePosFaker(puzzleX).run();
const d = getCoordinate(pos);
// console.log(pos[pos.length-1][2] -Date.now());
// await sleep(4500);
await sleep(pos[pos.length - 1][2] - Date.now());
const result = await JDJRValidator.jsonp('/slide/s.html', {d, ...this.data}, scene);
if (result.message === 'success') {
// console.log(result);
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);
}
} catch (e) {
console.info(e)
}
}
async recognize(scene) {
try {
const data = await JDJRValidator.jsonp('/slide/g.html', {e: ''}, 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);
const puzzleX = await re.run();
if (puzzleX > 0) {
this.data = {
c: data.challenge,
w: re.w,
e: '',
s: '',
o: '',
};
this.x = puzzleX;
}
return puzzleX;
} catch (e) {
console.info(e)
}
}
async report(n) {
console.time('PuzzleRecognizer');
let count = 0;
for (let i = 0; i < n; i++) {
const x = await this.recognize();
if (x > 0) count++;
if (i % 50 === 0) {
// console.log('%f\%', (i / n) * 100);
}
}
console.log('验证成功: %f\%', (count / n) * 100);
console.timeEnd('PuzzleRecognizer');
}
static jsonp(api, data = {}, scene) {
return new Promise((resolve, reject) => {
const fnId = `jsonp_${String(Math.random()).replace('.', '')}`;
const extraData = {callback: fnId};
const query = new URLSearchParams({...DATA, ...{"scene": scene}, ...extraData, ...data}).toString();
const url = `http://${SERVER}${api}?${query}`;
const headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip,deflate,br',
'Accept-Language': 'zh-CN,en-US',
'Connection': 'keep-alive',
'Host': SERVER,
'Proxy-Connection': 'keep-alive',
'Referer': 'https://h5.m.jd.com/babelDiy/Zeus/2wuqXrZrhygTQzYA7VufBEpj4amH/index.html',
'User-Agent': UA,
};
const req = http.get(url, {headers}, (response) => {
let res = response;
if (res.headers['content-encoding'] === 'gzip') {
const unzipStream = new stream.PassThrough();
stream.pipeline(
response,
zlib.createGunzip(),
unzipStream,
reject,
);
res = unzipStream;
}
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => rawData += chunk);
res.on('end', () => {
try {
const ctx = {
[fnId]: (data) => ctx.data = data,
data: {},
};
vm.createContext(ctx);
vm.runInContext(rawData, ctx);
// console.log(ctx.data);
res.resume();
resolve(ctx.data);
} catch (e) {
reject(e);
}
});
});
req.on('error', reject);
req.end();
});
}
}
function getCoordinate(c) {
function string10to64(d) {
var c = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~".split("")
, b = c.length
, e = +d
, a = [];
do {
mod = e % b;
e = (e - mod) / b;
a.unshift(c[mod])
} while (e);
return a.join("")
}
function prefixInteger(a, b) {
return (Array(b).join(0) + a).slice(-b)
}
function pretreatment(d, c, b) {
var e = string10to64(Math.abs(d));
var a = "";
if (!b) {
a += (d > 0 ? "1" : "0")
}
a += prefixInteger(e, c);
return a
}
var b = new Array();
for (var e = 0; e < c.length; e++) {
if (e == 0) {
b.push(pretreatment(c[e][0] < 262143 ? c[e][0] : 262143, 3, true));
b.push(pretreatment(c[e][1] < 16777215 ? c[e][1] : 16777215, 4, true));
b.push(pretreatment(c[e][2] < 4398046511103 ? c[e][2] : 4398046511103, 7, true))
} else {
var a = c[e][0] - c[e - 1][0];
var f = c[e][1] - c[e - 1][1];
var d = c[e][2] - c[e - 1][2];
b.push(pretreatment(a < 4095 ? a : 4095, 2, false));
b.push(pretreatment(f < 4095 ? f : 4095, 2, false));
b.push(pretreatment(d < 16777215 ? d : 16777215, 4, true))
}
}
return b.join("")
}
const HZ = 5;
class MousePosFaker {
constructor(puzzleX) {
this.x = parseInt(Math.random() * 20 + 20, 10);
this.y = parseInt(Math.random() * 80 + 80, 10);
this.t = Date.now();
this.pos = [[this.x, this.y, this.t]];
this.minDuration = parseInt(1000 / HZ, 10);
// this.puzzleX = puzzleX;
this.puzzleX = puzzleX + parseInt(Math.random() * 2 - 1, 10);
this.STEP = parseInt(Math.random() * 6 + 5, 10);
this.DURATION = parseInt(Math.random() * 7 + 14, 10) * 100;
// [9,1600] [10,1400]
this.STEP = 9;
// this.DURATION = 2000;
// console.log(this.STEP, this.DURATION);
}
run() {
const perX = this.puzzleX / this.STEP;
const perDuration = this.DURATION / this.STEP;
const firstPos = [this.x - parseInt(Math.random() * 6, 10), this.y + parseInt(Math.random() * 11, 10), this.t];
this.pos.unshift(firstPos);
this.stepPos(perX, perDuration);
this.fixPos();
const reactTime = parseInt(60 + Math.random() * 100, 10);
const lastIdx = this.pos.length - 1;
const lastPos = [this.pos[lastIdx][0], this.pos[lastIdx][1], this.pos[lastIdx][2] + reactTime];
this.pos.push(lastPos);
return this.pos;
}
stepPos(x, duration) {
let n = 0;
const sqrt2 = Math.sqrt(2);
for (let i = 1; i <= this.STEP; i++) {
n += 1 / i;
}
for (let i = 0; i < this.STEP; i++) {
x = this.puzzleX / (n * (i + 1));
const currX = parseInt((Math.random() * 30 - 15) + x, 10);
const currY = parseInt(Math.random() * 7 - 3, 10);
const currDuration = parseInt((Math.random() * 0.4 + 0.8) * duration, 10);
this.moveToAndCollect({
x: currX,
y: currY,
duration: currDuration,
});
}
}
fixPos() {
const actualX = this.pos[this.pos.length - 1][0] - this.pos[1][0];
const deviation = this.puzzleX - actualX;
if (Math.abs(deviation) > 4) {
this.moveToAndCollect({
x: deviation,
y: parseInt(Math.random() * 8 - 3, 10),
duration: 250,
});
}
}
moveToAndCollect({x, y, duration}) {
let movedX = 0;
let movedY = 0;
let movedT = 0;
const times = duration / this.minDuration;
let perX = x / times;
let perY = y / times;
let padDuration = 0;
if (Math.abs(perX) < 1) {
padDuration = duration / Math.abs(x) - this.minDuration;
perX = 1;
perY = y / Math.abs(x);
}
while (Math.abs(movedX) < Math.abs(x)) {
const rDuration = parseInt(padDuration + Math.random() * 16 - 4, 10);
movedX += perX + Math.random() * 2 - 1;
movedY += perY;
movedT += this.minDuration + rDuration;
const currX = parseInt(this.x + movedX, 10);
const currY = parseInt(this.y + movedY, 10);
const currT = this.t + movedT;
this.pos.push([currX, currY, currT]);
}
this.x += x;
this.y += y;
this.t += Math.max(duration, movedT);
}
}
// new JDJRValidator().run();
// new JDJRValidator().report(1000);
// console.log(getCoordinate(new MousePosFaker(100).run()));
function injectToRequest2(fn, scene = 'cww') {
return (opts, cb) => {
fn(opts, async (err, resp, data) => {
try {
if (err) {
console.error('验证请求失败.');
return;
}
if (data.search('验证') > -1) {
console.log('JDJR验证中......');
const res = await new JDJRValidator().run(scene);
if (res) {
opts.url += `&validate=${res.validate}`;
}
fn(opts, cb);
} else {
cb(err, resp, data);
}
} catch (e) {
console.info(e)
}
});
};
}
async function injectToRequest(scene = 'cww') {
console.log('JDJR验证中......');
const res = await new JDJRValidator().run(scene);
return `&validate=${res.validate}`
}
module.exports = {
sleep,
injectToRequest,
injectToRequest2
}

2080
utils/JDSignValidator.js Normal file

File diff suppressed because it is too large Load Diff

1950
utils/JD_DailyBonus.js Normal file

File diff suppressed because it is too large Load Diff

139
utils/MoveMentFaker.js Normal file
View File

@@ -0,0 +1,139 @@
const https = require('https');
const fs = require('fs/promises');
const { R_OK } = require('fs').constants;
const vm = require('vm');
const UA = require('../USER_AGENTS.js').USER_AGENT;
const URL = 'https://wbbny.m.jd.com/babelDiy/Zeus/2rtpffK8wqNyPBH6wyUDuBKoAbCt/index.html';
// const REG_MODULE = /(\d+)\:function\(.*(?=smashUtils\.get_risk_result)/gm;
const SYNTAX_MODULE = '!function(n){var r={};function o(e){if(r[e])';
const REG_SCRIPT = /<script type="text\/javascript" src="([^><]+\/(app\.\w+\.js))\">/gm;
const REG_ENTRY = /(__webpack_require__\(__webpack_require__\.s=)(\d+)(?=\)})/;
const needModuleId = 356
const DATA = {appid:'50085',sceneid:'OY217hPageh5'};
let smashUtils;
class MoveMentFaker {
constructor(cookie) {
// this.secretp = secretp;
this.cookie = cookie;
}
async run() {
if (!smashUtils) {
await this.init();
}
var t = Math.floor(1e7 + 9e7 * Math.random()).toString();
var e = smashUtils.get_risk_result({
id: t,
data: {
random: t
}
}).log;
var o = JSON.stringify({
extraData: {
log: e || -1,
// log: encodeURIComponent(e),
sceneid: DATA.sceneid,
},
// secretp: this.secretp,
random: t
})
// console.log(o);
return o;
}
async init() {
try {
// console.time('MoveMentFaker');
process.chdir(__dirname);
const html = await MoveMentFaker.httpGet(URL);
const script = REG_SCRIPT.exec(html);
if (script) {
const [, scriptUrl, filename] = script;
const jsContent = await this.getJSContent(filename, scriptUrl);
const fnMock = new Function;
const ctx = {
window: { addEventListener: fnMock },
document: {
addEventListener: fnMock,
removeEventListener: fnMock,
cookie: this.cookie
},
navigator: { userAgent: UA }
};
vm.createContext(ctx);
vm.runInContext(jsContent, ctx);
smashUtils = ctx.window.smashUtils;
smashUtils.init(DATA);
// console.log(ctx);
}
// console.log(html);
// console.log(script[1],script[2]);
// console.timeEnd('MoveMentFaker');
} catch (e) {
console.log(e)
}
}
async getJSContent(cacheKey, url) {
try {
await fs.access(cacheKey, R_OK);
const rawFile = await fs.readFile(cacheKey, { encoding: 'utf8' });
return rawFile;
} catch (e) {
let jsContent = await MoveMentFaker.httpGet(url);
const moduleIndex = jsContent.indexOf(SYNTAX_MODULE, 1);
const findEntry = REG_ENTRY.test(jsContent);
if (!(moduleIndex && findEntry)) {
throw new Error('Module not found.');
}
// const needModuleId = jsContent.substring(moduleIndex-20, moduleIndex).match(/(\d+):function/)[1]
jsContent = jsContent.replace(REG_ENTRY, `$1${needModuleId}`);
fs.writeFile(cacheKey, jsContent);
return jsContent;
REG_ENTRY.lastIndex = 0;
const entry = REG_ENTRY.exec(jsContent);
console.log(moduleIndex, needModuleId);
console.log(entry[1], entry[2]);
}
}
static httpGet(url) {
return new Promise((resolve, reject) => {
const protocol = url.indexOf('http') !== 0 ? 'https:' : '';
const req = https.get(protocol + url, (res) => {
res.setEncoding('utf-8');
let rawData = '';
res.on('error', reject);
res.on('data', chunk => rawData += chunk);
res.on('end', () => resolve(rawData));
});
req.on('error', reject);
req.end();
});
}
}
async function getBody($) {
const zf = new MoveMentFaker($.cookie);
// const zf = new MoveMentFaker($.secretp, $.cookie);
const ss = await zf.run();
return ss;
}
MoveMentFaker.getBody = getBody;
module.exports = MoveMentFaker;

51
utils/USER_AGENTS.js Normal file
View File

@@ -0,0 +1,51 @@
const USER_AGENTS = [
"jdapp;android;10.1.0;10;network/wifi;Mozilla/5.0 (Linux; Android 10; ONEPLUS A5010 Build/QKQ1.191014.012; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36",
"jdapp;iPhone;10.1.0;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;android;10.1.0;9;network/4g;Mozilla/5.0 (Linux; Android 9; Mi Note 3 Build/PKQ1.181007.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36",
"jdapp;android;10.1.0;10;network/wifi;Mozilla/5.0 (Linux; Android 10; GM1910 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36",
"jdapp;android;10.1.0;9;network/wifi;Mozilla/5.0 (Linux; Android 9; 16T Build/PKQ1.190616.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36",
"jdapp;iPhone;10.1.0;13.6;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;13.6;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;13.5;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;13.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;13.7;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;13.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;13.4;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;android;10.1.0;9;network/wifi;Mozilla/5.0 (Linux; Android 9; MI 6 Build/PKQ1.190118.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36",
"jdapp;android;10.1.0;11;network/wifi;Mozilla/5.0 (Linux; Android 11; Redmi K30 5G Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045511 Mobile Safari/537.36",
"jdapp;iPhone;10.1.0;11.4;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79",
"jdapp;android;10.1.0;10;;network/wifi;Mozilla/5.0 (Linux; Android 10; M2006J10C Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36",
"jdapp;android;10.1.0;10;network/wifi;Mozilla/5.0 (Linux; Android 10; M2006J10C Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36",
"jdapp;android;10.1.0;10;network/wifi;Mozilla/5.0 (Linux; Android 10; ONEPLUS A6000 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045224 Mobile Safari/537.36",
"jdapp;android;10.1.0;9;network/wifi;Mozilla/5.0 (Linux; Android 9; MHA-AL00 Build/HUAWEIMHA-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36",
"jdapp;android;10.1.0;8.1.0;network/wifi;Mozilla/5.0 (Linux; Android 8.1.0; 16 X Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36",
"jdapp;android;10.1.0;8.0.0;network/wifi;Mozilla/5.0 (Linux; Android 8.0.0; HTC U-3w Build/OPR6.170623.013; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36",
"jdapp;iPhone;10.1.0;14.0.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;android;10.1.0;10;network/wifi;Mozilla/5.0 (Linux; Android 10; LYA-AL00 Build/HUAWEILYA-AL00L; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36",
"jdapp;iPhone;10.1.0;14.2;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;14.2;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;android;10.1.0;8.1.0;network/wifi;Mozilla/5.0 (Linux; Android 8.1.0; MI 8 Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36",
"jdapp;android;10.1.0;10;network/wifi;Mozilla/5.0 (Linux; Android 10; Redmi K20 Pro Premium Edition Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045227 Mobile Safari/537.36",
"jdapp;iPhone;10.1.0;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;iPhone;10.1.0;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
"jdapp;android;10.1.0;11;network/wifi;Mozilla/5.0 (Linux; Android 11; Redmi K20 Pro Premium Edition Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045513 Mobile Safari/537.36",
"jdapp;android;10.1.0;10;network/wifi;Mozilla/5.0 (Linux; Android 10; MI 8 Build/QKQ1.190828.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045227 Mobile Safari/537.36",
"jdapp;iPhone;10.1.0;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1",
]
/**
* 生成随机数字
* @param {number} min 最小值(包含)
* @param {number} max 最大值(不包含)
*/
function randomNumber(min = 0, max = 100) {
return Math.min(Math.floor(min + Math.random() * (max - min)), max);
}
const USER_AGENT = USER_AGENTS[randomNumber(0, USER_AGENTS.length)];
module.exports = {
USER_AGENT
}

903
utils/ZooFaker_Necklace.js Normal file
View File

@@ -0,0 +1,903 @@
function safeAdd(x, y) {
var lsw = (x & 0xffff) + (y & 0xffff)
var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
return (msw << 16) | (lsw & 0xffff)
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function bitRotateLeft(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt))
}
function md5(string, key, raw) {
if (!key) {
if (!raw) {
return hexMD5(string)
}
return rawMD5(string)
}
if (!raw) {
return hexHMACMD5(key, string)
}
return rawHMACMD5(key, string)
}
/*
* Convert a raw string to a hex string
*/
function rstr2hex(input) {
var hexTab = '0123456789abcdef'
var output = ''
var x
var i
for (i = 0; i < input.length; i += 1) {
x = input.charCodeAt(i)
output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f)
}
return output
}
/*
* Encode a string as utf-8
*/
function str2rstrUTF8(input) {
return unescape(encodeURIComponent(input))
}
/*
* Calculate the MD5 of a raw string
*/
function rstrMD5(s) {
return binl2rstr(binlMD5(rstr2binl(s), s.length * 8))
}
function hexMD5(s) {
return rstr2hex(rawMD5(s))
}
function rawMD5(s) {
return rstrMD5(str2rstrUTF8(s))
}
/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5cmn(q, a, b, x, s, t) {
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b)
}
function md5ff(a, b, c, d, x, s, t) {
return md5cmn((b & c) | (~b & d), a, b, x, s, t)
}
function md5gg(a, b, c, d, x, s, t) {
return md5cmn((b & d) | (c & ~d), a, b, x, s, t)
}
function md5hh(a, b, c, d, x, s, t) {
return md5cmn(b ^ c ^ d, a, b, x, s, t)
}
function md5ii(a, b, c, d, x, s, t) {
return md5cmn(c ^ (b | ~d), a, b, x, s, t)
}
/*
* Calculate the MD5 of an array of little-endian words, and a bit length.
*/
function binlMD5(x, len) {
/* append padding */
x[len >> 5] |= 0x80 << (len % 32)
x[((len + 64) >>> 9 << 4) + 14] = len
var i
var olda
var oldb
var oldc
var oldd
var a = 1732584193
var b = -271733879
var c = -1732584194
var d = 271733878
for (i = 0; i < x.length; i += 16) {
olda = a
oldb = b
oldc = c
oldd = d
a = md5ff(a, b, c, d, x[i], 7, -680876936)
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586)
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819)
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330)
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897)
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426)
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341)
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983)
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416)
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417)
c = md5ff(c, d, a, b, x[i + 10], 17, -42063)
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162)
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682)
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101)
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290)
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329)
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510)
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632)
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713)
b = md5gg(b, c, d, a, x[i], 20, -373897302)
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691)
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083)
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335)
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848)
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438)
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690)
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961)
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501)
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467)
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784)
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473)
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734)
a = md5hh(a, b, c, d, x[i + 5], 4, -378558)
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463)
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562)
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556)
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060)
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353)
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632)
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640)
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174)
d = md5hh(d, a, b, c, x[i], 11, -358537222)
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979)
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189)
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487)
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835)
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520)
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651)
a = md5ii(a, b, c, d, x[i], 6, -198630844)
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415)
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905)
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055)
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571)
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606)
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523)
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799)
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359)
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744)
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380)
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649)
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070)
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379)
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259)
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551)
a = safeAdd(a, olda)
b = safeAdd(b, oldb)
c = safeAdd(c, oldc)
d = safeAdd(d, oldd)
}
return [a, b, c, d]
}
/*
* Convert an array of little-endian words to a string
*/
function binl2rstr(input) {
var i
var output = ''
var length32 = input.length * 32
for (i = 0; i < length32; i += 8) {
output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff)
}
return output
}
/*
* Convert a raw string to an array of little-endian words
* Characters >255 have their high-byte silently ignored.
*/
function rstr2binl(input) {
var i
var output = []
output[(input.length >> 2) - 1] = undefined
for (i = 0; i < output.length; i += 1) {
output[i] = 0
}
var length8 = input.length * 8
for (i = 0; i < length8; i += 8) {
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32)
}
return output
}
function encrypt_3(e) {
return function (e) {
if (Array.isArray(e)) return encrypt_3_3(e)
}(e) || function (e) {
if ("undefined" != typeof Symbol && Symbol.iterator in Object(e)) return Array.from(e)
}(e) || function (e, t) {
if (e) {
if ("string" == typeof e) return encrypt_3_3(e, t);
var n = Object.prototype.toString.call(e).slice(8, -1);
return "Object" === n && e.constructor && (n = e.constructor.name), "Map" === n || "Set" === n ? Array.from(e) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? encrypt_3_3(e, t) : void 0
}
}(e) || function () {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
}()
}
function encrypt_3_3(e, t) {
(null == t || t > e.length) && (t = e.length);
for (var n = 0, r = new Array(t); n < t; n++) r[n] = e[n];
return r
}
function rotateRight(n, x) {
return ((x >>> n) | (x << (32 - n)));
}
function choice(x, y, z) {
return ((x & y) ^ (~x & z));
}
function majority(x, y, z) {
return ((x & y) ^ (x & z) ^ (y & z));
}
function sha256_Sigma0(x) {
return (rotateRight(2, x) ^ rotateRight(13, x) ^ rotateRight(22, x));
}
function sha256_Sigma1(x) {
return (rotateRight(6, x) ^ rotateRight(11, x) ^ rotateRight(25, x));
}
function sha256_sigma0(x) {
return (rotateRight(7, x) ^ rotateRight(18, x) ^ (x >>> 3));
}
function sha256_sigma1(x) {
return (rotateRight(17, x) ^ rotateRight(19, x) ^ (x >>> 10));
}
function sha256_expand(W, j) {
return (W[j & 0x0f] += sha256_sigma1(W[(j + 14) & 0x0f]) + W[(j + 9) & 0x0f] +
sha256_sigma0(W[(j + 1) & 0x0f]));
}
/* Hash constant words K: */
var K256 = new Array(
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
);
/* global arrays */
var ihash, count, buffer;
var sha256_hex_digits = "0123456789abcdef";
/* Add 32-bit integers with 16-bit operations (bug in some JS-interpreters:
overflow) */
function safe_add(x, y) {
var lsw = (x & 0xffff) + (y & 0xffff);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xffff);
}
/* Initialise the SHA256 computation */
function sha256_init() {
ihash = new Array(8);
count = new Array(2);
buffer = new Array(64);
count[0] = count[1] = 0;
ihash[0] = 0x6a09e667;
ihash[1] = 0xbb67ae85;
ihash[2] = 0x3c6ef372;
ihash[3] = 0xa54ff53a;
ihash[4] = 0x510e527f;
ihash[5] = 0x9b05688c;
ihash[6] = 0x1f83d9ab;
ihash[7] = 0x5be0cd19;
}
/* Transform a 512-bit message block */
function sha256_transform() {
var a, b, c, d, e, f, g, h, T1, T2;
var W = new Array(16);
/* Initialize registers with the previous intermediate value */
a = ihash[0];
b = ihash[1];
c = ihash[2];
d = ihash[3];
e = ihash[4];
f = ihash[5];
g = ihash[6];
h = ihash[7];
/* make 32-bit words */
for (var i = 0; i < 16; i++)
W[i] = ((buffer[(i << 2) + 3]) | (buffer[(i << 2) + 2] << 8) | (buffer[(i << 2) + 1] <<
16) | (buffer[i << 2] << 24));
for (var j = 0; j < 64; j++) {
T1 = h + sha256_Sigma1(e) + choice(e, f, g) + K256[j];
if (j < 16) T1 += W[j];
else T1 += sha256_expand(W, j);
T2 = sha256_Sigma0(a) + majority(a, b, c);
h = g;
g = f;
f = e;
e = safe_add(d, T1);
d = c;
c = b;
b = a;
a = safe_add(T1, T2);
}
/* Compute the current intermediate hash value */
ihash[0] += a;
ihash[1] += b;
ihash[2] += c;
ihash[3] += d;
ihash[4] += e;
ihash[5] += f;
ihash[6] += g;
ihash[7] += h;
}
/* Read the next chunk of data and update the SHA256 computation */
function sha256_update(data, inputLen) {
var i, index, curpos = 0;
/* Compute number of bytes mod 64 */
index = ((count[0] >> 3) & 0x3f);
var remainder = (inputLen & 0x3f);
/* Update number of bits */
if ((count[0] += (inputLen << 3)) < (inputLen << 3)) count[1]++;
count[1] += (inputLen >> 29);
/* Transform as many times as possible */
for (i = 0; i + 63 < inputLen; i += 64) {
for (var j = index; j < 64; j++)
buffer[j] = data.charCodeAt(curpos++);
sha256_transform();
index = 0;
}
/* Buffer remaining input */
for (var j = 0; j < remainder; j++)
buffer[j] = data.charCodeAt(curpos++);
}
/* Finish the computation by operations such as padding */
function sha256_final() {
var index = ((count[0] >> 3) & 0x3f);
buffer[index++] = 0x80;
if (index <= 56) {
for (var i = index; i < 56; i++)
buffer[i] = 0;
} else {
for (var i = index; i < 64; i++)
buffer[i] = 0;
sha256_transform();
for (var i = 0; i < 56; i++)
buffer[i] = 0;
}
buffer[56] = (count[1] >>> 24) & 0xff;
buffer[57] = (count[1] >>> 16) & 0xff;
buffer[58] = (count[1] >>> 8) & 0xff;
buffer[59] = count[1] & 0xff;
buffer[60] = (count[0] >>> 24) & 0xff;
buffer[61] = (count[0] >>> 16) & 0xff;
buffer[62] = (count[0] >>> 8) & 0xff;
buffer[63] = count[0] & 0xff;
sha256_transform();
}
/* Split the internal hash values into an array of bytes */
function sha256_encode_bytes() {
var j = 0;
var output = new Array(32);
for (var i = 0; i < 8; i++) {
output[j++] = ((ihash[i] >>> 24) & 0xff);
output[j++] = ((ihash[i] >>> 16) & 0xff);
output[j++] = ((ihash[i] >>> 8) & 0xff);
output[j++] = (ihash[i] & 0xff);
}
return output;
}
/* Get the internal hash as a hex string */
function sha256_encode_hex() {
var output = new String();
for (var i = 0; i < 8; i++) {
for (var j = 28; j >= 0; j -= 4)
output += sha256_hex_digits.charAt((ihash[i] >>> j) & 0x0f);
}
return output;
}
let utils = {
getDefaultVal: function (e) {
try {
return {
undefined: "u",
false: "f",
true: "t"
} [e] || e
} catch (t) {
return e
}
},
requestUrl: {
gettoken: "".concat("https://", "bh.m.jd.com/gettoken"),
bypass: "".concat("https://blackhole", ".m.jd.com/bypass")
},
getTouchSession: function () {
var e = (new Date).getTime(),
t = this.getRandomInt(1e3, 9999);
return String(e) + String(t)
},
sha256: function (data) {
sha256_init();
sha256_update(data, data.length);
sha256_final();
return sha256_encode_hex().toUpperCase();
},
atobPolyfill: function (e) {
return function (e) {
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
if (e = String(e).replace(/[\t\n\f\r ]+/g, ""), !/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(e)) throw new TypeError("解密错误");
e += "==".slice(2 - (3 & e.length));
for (var n, r, i, o = "", a = 0; a < e.length;) n = t.indexOf(e.charAt(a++)) << 18 | t.indexOf(e.charAt(a++)) << 12 | (r = t.indexOf(e.charAt(a++))) << 6 | (i = t.indexOf(e.charAt(a++))), o += 64 === r ? String.fromCharCode(n >> 16 & 255) : 64 === i ? String.fromCharCode(n >> 16 & 255, n >> 8 & 255) : String.fromCharCode(n >> 16 & 255, n >> 8 & 255, 255 & n);
return o
}(e)
},
btoaPolyfill: function (e) {
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
return function (e) {
for (var n, r, i, o, a = "", s = 0, u = (e = String(e)).length % 3; s < e.length;) {
if ((r = e.charCodeAt(s++)) > 255 || (i = e.charCodeAt(s++)) > 255 || (o = e.charCodeAt(s++)) > 255) throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");
a += t.charAt((n = r << 16 | i << 8 | o) >> 18 & 63) + t.charAt(n >> 12 & 63) + t.charAt(n >> 6 & 63) + t.charAt(63 & n)
}
return u ? a.slice(0, u - 3) + "===".substring(u) : a
}(unescape(encodeURIComponent(e)))
},
xorEncrypt: function (e, t) {
for (var n = t.length, r = "", i = 0; i < e.length; i++) r += String.fromCharCode(e[i].charCodeAt() ^ t[i % n].charCodeAt());
return r
},
encrypt1: function (e, t) {
for (var n = e.length, r = t.toString(), i = [], o = "", a = 0, s = 0; s < r.length; s++) a >= n && (a %= n), o = (r.charCodeAt(s) ^ e.charCodeAt(a)) % 10, i.push(o), a += 1;
return i.join().replace(/,/g, "")
},
len_Fun: function (e, t) {
return "".concat(e.substring(t, e.length)) + "".concat(e.substring(0, t))
},
encrypt2: function (e, t) {
var n = t.toString(),
r = t.toString().length,
i = parseInt((r + e.length) / 3),
o = "",
a = "";
return r > e.length ? (o = this.len_Fun(n, i), a = this.encrypt1(e, o)) : (o = this.len_Fun(e, i), a = this.encrypt1(n, o)), a
},
addZeroFront: function (e) {
return e && e.length >= 5 ? e : ("00000" + String(e)).substr(-5)
},
addZeroBack: function (e) {
return e && e.length >= 5 ? e : (String(e) + "00000").substr(0, 5)
},
encrypt3: function (e, t) {
var n = this.addZeroBack(t).toString().substring(0, 5),
r = this.addZeroFront(e).substring(e.length - 5),
i = n.length,
o = encrypt_3(Array(i).keys()),
a = [];
return o.forEach(function (e) {
a.push(Math.abs(n.charCodeAt(e) - r.charCodeAt(e)))
}), a.join().replace(/,/g, "")
},
getCurrentDate: function () {
return new Date
},
getCurrentTime: function () {
return this.getCurrentDate().getTime()
},
getRandomInt: function () {
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0,
t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 9;
return e = Math.ceil(e), t = Math.floor(t), Math.floor(Math.random() * (t - e + 1)) + e
},
getRandomWord: function (e) {
for (var t = "", n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r = 0; r < e; r++) {
var i = Math.round(Math.random() * (n.length - 1));
t += n.substring(i, i + 1)
}
return t
},
getNumberInString: function (e) {
return Number(e.replace(/[^0-9]/gi, ""))
},
getSpecialPosition: function (e) {
for (var t = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1], n = ((e = String(e)).length, t ? 1 : 0), r = "", i = 0; i < e.length; i++) i % 2 === n && (r += e[i]);
return r
},
getLastAscii: function (e) {
var t = e.charCodeAt(0).toString();
return t[t.length - 1]
},
toAscii: function (e) {
var t = "";
for (var n in e) {
var r = e[n],
i = /[a-zA-Z]/.test(r);
e.hasOwnProperty(n) && (t += i ? this.getLastAscii(r) : r)
}
return t
},
add0: function (e, t) {
return (Array(t).join("0") + e).slice(-t)
},
minusByByte: function (e, t) {
var n = e.length,
r = t.length,
i = Math.max(n, r),
o = this.toAscii(e),
a = this.toAscii(t),
s = "",
u = 0;
for (n !== r && (o = this.add0(o, i), a = this.add0(a, i)); u < i;) s += Math.abs(o[u] - a[u]), u++;
return s
},
Crc32: function (str) {
var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
crc = 0 ^ (-1);
var n = 0; //a number between 0 and 255
var x = 0; //an hex number
for (var i = 0, iTop = str.length; i < iTop; i++) {
n = (crc ^ str.charCodeAt(i)) & 0xFF;
x = "0x" + table.substr(n * 9, 8);
crc = (crc >>> 8) ^ x;
}
return (crc ^ (-1)) >>> 0;
},
getCrcCode: function (e) {
var t = "0000000",
n = "";
try {
n = this.Crc32(e).toString(36), t = this.addZeroToSeven(n)
} catch (e) {}
return t
},
addZeroToSeven: function (e) {
return e && e.length >= 7 ? e : ("0000000" + String(e)).substr(-7)
},
getInRange: function (e, t, n) {
var r = [];
return e.map(function (e, i) {
e >= t && e <= n && r.push(e)
}), r
},
RecursiveSorting: function () {
var e = this,
t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
n = {},
r = t;
if ("[object Object]" == Object.prototype.toString.call(r)) {
var i = Object.keys(r).sort(function (e, t) {
return e < t ? -1 : e > t ? 1 : 0
});
i.forEach(function (t) {
var i = r[t];
if ("[object Object]" === Object.prototype.toString.call(i)) {
var o = e.RecursiveSorting(i);
n[t] = o
} else if ("[object Array]" === Object.prototype.toString.call(i)) {
for (var a = [], s = 0; s < i.length; s++) {
var u = i[s];
if ("[object Object]" === Object.prototype.toString.call(u)) {
var c = e.RecursiveSorting(u);
a[s] = c
} else a[s] = u
}
n[t] = a
} else n[t] = i
})
} else n = t;
return n
},
objToString2: function () {
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
t = "";
return Object.keys(e).forEach(function (n) {
var r = e[n];
null != r && (t += r instanceof Object || r instanceof Array ? "".concat("" === t ? "" : "&").concat(n, "=").concat(JSON.stringify(r)) : "".concat("" === t ? "" : "&").concat(n, "=").concat(r))
}), t
},
getKey: function (e, t, n) {
let r = this;
return {
1: function () {
var e = r.getNumberInString(t),
i = r.getSpecialPosition(n);
return Math.abs(e - i)
},
2: function () {
var e = r.getSpecialPosition(t, !1),
i = r.getSpecialPosition(n);
return r.minusByByte(e, i)
},
3: function () {
var e = t.slice(0, 5),
i = String(n).slice(-5);
return r.minusByByte(e, i)
},
4: function () {
return r.encrypt1(t, n)
},
5: function () {
return r.encrypt2(t, n)
},
6: function () {
return r.encrypt3(t, n)
}
} [e]()
},
decipherJoyToken: function (e, t) {
let m = this;
var n = {
jjt: "a",
expire: m.getCurrentTime(),
outtime: 3,
time_correction: !1
};
var r = "",
i = e.indexOf(t) + t.length,
o = e.length;
if ((r = (r = e.slice(i, o).split(".")).map(function (e) {
return m.atobPolyfill(e)
}))[1] && r[0] && r[2]) {
var a = r[0].slice(2, 7),
s = r[0].slice(7, 9),
u = m.xorEncrypt(r[1] || "", a).split("~");
n.outtime = u[3] - 0, n.encrypt_id = u[2], n.jjt = "t";
var c = u[0] - 0 || 0;
c && "number" == typeof c && (n.time_correction = !0, n.expire = c);
var l = c - m.getCurrentTime() || 0;
return n.q = l, n.cf_v = s, n
}
return n
},
sha1: function (s) {
var data = new Uint8Array(this.encodeUTF8(s))
var i, j, t;
var l = ((data.length + 8) >>> 6 << 4) + 16,
s = new Uint8Array(l << 2);
s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer);
for (t = new DataView(s.buffer), i = 0; i < l; i++) s[i] = t.getUint32(i << 2);
s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8);
s[l - 1] = data.length << 3;
var w = [],
f = [
function () {
return m[1] & m[2] | ~m[1] & m[3];
},
function () {
return m[1] ^ m[2] ^ m[3];
},
function () {
return m[1] & m[2] | m[1] & m[3] | m[2] & m[3];
},
function () {
return m[1] ^ m[2] ^ m[3];
}
],
rol = function (n, c) {
return n << c | n >>> (32 - c);
},
k = [1518500249, 1859775393, -1894007588, -899497514],
m = [1732584193, -271733879, null, null, -1009589776];
m[2] = ~m[0], m[3] = ~m[1];
for (var i = 0; i < s.length; i += 16) {
var o = m.slice(0);
for (j = 0; j < 80; j++)
w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1),
t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0,
m[1] = rol(m[1], 30), m.pop(), m.unshift(t);
for (j = 0; j < 5; j++) m[j] = m[j] + o[j] | 0;
};
t = new DataView(new Uint32Array(m).buffer);
for (var i = 0; i < 5; i++) m[i] = t.getUint32(i << 2);
var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) {
return (e < 16 ? "0" : "") + e.toString(16);
}).join("");
return hex.toString().toUpperCase();
},
encodeUTF8: function (s) {
var i, r = [],
c, x;
for (i = 0; i < s.length; i++)
if ((c = s.charCodeAt(i)) < 0x80) r.push(c);
else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F));
else {
if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode
c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000,
r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F));
else r.push(0xE0 + (c >> 12 & 0xF));
r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
};
return r;
},
get_blog: function (pin) {
let encrypefun = {
"z": function (p1, p2) {
var str = "";
for (var vi = 0; vi < p1.length; vi++) {
str += (p1.charCodeAt(vi) ^ p2.charCodeAt(vi % p2.length)).toString("16");
}
return str;
},
"y": function (p1, p2) {
var str = "";
for (var vi = 0; vi < p1.length; vi++) {
str += (p1.charCodeAt(vi) & p2.charCodeAt(vi % p2.length)).toString("16");
}
return str;
},
"x": function (p1, p2) {
p1 = p1.substring(1) + p1.substring(0, 1);
p2 = p2.substring((p2.length - 1)) + p2.substring(0, (p2.length - 1));
var str = "";
for (var vi = 0; vi < p1.length; vi++) {
str += (p1.charCodeAt(vi) ^ p2.charCodeAt(vi % p2.length)).toString("16");
}
return str;
},
"jiami": function (po, p1) {
var str = "";
for (vi = 0; vi < po.length; vi++) {
str += String.fromCharCode(po.charCodeAt(vi) ^ p1.charCodeAt(vi % p1.length));
}
return new Buffer.from(str).toString('base64');
}
}
const ids = ["x", "y", "z"];
var encrypeid = ids[Math.floor(Math.random() * 1e8) % ids.length];
var timestamp = this.getCurrentTime();
var nonce_str = this.getRandomWord(10);
var isDefaultKey = "B";
// timestamp = 1627139784174;
refer = "com.miui.home";
encrypeid = "x";
//nonce_str = "jNN40H0elF";
var json = {
r: refer,
a: "",
c: "a",
v: "2.5.8",
t: timestamp.toString().substring(timestamp.toString().length - 4)
}
var token = md5(pin);
var key = encrypefun[encrypeid](timestamp.toString(), nonce_str);
//console.log(key);
var cipher = encrypefun["jiami"](JSON.stringify(json), key);
//sOf+"~1"+sa1+sb+"~"+sb1+"~~~"+str+"~"+sa+"~"+sa2;
//"1627139784174~1jNN40H0elF14e91ebb633928c23d5afbaa8f947952~x~~~B~TBJHGg0bVAlaF1oPTVwfXQtaVBdJFQcVChcaGxtURA0bVkQUF0cXXhUDG1AZXhUcF0wVAxVSBg4DREU=~0v3u0bq",
return `${timestamp}~1${nonce_str+token}~${encrypeid}~~~${isDefaultKey}~${cipher}~${this.getCrcCode(cipher)}`;
},
getBody: async function ($ = {}) {
var pin = decodeURIComponent($.cookie.match(/pt_pin=([^; ]+)(?=;?)/) && $.cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1])
var appid = "50082";
var TouchSession = this.getTouchSession();
let riskData;
switch ($.action) {
case 'startTask':
riskData = { taskId: $.id };
break;
case 'chargeScores':
riskData = { bubleId: $.id };
break;
case 'sign':
riskData = {};
break;
case 'exchangeGift':
riskData = { scoreNums: $.id, giftConfigId: $.giftConfigId || 198 };
break;
default:
break;
}
var random = Math.floor(1e+6 * Math.random()).toString().padEnd(6, '8');
var senddata = this.objToString2(this.RecursiveSorting({
pin,
random,
...riskData
}));
var time = this.getCurrentTime();
// time = 1626970587918;
var encrypt_id = this.decipherJoyToken(appid + $.joyToken, appid)["encrypt_id"].split(",");
var nonce_str = this.getRandomWord(10);
// nonce_str="iY8uFBbYX7";
var key = this.getKey(encrypt_id[2], nonce_str, time.toString());
var str1 = `${senddata}&token=${$.joyToken}&time=${time}&nonce_str=${nonce_str}&key=${key}&is_trust=1`;
//console.log(str1);
str1 = this.sha1(str1);
var outstr = [time, "1" + nonce_str + $.joyToken, encrypt_id[2] + "," + encrypt_id[3]];
outstr.push(str1);
outstr.push(this.getCrcCode(str1));
outstr.push("C");
var data = {
tm: [],
tnm: ["d5-15,C5,5JD,a,t","d7-15,C5,5LJ,a,t"],
grn: 1,
ss: TouchSession,
wed: 'ttttt',
wea: 'ffttttua',
pdn: [7, (Math.floor(Math.random() * 1e8) % 180) + 1, 6, 11, 1, 5],
jj: 1,
cs: hexMD5("Object.P.<computed>=&HTMLDocument.Ut.<computed>=https://storage.360buyimg.com/babel/00750963/1942873/production/dev/main.e5d1c436.js"),
np: 'iPhone',
t: time,
jk: $.uuid,
fpb: '',
nv: 'Apple Computer, Inc.',
nav: '167741',
scr: [736, 414],
ro: [
'iPhone10,2',
'iOS',
'14.4.2',
'10.0.8',
'167741',
$.uuid,
'a'
],
ioa: 'fffffftt',
aj: 'u',
ci: 'w3.1.0',
cf_v: '01',
bd: senddata,
mj: [1, 0, 0],
blog: 'a',
msg: ''
}
// console.log(data);
//console.log(JSON.stringify(data));
data = new Buffer.from(this.xorEncrypt(JSON.stringify(data), key)).toString('base64');
//console.log(data);
outstr.push(data);
outstr.push(this.getCrcCode(data));
//console.log(outstr.join("~"));
return {
extraData: {
log: outstr.join("~"),
sceneid: "DDhomePageh5"
},
...riskData,
random,
};
}
};
module.exports = {
utils
}

280
utils/common.js Normal file
View File

@@ -0,0 +1,280 @@
let request = require('request');
let CryptoJS = require('crypto-js');
let qs = require('querystring');
let urls = require('url');
let path = require('path');
let notify = require('./sendNotify');
let mainEval = require("./eval");
let assert = require('assert');
let jxAlgo = require("./jxAlgo");
let config = require("./config");
let user = {}
try {
user = require("./user")
} catch (e) {}
class env {
constructor(name) {
this.config = { ...process.env,
...config,
...user,
};
this.name = name;
this.message = [];
this.sharecode = [];
this.code = [];
this.timestamp = new Date().getTime();
this.time = this.start = parseInt(this.timestamp / 1000);
this.options = {
'headers': {}
};
console.log(`\n🔔${this.name}, 开始!\n`)
console.log(`=========== 脚本执行-北京时间(UTC+8)${new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000).toLocaleString()} ===========\n`)
}
done() {
let timestamp = new Date().getTime();
let work = ((timestamp - this.timestamp) / 1000).toFixed(2)
console.log(`=========================脚本执行完成,耗时${work}s============================\n`)
console.log(`🔔${this.name}, 结束!\n`)
}
notify(array) {
let text = [];
let type = 0
for (let i of array) {
text.push(`${i.user} -- ${i.msg}`)
type = i.type
}
console.log(`\n=============================开始发送提醒消息=============================`)
if (type == 1) {
for (let i of text) {
notify.sendNotify(this.name + "消息提醒", i)
}
} else {
notify.sendNotify(this.name + "消息提醒", text.join('\n'))
}
}
wait(t) {
return new Promise(e => setTimeout(e, t))
}
setOptions(params) {
this.options = params;
}
setCookie(cookie) {
this.options.headers.cookie = cookie
}
jsonParse(str) {
try {
return JSON.parse(str);
} catch (e) {
try {
let data = this.match([/try\s*\{\w+\s*\(([^\)]+)/, /\w+\s*\(([^\)]+)/], str)
return JSON.parse(data);
} catch (ee) {
try {
let cb = this.match(/try\s*\{\s*(\w+)/, str)
if (cb) {
let func = "";
let data = str.replace(cb, `func=`)
eval(data);
return func
}
} catch (eee) {
return str
}
}
}
}
curl(params, extra = '') {
if (typeof(params) != 'object') {
params = {
'url': params
}
}
params = Object.assign({ ...this.options
}, params);
params.method = params.body ? 'POST' : 'GET';
if (params.hasOwnProperty('cookie')) {
params.headers.cookie = params.cookie
}
if (params.hasOwnProperty('ua') || params.hasOwnProperty('useragent')) {
params.headers['user-agent'] = params.ua
}
if (params.hasOwnProperty('referer')) {
params.headers.referer = params.referer
}
if (params.hasOwnProperty('params')) {
params.url += '?' + qs.stringify(params.params)
}
if (params.hasOwnProperty('form')) {
params.method = 'POST'
}
return new Promise(resolve => {
request(params, async (err, resp, data) => {
try {
if (params.console) {
console.log(data)
}
this.source = this.jsonParse(data);
if (extra) {
this[extra] = this.source
}
} catch (e) {
console.log(e, resp)
} finally {
resolve(data);
}
})
})
}
dumps(dict) {
return JSON.stringify(dict)
}
loads(str) {
return JSON.parse(str)
}
notice(msg, type = 0) {
this.message.push({
'index': this.index,
'user': this.user,
'msg': msg,
type
})
}
notices(msg, user, type = 0) {
this.message.push({
'user': user,
'msg': msg,
// 'index': index,
type
})
}
urlparse(url) {
return urls.parse(url, true, true)
}
md5(encryptString) {
return CryptoJS.MD5(encryptString).toString()
}
haskey(data, key, value) {
value = typeof value !== 'undefined' ? value : '';
var spl = key.split('.');
for (var i of spl) {
i = !isNaN(i) ? parseInt(i) : i;
try {
data = data[i];
} catch (error) {
return '';
}
}
if (data == undefined) {
return ''
}
if (value !== '') {
return data === value ? true : false;
} else {
return data
}
}
match(pattern, string) {
pattern = (pattern instanceof Array) ? pattern : [pattern];
for (let pat of pattern) {
// var match = string.match(pat);
var match = pat.exec(string)
if (match) {
var len = match.length;
if (len == 1) {
return match;
} else if (len == 2) {
return match[1];
} else {
var r = [];
for (let i = 1; i < len; i++) {
r.push(match[i])
}
return r;
}
break;
}
// console.log(pat.exec(string))
}
return '';
}
matchall(pattern, string) {
pattern = (pattern instanceof Array) ? pattern : [pattern];
var match;
var result = [];
for (var pat of pattern) {
while ((match = pat.exec(string)) != null) {
var len = match.length;
if (len == 1) {
result.push(match);
} else if (len == 2) {
result.push(match[1]);
} else {
var r = [];
for (let i = 1; i < len; i++) {
r.push(match[i])
}
result.push(r);
}
}
}
return result;
}
compare(property) {
return function(a, b) {
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
}
}
filename(file, rename = '') {
if (!this.runfile) {
this.runfile = path.basename(file).replace(".js", '').replace(/-/g, '_')
}
if (rename) {
rename = `_${rename}`;
}
return path.basename(file).replace(".js", rename).replace(/-/g, '_');
}
rand(n, m) {
var random = Math.floor(Math.random() * (m - n + 1) + n);
return random;
}
random(arr, num) {
var temp_array = new Array();
for (var index in arr) {
temp_array.push(arr[index]);
}
var return_array = new Array();
for (var i = 0; i < num; i++) {
if (temp_array.length > 0) {
var arrIndex = Math.floor(Math.random() * temp_array.length);
return_array[i] = temp_array[arrIndex];
temp_array.splice(arrIndex, 1);
} else {
break;
}
}
return return_array;
}
compact(lists, keys) {
let array = {};
for (let i of keys) {
if (lists[i]) {
array[i] = lists[i];
}
}
return array;
}
unique(arr) {
return Array.from(new Set(arr));
}
end(args) {
return args[args.length - 1]
}
}
module.exports = {
env,
eval: mainEval,
assert,
jxAlgo,
}

1
utils/config.js Normal file
View File

@@ -0,0 +1 @@
module.exports = {}

86
utils/eval.js Normal file
View File

@@ -0,0 +1,86 @@
function mainEval($) {
return `
!(async () => {
jdcookie = process.env.JD_COOKIE ? process.env.JD_COOKIE.split("&") : require("./function/jdcookie").cookie;
cookies={
'all':jdcookie,
'help': typeof(help) != 'undefined' ? [...jdcookie].splice(0,parseInt(help)):[]
}
$.sleep=cookies['all'].length * 500
taskCookie=cookies['all']
if($.config[\`\${$.runfile}_limit\`]){
taskCookie = cookies['all'].slice(0,parseInt($.config[\`\${$.runfile}_limit\`]))
}
jxAlgo = new common.jxAlgo();
if ($.readme) {
console.log(\`使用说明:\\n\${$.readme}\\n以上内容仅供参考,有需求自行添加\\n\`,)
}
console.log(\`======================本次任务共\${taskCookie.length}个京东账户Cookie======================\\n\`)
try{
await prepare();
if ($.sharecode.length > 0) {
$.sharecode = $.sharecode.filter(d=>d && JSON.stringify(d)!='{}')
console.log('助力码', $.sharecode )
}
}catch(e1){console.log("初始函数不存在,将继续执行主函数Main\\n")}
if (typeof(main) != 'undefined') {
try{
for (let i = 0; i < taskCookie.filter(d => d).length; i++) {
$.cookie = taskCookie[i];
$.user = decodeURIComponent($.cookie.match(/pt_pin=([^;]+)/)[1])
$.index = parseInt(i) + 1;
let info = {
'index': $.index,
'user': $.user,
'cookie': $.cookie
}
if (!$.thread) {
console.log(\`\n******开始【京东账号\${$.index}】\${$.user} 任务*********\n\`);
}
if ($.config[\`\${$.runfile}_except\`] && $.config[\`\${$.runfile}_except\`].includes(\$.user)) {
console.log(\`全局变量\${$.runfile}_except中配置了该账号pt_pin,跳过此次任务\`)
}else{
$.setCookie($.cookie)
try{
if ($.sharecode.length > 0) {
for (let smp of $.sharecode) {
smp = Object.assign({ ...info}, smp);
$.thread ? main(smp) : await main(smp);
}
}else{
$.thread ? main(info) : await main(info);
}
}
catch(em){
console.log(em.message)
}
}
}
}catch(em){console.log(em.message)}
if ($.thread) {
await $.wait($.sleep)
}
}
if (typeof(extra) != 'undefined') {
console.log(\`============================开始运行额外任务============================\`)
try{
await extra();
}catch(e4){console.log(e4.message)}
}
})().catch((e) => {
console.log(e.message)
}).finally(() => {
if ($.message.length > 0) {
$.notify($.message)
}
$.done();
});
`
}
module.exports = {
mainEval
}

72
utils/jdShareCodes.js Normal file
View File

@@ -0,0 +1,72 @@
// 从日志中获取互助码
// process.env.SHARE_CODE_FILE = "/scripts/logs/sharecode.log";
// process.env.JD_COOKIE = "cookie1&cookie2";
exports.JDZZ_SHARECODES = [];
exports.DDFACTORY_SHARECODES = [];
exports.DREAM_FACTORY_SHARE_CODES = [];
exports.PLANT_BEAN_SHARECODES = [];
exports.FRUITSHARECODES = [];
exports.PETSHARECODES = [];
exports.JDJOY_SHARECODES = [];
let fileContent = '';
if (process.env.SHARE_CODE_FILE) {
try {
const fs = require('fs');
if (fs.existsSync(process.env.SHARE_CODE_FILE)) fileContent = fs.readFileSync(process.env.SHARE_CODE_FILE, 'utf8');
} catch (err) {
console.error(err)
}
}
let lines = fileContent.split('\n');
let shareCodesMap = {
"JDZZ_SHARECODES": [],
"DDFACTORY_SHARECODES": [],
"DREAM_FACTORY_SHARE_CODES": [],
"PLANT_BEAN_SHARECODES": [],
"FRUITSHARECODES": [],
"PETSHARECODES": [],
"JDJOY_SHARECODES": [],
};
for (let i = 0; i < lines.length; i++) {
if (lines[i].includes('京东赚赚')) {
shareCodesMap.JDZZ_SHARECODES.push(lines[i].split('】')[1].trim());
} else if (lines[i].includes('东东工厂')) {
shareCodesMap.DDFACTORY_SHARECODES.push(lines[i].split('】')[1].trim());
} else if (lines[i].includes('京喜工厂')) {
shareCodesMap.DREAM_FACTORY_SHARE_CODES.push(lines[i].split('】')[1].trim());
} else if (lines[i].includes('京东种豆得豆')) {
shareCodesMap.PLANT_BEAN_SHARECODES.push(lines[i].split('】')[1].trim());
} else if (lines[i].includes('东东农场')) {
shareCodesMap.FRUITSHARECODES.push(lines[i].split('】')[1].trim());
} else if (lines[i].includes('东东萌宠')) {
shareCodesMap.PETSHARECODES.push(lines[i].split('】')[1].trim());
} else if (lines[i].includes('crazyJoy')) {
shareCodesMap.JDJOY_SHARECODES.push(lines[i].split('】')[1].trim());
}
}
for (let key in shareCodesMap) {
shareCodesMap[key] = shareCodesMap[key].reduce((prev, cur) => prev.includes(cur) ? prev : [...prev, cur], []); // 去重
}
let cookieCount = 0;
if (process.env.JD_COOKIE) {
if (process.env.JD_COOKIE.indexOf('&') > -1) {
cookieCount = process.env.JD_COOKIE.split('&').length;
} else {
cookieCount = process.env.JD_COOKIE.split('\n').length;
}
}
for (let key in shareCodesMap) {
exports[key] = [];
if (shareCodesMap[key].length === 0) {
continue;
}
for (let i = 0; i < cookieCount; i++) {
exports[key][i] = shareCodesMap[key].sort(() => Math.random() - 0.5).join('@');
}
}

466
utils/jdValidate.js Normal file
View File

@@ -0,0 +1,466 @@
const https = require('https');
const http = require('http');
const stream = require('stream');
const zlib = require('zlib');
const vm = require('vm');
const PNG = require('png-js');
const UA = 'jdapp;iPhone;9.4.6;14.2;965af808880443e4c1306a54afdd5d5ae771de46;network/wifi;supportApplePay/0;hasUPPay/0;hasOCPay/0;model/iPhone8,4;addressid/;supportBestPay/0;appBuild/167618;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1';
Math.avg = function average() {
var sum = 0;
var len = this.length;
for (var i = 0; i < len; i++) {
sum += this[i];
}
return sum / len;
};
function sleep(timeout) {
return new Promise((resolve) => setTimeout(resolve, timeout));
}
class PNGDecoder extends PNG {
constructor(args) {
super(args);
this.pixels = [];
}
decodeToPixels() {
return new Promise((resolve) => {
this.decode((pixels) => {
this.pixels = pixels;
resolve();
});
});
}
getImageData(x, y, w, h) {
const {
pixels
} = this;
const len = w * h * 4;
const startIndex = x * 4 + y * (w * 4);
return {
data: pixels.slice(startIndex, startIndex + len)
};
}
}
const PUZZLE_GAP = 8;
const PUZZLE_PAD = 10;
class PuzzleRecognizer {
constructor(bg, patch, y) {
// console.log(bg);
const imgBg = new PNGDecoder(Buffer.from(bg, 'base64'));
const imgPatch = new PNGDecoder(Buffer.from(patch, 'base64'));
// console.log(imgBg);
this.bg = imgBg;
this.patch = imgPatch;
this.rawBg = bg;
this.rawPatch = patch;
this.y = y;
this.w = imgBg.width;
this.h = imgBg.height;
}
async run() {
await this.bg.decodeToPixels();
await this.patch.decodeToPixels();
return this.recognize();
}
recognize() {
const {
ctx,
w: width,
bg
} = this;
const {
width: patchWidth,
height: patchHeight
} = this.patch;
const posY = this.y + PUZZLE_PAD + ((patchHeight - PUZZLE_PAD) / 2) - (PUZZLE_GAP / 2);
// const cData = ctx.getImageData(0, a.y + 10 + 20 - 4, 360, 8).data;
const cData = bg.getImageData(0, posY, width, PUZZLE_GAP).data;
const lumas = [];
for (let x = 0; x < width; x++) {
var sum = 0;
// y xais
for (let y = 0; y < PUZZLE_GAP; y++) {
var idx = x * 4 + y * (width * 4);
var r = cData[idx];
var g = cData[idx + 1];
var b = cData[idx + 2];
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
sum += luma;
}
lumas.push(sum / PUZZLE_GAP);
}
const n = 2; // minium macroscopic image width (px)
const margin = patchWidth - PUZZLE_PAD;
const diff = 20; // macroscopic brightness difference
const radius = PUZZLE_PAD;
for (let i = 0, len = lumas.length - 2 * 4; i < len; i++) {
const left = (lumas[i] + lumas[i + 1]) / n;
const right = (lumas[i + 2] + lumas[i + 3]) / n;
const mi = margin + i;
const mLeft = (lumas[mi] + lumas[mi + 1]) / n;
const mRigth = (lumas[mi + 2] + lumas[mi + 3]) / n;
if (left - right > diff && mLeft - mRigth < -diff) {
const pieces = lumas.slice(i + 2, margin + i + 2);
const median = pieces.sort((x1, x2) => x1 - x2)[20];
const avg = Math.avg(pieces);
// noise reducation
if (median > left || median > mRigth) return;
if (avg > 100) return;
// console.table({left,right,mLeft,mRigth,median});
// ctx.fillRect(i+n-radius, 0, 1, 360);
// console.log(i+n-radius);
return i + n - radius;
}
}
// not found
return -1;
}
runWithCanvas() {
const {
createCanvas,
Image
} = require('canvas');
const canvas = createCanvas();
const ctx = canvas.getContext('2d');
const imgBg = new Image();
const imgPatch = new Image();
const prefix = 'data:image/png;base64,';
imgBg.src = prefix + this.rawBg;
imgPatch.src = prefix + this.rawPatch;
const {
naturalWidth: w,
naturalHeight: h
} = imgBg;
canvas.width = w;
canvas.height = h;
ctx.clearRect(0, 0, w, h);
ctx.drawImage(imgBg, 0, 0, w, h);
const width = w;
const {
naturalWidth,
naturalHeight
} = imgPatch;
const posY = this.y + PUZZLE_PAD + ((naturalHeight - PUZZLE_PAD) / 2) - (PUZZLE_GAP / 2);
// const cData = ctx.getImageData(0, a.y + 10 + 20 - 4, 360, 8).data;
const cData = ctx.getImageData(0, posY, width, PUZZLE_GAP).data;
const lumas = [];
for (let x = 0; x < width; x++) {
var sum = 0;
// y xais
for (let y = 0; y < PUZZLE_GAP; y++) {
var idx = x * 4 + y * (width * 4);
var r = cData[idx];
var g = cData[idx + 1];
var b = cData[idx + 2];
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
sum += luma;
}
lumas.push(sum / PUZZLE_GAP);
}
const n = 2; // minium macroscopic image width (px)
const margin = naturalWidth - PUZZLE_PAD;
const diff = 20; // macroscopic brightness difference
const radius = PUZZLE_PAD;
for (let i = 0, len = lumas.length - 2 * 4; i < len; i++) {
const left = (lumas[i] + lumas[i + 1]) / n;
const right = (lumas[i + 2] + lumas[i + 3]) / n;
const mi = margin + i;
const mLeft = (lumas[mi] + lumas[mi + 1]) / n;
const mRigth = (lumas[mi + 2] + lumas[mi + 3]) / n;
if (left - right > diff && mLeft - mRigth < -diff) {
const pieces = lumas.slice(i + 2, margin + i + 2);
const median = pieces.sort((x1, x2) => x1 - x2)[20];
const avg = Math.avg(pieces);
// noise reducation
if (median > left || median > mRigth) return;
if (avg > 100) return;
// console.table({left,right,mLeft,mRigth,median});
// ctx.fillRect(i+n-radius, 0, 1, 360);
// console.log(i+n-radius);
return i + n - radius;
}
}
// not found
return -1;
}
}
const DATA = {
"appId": "17839d5db83",
"scene": "cww",
"product": "embed",
"lang": "zh_CN",
};
let SERVER = 'iv.jd.com';
if (process.env.JDJR_SERVER) {
SERVER = process.env.JDJR_SERVER
}
class JDJRValidator {
constructor() {
this.data = {};
this.x = 0;
this.t = Date.now();
this.n = 0;
}
async run() {
const tryRecognize = async () => {
const x = await this.recognize();
if (x > 0) {
return x;
}
// retry
return await tryRecognize();
};
const puzzleX = await tryRecognize();
console.log(puzzleX);
const pos = new MousePosFaker(puzzleX).run();
const d = getCoordinate(pos);
// console.log(pos[pos.length-1][2] -Date.now());
await sleep(3000);
//await sleep(pos[pos.length - 1][2] - Date.now());
const result = await JDJRValidator.jsonp('/slide/s.html', {
d,
...this.data
});
if (result.message === 'success') {
// console.log(result);
// console.log('JDJRValidator: %fs', (Date.now() - this.t) / 1000);
return result;
} else {
if (this.n > 60) {
return;
}
this.n++;
return await this.run();
}
}
async recognize() {
const data = await JDJRValidator.jsonp('/slide/g.html', {
e: ''
});
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);
const puzzleX = await re.run();
if (puzzleX > 0) {
this.data = {
c: data.challenge,
w: re.w,
e: '',
s: '',
o: '',
};
this.x = puzzleX;
}
return puzzleX;
}
async report(n) {
console.time('PuzzleRecognizer');
let count = 0;
for (let i = 0; i < n; i++) {
const x = await this.recognize();
if (x > 0) count++;
if (i % 50 === 0) {
console.log('%f\%', (i / n) * 100);
}
}
console.log('successful: %f\%', (count / n) * 100);
console.timeEnd('PuzzleRecognizer');
}
static jsonp(api, data = {}) {
return new Promise((resolve, reject) => {
const fnId = `jsonp_${String(Math.random()).replace('.', '')}`;
const extraData = {
callback: fnId
};
const query = new URLSearchParams({ ...DATA,
...extraData,
...data
}).toString();
const url = `http://${SERVER}${api}?${query}`;
const headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip,deflate,br',
'Accept-Language': 'zh-CN,en-US',
'Connection': 'keep-alive',
'Host': SERVER,
'Proxy-Connection': 'keep-alive',
'Referer': 'https://h5.m.jd.com/babelDiy/Zeus/2wuqXrZrhygTQzYA7VufBEpj4amH/index.html',
'User-Agent': UA,
};
const req = http.get(url, {
headers
}, (response) => {
let res = response;
if (res.headers['content-encoding'] === 'gzip') {
const unzipStream = new stream.PassThrough();
stream.pipeline(response, zlib.createGunzip(), unzipStream, reject, );
res = unzipStream;
}
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => rawData += chunk);
res.on('end', () => {
try {
const ctx = {
[fnId]: (data) => ctx.data = data,
data: {},
};
vm.createContext(ctx);
vm.runInContext(rawData, ctx);
// console.log(ctx.data);
res.resume();
resolve(ctx.data);
} catch (e) {
reject(e);
}
});
});
req.on('error', reject);
req.end();
});
}
}
function getCoordinate(c) {
function string10to64(d) {
var c = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~".split(""),
b = c.length,
e = +d,
a = [];
do {
mod = e % b;
e = (e - mod) / b;
a.unshift(c[mod])
} while (e);
return a.join("")
}
function prefixInteger(a, b) {
return (Array(b).join(0) + a).slice(-b)
}
function pretreatment(d, c, b) {
var e = string10to64(Math.abs(d));
var a = "";
if (!b) {
a += (d > 0 ? "1" : "0")
}
a += prefixInteger(e, c);
return a
}
var b = new Array();
for (var e = 0; e < c.length; e++) {
if (e == 0) {
b.push(pretreatment(c[e][0] < 262143 ? c[e][0] : 262143, 3, true));
b.push(pretreatment(c[e][1] < 16777215 ? c[e][1] : 16777215, 4, true));
b.push(pretreatment(c[e][2] < 4398046511103 ? c[e][2] : 4398046511103, 7, true))
} else {
var a = c[e][0] - c[e - 1][0];
var f = c[e][1] - c[e - 1][1];
var d = c[e][2] - c[e - 1][2];
b.push(pretreatment(a < 4095 ? a : 4095, 2, false));
b.push(pretreatment(f < 4095 ? f : 4095, 2, false));
b.push(pretreatment(d < 16777215 ? d : 16777215, 4, true))
}
}
return b.join("")
}
const HZ = 32;
class MousePosFaker {
constructor(puzzleX) {
this.x = parseInt(Math.random() * 20 + 20, 10);
this.y = parseInt(Math.random() * 80 + 80, 10);
this.t = Date.now();
this.pos = [
[this.x, this.y, this.t]
];
this.minDuration = parseInt(1000 / HZ, 10);
// this.puzzleX = puzzleX;
this.puzzleX = puzzleX + parseInt(Math.random() * 2 - 1, 10);
this.STEP = parseInt(Math.random() * 6 + 5, 10);
this.DURATION = parseInt(Math.random() * 7 + 12, 10) * 100;
// [9,1600] [10,1400]
this.STEP = 9;
// this.DURATION = 2000;
console.log(this.STEP, this.DURATION);
}
run() {
const perX = this.puzzleX / this.STEP;
const perDuration = this.DURATION / this.STEP;
const firstPos = [this.x - parseInt(Math.random() * 6, 10), this.y + parseInt(Math.random() * 11, 10), this.t];
this.pos.unshift(firstPos);
this.stepPos(perX, perDuration);
this.fixPos();
const reactTime = parseInt(60 + Math.random() * 100, 10);
const lastIdx = this.pos.length - 1;
const lastPos = [this.pos[lastIdx][0], this.pos[lastIdx][1], this.pos[lastIdx][2] + reactTime];
this.pos.push(lastPos);
return this.pos;
}
stepPos(x, duration) {
let n = 0;
const sqrt2 = Math.sqrt(2);
for (let i = 1; i <= this.STEP; i++) {
n += 1 / i;
}
for (let i = 0; i < this.STEP; i++) {
x = this.puzzleX / (n * (i + 1));
const currX = parseInt((Math.random() * 30 - 15) + x, 10);
const currY = parseInt(Math.random() * 7 - 3, 10);
const currDuration = parseInt((Math.random() * 0.4 + 0.8) * duration, 10);
this.moveToAndCollect({
x: currX,
y: currY,
duration: currDuration,
});
}
}
fixPos() {
const actualX = this.pos[this.pos.length - 1][0] - this.pos[1][0];
const deviation = this.puzzleX - actualX;
if (Math.abs(deviation) > 4) {
this.moveToAndCollect({
x: deviation,
y: parseInt(Math.random() * 8 - 3, 10),
duration: 100,
});
}
}
moveToAndCollect({
x,
y,
duration
}) {
let movedX = 0;
let movedY = 0;
let movedT = 0;
const times = duration / this.minDuration;
let perX = x / times;
let perY = y / times;
let padDuration = 0;
if (Math.abs(perX) < 1) {
padDuration = duration / Math.abs(x) - this.minDuration;
perX = 1;
perY = y / Math.abs(x);
}
while (Math.abs(movedX) < Math.abs(x)) {
const rDuration = parseInt(padDuration + Math.random() * 16 - 4, 10);
movedX += perX + Math.random() * 2 - 1;
movedY += perY;
movedT += this.minDuration + rDuration;
const currX = parseInt(this.x + 20, 10);
const currY = parseInt(this.y + 20, 10);
const currT = this.t + movedT;
this.pos.push([currX, currY, currT]);
}
this.x += x;
this.y += y;
this.t += Math.max(duration, movedT);
}
}
exports.JDJRValidator = JDJRValidator

91
utils/jd_jxmcToken.js Normal file
View File

@@ -0,0 +1,91 @@
function t(n, t) {
var r = (65535 & n) + (65535 & t);
return (n >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r
}
function r(n, t) {
return n << t | n >>> 32 - t
}
function e(n, e, o, u, c, f) {
return t(r(t(t(e, n), t(u, f)), c), o)
}
function o(n, t, r, o, u, c, f) {
return e(t & r | ~t & o, n, t, u, c, f)
}
function u(n, t, r, o, u, c, f) {
return e(t & o | r & ~o, n, t, u, c, f)
}
function c(n, t, r, o, u, c, f) {
return e(t ^ r ^ o, n, t, u, c, f)
}
function f(n, t, r, o, u, c, f) {
return e(r ^ (t | ~o), n, t, u, c, f)
}
function i(n, r) {
n[r >> 5] |= 128 << r % 32, n[14 + (r + 64 >>> 9 << 4)] = r;
var e, i, a, d, h, l = 1732584193, g = -271733879, v = -1732584194, m = 271733878;
for (e = 0; e < n.length; e += 16) i = l, a = g, d = v, h = m, g = f(g = f(g = f(g = f(g = c(g = c(g = c(g = c(g = u(g = u(g = u(g = u(g = o(g = o(g = o(g = o(g, v = o(v, m = o(m, l = o(l, g, v, m, n[e], 7, -680876936), g, v, n[e + 1], 12, -389564586), l, g, n[e + 2], 17, 606105819), m, l, n[e + 3], 22, -1044525330), v = o(v, m = o(m, l = o(l, g, v, m, n[e + 4], 7, -176418897), g, v, n[e + 5], 12, 1200080426), l, g, n[e + 6], 17, -1473231341), m, l, n[e + 7], 22, -45705983), v = o(v, m = o(m, l = o(l, g, v, m, n[e + 8], 7, 1770035416), g, v, n[e + 9], 12, -1958414417), l, g, n[e + 10], 17, -42063), m, l, n[e + 11], 22, -1990404162), v = o(v, m = o(m, l = o(l, g, v, m, n[e + 12], 7, 1804603682), g, v, n[e + 13], 12, -40341101), l, g, n[e + 14], 17, -1502002290), m, l, n[e + 15], 22, 1236535329), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 1], 5, -165796510), g, v, n[e + 6], 9, -1069501632), l, g, n[e + 11], 14, 643717713), m, l, n[e], 20, -373897302), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 5], 5, -701558691), g, v, n[e + 10], 9, 38016083), l, g, n[e + 15], 14, -660478335), m, l, n[e + 4], 20, -405537848), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 9], 5, 568446438), g, v, n[e + 14], 9, -1019803690), l, g, n[e + 3], 14, -187363961), m, l, n[e + 8], 20, 1163531501), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 13], 5, -1444681467), g, v, n[e + 2], 9, -51403784), l, g, n[e + 7], 14, 1735328473), m, l, n[e + 12], 20, -1926607734), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 5], 4, -378558), g, v, n[e + 8], 11, -2022574463), l, g, n[e + 11], 16, 1839030562), m, l, n[e + 14], 23, -35309556), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 1], 4, -1530992060), g, v, n[e + 4], 11, 1272893353), l, g, n[e + 7], 16, -155497632), m, l, n[e + 10], 23, -1094730640), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 13], 4, 681279174), g, v, n[e], 11, -358537222), l, g, n[e + 3], 16, -722521979), m, l, n[e + 6], 23, 76029189), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 9], 4, -640364487), g, v, n[e + 12], 11, -421815835), l, g, n[e + 15], 16, 530742520), m, l, n[e + 2], 23, -995338651), v = f(v, m = f(m, l = f(l, g, v, m, n[e], 6, -198630844), g, v, n[e + 7], 10, 1126891415), l, g, n[e + 14], 15, -1416354905), m, l, n[e + 5], 21, -57434055), v = f(v, m = f(m, l = f(l, g, v, m, n[e + 12], 6, 1700485571), g, v, n[e + 3], 10, -1894986606), l, g, n[e + 10], 15, -1051523), m, l, n[e + 1], 21, -2054922799), v = f(v, m = f(m, l = f(l, g, v, m, n[e + 8], 6, 1873313359), g, v, n[e + 15], 10, -30611744), l, g, n[e + 6], 15, -1560198380), m, l, n[e + 13], 21, 1309151649), v = f(v, m = f(m, l = f(l, g, v, m, n[e + 4], 6, -145523070), g, v, n[e + 11], 10, -1120210379), l, g, n[e + 2], 15, 718787259), m, l, n[e + 9], 21, -343485551), l = t(l, i), g = t(g, a), v = t(v, d), m = t(m, h);
return [l, g, v, m]
}
function a(n) {
var t, r = "", e = 32 * n.length;
for (t = 0; t < e; t += 8) r += String.fromCharCode(n[t >> 5] >>> t % 32 & 255);
return r
}
function d(n) {
var t, r = [];
for (r[(n.length >> 2) - 1] = void 0, t = 0; t < r.length; t += 1) r[t] = 0;
var e = 8 * n.length;
for (t = 0; t < e; t += 8) r[t >> 5] |= (255 & n.charCodeAt(t / 8)) << t % 32;
return r
}
function h(n) {
return a(i(d(n), 8 * n.length))
}
function l(n, t) {
var r, e, o = d(n), u = [], c = [];
for (u[15] = c[15] = void 0, o.length > 16 && (o = i(o, 8 * n.length)), r = 0; r < 16; r += 1) u[r] = 909522486 ^ o[r], c[r] = 1549556828 ^ o[r];
return e = i(u.concat(d(t)), 512 + 8 * t.length), a(i(c.concat(e), 640))
}
function g(n) {
var t, r, e = "";
for (r = 0; r < n.length; r += 1) t = n.charCodeAt(r), e += "0123456789abcdef".charAt(t >>> 4 & 15) + "0123456789abcdef".charAt(15 & t);
return e
}
function v(n) {
return unescape(encodeURIComponent(n))
}
function m(n) {
return h(v(n))
}
function p(n) {
return g(m(n))
}
function s(n, t) {
return l(v(n), v(t))
}
function C(n, t) {
return g(s(n, t))
}
function A(n, t, r) {
return t ? r ? s(t, n) : C(t, n) : r ? m(n) : p(n)
}
module.exports = A

6
utils/jdcookie.js Normal file
View File

@@ -0,0 +1,6 @@
// 本地测试在这边填写cookie
let cookie = [
];
module.exports = {
cookie
}

204
utils/jxAlgo.js Normal file
View File

@@ -0,0 +1,204 @@
let request = require("request");
let CryptoJS = require('crypto-js');
let qs = require("querystring");
Date.prototype.Format = function(fmt) {
var e,
n = this,
d = fmt,
l = {
"M+": n.getMonth() + 1,
"d+": n.getDate(),
"D+": n.getDate(),
"h+": n.getHours(),
"H+": n.getHours(),
"m+": n.getMinutes(),
"s+": n.getSeconds(),
"w+": n.getDay(),
"q+": Math.floor((n.getMonth() + 3) / 3),
"S+": n.getMilliseconds()
};
/(y+)/i.test(d) && (d = d.replace(RegExp.$1, "".concat(n.getFullYear()).substr(4 - RegExp.$1.length)));
for (var k in l) {
if (new RegExp("(".concat(k, ")")).test(d)) {
var t, a = "S+" === k ? "000" : "00";
d = d.replace(RegExp.$1, 1 == RegExp.$1.length ? l[k] : ("".concat(a) + l[k]).substr("".concat(l[k]).length))
}
}
return d;
}
function generateFp() {
let e = "0123456789";
let a = 13;
let i = '';
for (; a--;) i += e[Math.random() * e.length | 0];
return (i + Date.now()).slice(0, 16)
}
function getUrlData(url, name) {
if (typeof URL !== "undefined") {
let urls = new URL(url);
let data = urls.searchParams.get(name);
return data ? data : '';
} else {
const query = url.match(/\?.*/)[0].substring(1)
const vars = query.split('&')
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split('=')
if (pair[0] === name) {
return vars[i].substr(vars[i].indexOf('=') + 1);
}
}
return ''
}
}
class jxAlgo {
constructor(params = {}) {
this.appId = 10001
this.result = {}
this.timestamp = Date.now();
for (let i in params) {
this[i] = params[i]
}
}
set(params = {}) {
for (let i in params) {
this[i] = params[i]
}
}
get(key) {
return this[key]
}
async dec(url) {
if (!this.tk) {
this.fingerprint = generateFp();
await this.requestAlgo()
}
let obj = qs.parse(url.split("?")[1]);
let stk = obj['_stk'];
return this.h5st(this.timestamp, stk, url)
}
h5st(time, stk, url) {
stk = stk || (url ? getUrlData(url, '_stk') : '')
const timestamp = new Date(time).Format("yyyyMMddhhmmssSSS");
let hash1 = this.enCryptMethodJD(this.tk, this.fingerprint.toString(), timestamp.toString(), this.appId.toString(), CryptoJS).toString(CryptoJS.enc.Hex);
let st = '';
stk.split(',').map((item, index) => {
st += `${item}:${getUrlData(url, item)}${index === stk.split(',').length - 1 ? '' : '&'}`;
})
const hash2 = CryptoJS.HmacSHA256(st, hash1.toString()).toString(CryptoJS.enc.Hex);
const enc = (["".concat(timestamp.toString()), "".concat(this.fingerprint.toString()), "".concat(this.appId.toString()), "".concat(this.tk), "".concat(hash2)].join(";"))
this.result['fingerprint'] = this.fingerprint;
this.result['timestamp'] = this.timestamp
this.result['stk'] = stk;
this.result['h5st'] = enc
let sp = url.split("?");
let obj = qs.parse(sp[1])
if (obj.callback) {
delete obj.callback
}
let params = Object.assign(obj, {
'_time': this.timestamp,
'_': this.timestamp,
'timestamp': this.timestamp,
'sceneval': 2,
'g_login_type': 1,
'h5st': enc,
})
this.result['url'] = `${sp[0]}?${qs.stringify(params)}`
return this.result
}
token(user) {
let nickname = user.includes('pt_pin') ? user.match(/pt_pin=([^;]+)/)[1] : user;
let phoneId = this.createuuid(40, 'lc');
let token = this.md5(decodeURIComponent(nickname) + this.timestamp + phoneId + 'tPOamqCuk9NLgVPAljUyIHcPRmKlVxDy');
return {
'strPgtimestamp': this.timestamp,
'strPhoneID': phoneId,
'strPgUUNum': token
}
}
md5(encryptString) {
return CryptoJS.MD5(encryptString).toString()
}
createuuid(a, c) {
switch (c) {
case "a":
c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
break;
case "n":
c = "0123456789";
break;
case "c":
c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
case "l":
c = "abcdefghijklmnopqrstuvwxyz";
break;
case 'cn':
case 'nc':
c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
break;
case "lc":
case "cl":
c = "abcdefghijklmnopqrstuvwxyz0123456789";
break;
default:
c = "0123456789abcdef"
}
var e = "";
for (var g = 0; g < a; g++) e += c[Math.ceil(1E8 * Math.random()) % c.length];
return e
}
async requestAlgo() {
const options = {
"url": `https://cactus.jd.com/request_algo?g_ty=ajax`,
"headers": {
'Authority': 'cactus.jd.com',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'Accept': 'application/json',
'User-Agent': 'jdpingou;iPhone;4.9.4;12.4;ae49fae72d0a8976f5155267f56ec3a5b0da75c3;network/wifi;model/iPhone8,4;appBuild/100579;ADID/00000000-0000-0000-0000-000000000000;supportApplePay/1;hasUPPay/0;pushNoticeIsOpen/0;hasOCPay/0;supportBestPay/0;session/1;pap/JA2019_3111789;brand/apple;supportJDSHWK/1;Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
'Content-Type': 'application/json',
'Origin': 'https://st.jingxi.com',
'Sec-Fetch-Site': 'cross-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://st.jingxi.com/pingou/dream_factory/index.html?ptag=7155.9.4',
'Accept-Language': 'zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7'
},
'body': JSON.stringify({
"version": "1.0",
"fp": this.fingerprint,
"appId": this.appId.toString(),
"timestamp": this.timestamp,
"platform": "web",
"expandParams": ""
})
}
return new Promise(async resolve => {
request.post(options, (err, resp, data) => {
try {
if (data) {
data = JSON.parse(data);
if (data['status'] === 200) {
let result = data.data.result
this.tk = result.tk;
let enCryptMethodJDString = result.algo;
if (enCryptMethodJDString) {
this.enCryptMethodJD = new Function(`return ${enCryptMethodJDString}`)();
}
this.result = result
}
}
} catch (e) {
console.log(e)
} finally {
resolve(this.result);
}
})
})
}
}
module.exports = jxAlgo

2499
utils/sendNotify.js Normal file

File diff suppressed because it is too large Load Diff