yydspure/jddj_getPoints.js

246 lines
23 KiB
JavaScript
Raw Normal View History

2022-02-08 14:36:02 +08:00
//京东到家鲜豆庄园收水滴脚本,支持qx,loon,shadowrocket,surge,nodejs
// 兼容京东jdCookie.js
// 手机设备在boxjs里填写cookie
// boxjs订阅地址:https://gitee.com/passerby-b/javascript/raw/master/JD/passerby-b.boxjs.json
//TG群:https://t.me/passerbyb2021
//[task_local]
//7 */1 * * * https://raw.githubusercontent.com/passerby-b/JDDJ/main/jddj_getPoints.js
//[Script]
//cron "7 */1 * * *" script-path=https://raw.githubusercontent.com/passerby-b/JDDJ/main/jddj_getPoints.js,tag=京东到家鲜豆庄园收水滴
const $ = new API("jddj_getPoints");
let ckPath = './jdCookie.js';//ck路径,环境变量:JDDJ_CKPATH
let cookies = [];
let thiscookie = '', deviceid = '', nickname = '';
let lat = '30.' + Math.round(Math.random() * (99999 - 10000) + 10000);
let lng = '114.' + Math.round(Math.random() * (99999 - 10000) + 10000);
let cityid = Math.round(Math.random() * (1500 - 1000) + 1000);
!(async () => {
if (cookies.length == 0) {
if ($.env.isNode) {
if (process.env.JDDJ_CKPATH) ckPath = process.env.JDDJ_CKPATH;
delete require.cache[ckPath];
let jdcookies = require(ckPath);
for (let key in jdcookies) if (!!jdcookies[key]) cookies.push(jdcookies[key]);
}
else {
let ckstr = $.read('#jddj_cookies');
if (!!ckstr) {
if (ckstr.indexOf(',') < 0) {
cookies.push(ckstr);
} else {
cookies = ckstr.split(',');
}
}
}
}
if (cookies.length == 0) {
console.log(`\r\n请先填写cookie`);
return;
}
for (let i = 0; i < cookies.length; i++) {
console.log(`\r\n★★★★★开始执行第${i + 1}个账号,共${cookies.length}个账号★★★★★`);
thiscookie = cookies[i];
if (!thiscookie) continue;
thiscookie = await taskLoginUrl(thiscookie);
await userinfo();
await $.wait(1000);
await getPoints();
await $.wait(1000);
}
})().catch((e) => {
console.log('', `❌失败! 原因: ${e}!`, '');
}).finally(() => {
$.done();
})
//收水车水滴
async function getPoints() {
return new Promise(async resolve => {
try {
let time = Math.round(new Date());
let option = urlTask('https://daojia.jd.com/client?_jdrandom=' + time + '&_funid_=plantBeans/getWater', 'functionId=plantBeans%2FgetWater&isNeedDealError=true&method=POST&body=%7B%7D&lat=' + lat + '&lng=' + lng + '&lat_pos=' + lat + '&lng_pos=' + lng + '&city_id=' + cityid + '&channel=rn&platform=6.6.0&platCode=h5&appVersion=6.6.0&appName=paidaojia&deviceModel=appmodel&traceId=' + deviceid + time + '&deviceToken=' + deviceid + '&deviceId=' + deviceid + '&_jdrandom=' + time + '&_funid_=plantBeans%2FgetWater');
$.http.post(option).then(async response => {
let data = JSON.parse(response.body);
if (data.code == 0) {
console.log('\n【收水车水滴】:' + data.msg + '->当前收取:' + data.result.addWater + ',当前剩余:' + data.result.water + ',当日累计:' + data.result.dailyWater);
} else {
console.log('\n【收水车水滴】:' + data.msg);
}
resolve();
})
} catch (error) {
console.log('\n【收水车水滴】:' + error);
resolve();
}
})
}
//浇水
async function watering() {
return new Promise(async resolve => {
try {
let option = urlTask('https://daojia.jd.com/client?_jdrandom=' + Math.round(new Date()), 'functionId=plantBeans%2Fwatering&isNeedDealError=true&method=POST&body=%7B%22activityId%22%3A%2223e4a58bca00bef%22%2C%22waterAmount%22%3A100%7D&lat=&lng=&lat_pos=&lng_pos=&city_id=&channel=ios&platform=6.6.0&platCode=h5&appVersion=6.6.0&appName=paidaojia&deviceModel=appmodel&traceId=' + deviceid + Math.round(new Date()) + '&deviceToken=' + deviceid + '&deviceId=' + deviceid + '');
let waterStatus = 1, waterCount = 0;
do {
waterCount++;
console.log(`\n**********开始执行第${waterCount}次浇水**********`);
$.http.post(option).then(response => {
let data = JSON.parse(response.body);
console.log('\n【浇水】:' + data.msg);
waterStatus = data.code;
})
await $.wait(1000);
} while (waterStatus == 0);
resolve();
} catch (error) {
console.log('\n【浇水】:' + error);
resolve();
}
})
}
//个人信息
async function userinfo() {
return new Promise(async resolve => {
try {
let option = urlTask('https://daojia.jd.com/client?channel=wx_xcx&platform=5.0.0&platCode=mini&mpChannel=wx_xcx&appVersion=8.10.5&xcxVersion=8.10.1&appName=paidaojia&functionId=mine%2FgetUserAccountInfo&isForbiddenDialog=false&isNeedDealError=false&isNeedDealLogin=false&body=%7B%22cityId%22%3A' + cityid + '%2C%22fromSource%22%3A%225%22%7D&afsImg=&lat_pos=' + lat + '&lng_pos=' + lng + '&lat=' + lat + '&lng=' + lng + '&city_id=' + cityid + '&deviceToken=' + deviceid + '&deviceId=' + deviceid + '&deviceModel=appmodel&business=&traceId=' + deviceid + '1628044517506&channelCode=', '');
$.http.get(option).then(response => {
//console.log(response.body);
let data = JSON.parse(response.body);
if (data.code == 0) {
try {
nickname = data.result.userInfo.userBaseInfo.nickName;
console.log("●●●" + nickname + "●●●");
} catch (error) { nickname = '昵称获取失败' }
}
else nickname = '昵称获取失败';
});
resolve();
} catch (error) {
console.log('\n【个人信息】:' + error);
resolve();
}
})
}
function urlTask(url, body) {
let arr = decodeURIComponent(body).split('&');
let json = {}, keys = [], sortVlaues = [];
for (const o of arr) {
let c = o.split('=');
if (!!c[1] && c[0] != 'functionId' && c[0] != 'signKeyV1') {
json[c[0]] = c[1];
keys.push(c[0]);
}
}
keys = keys.sort();
keys.forEach(element => {
sortVlaues.push(json[element]);
});
const secret = "923047ae3f8d11d8b19aeb9f3d1bc200";//秘钥
// var hmac = crypto.createHmac("sha256", secret);
// var content = hmac.update(sortVlaues.join('&'));
// var cryptoContent = content.digest("hex");
let cryptoContent = hex_hmac_sha256(secret, sortVlaues.join('&'));
let option = {
url: url,
headers: {
'Host': 'daojia.jd.com',
'Content-Type': 'application/x-www-form-urlencoded;',
'Cookie': thiscookie,
'Connection': 'keep-alive',
'Accept': '*/*',
'User-Agent': 'jdapp;iPhone;10.1.0;14.1;' + deviceid + ';network/wifi;model/iPhone11,6;addressid/397459499;appBuild/167774;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1',
'Accept-Language': 'zh-cn'
},
body: body + '&signKeyV1=' + cryptoContent
};
return option;
}
//根据京东ck获取到家ck
async function taskLoginUrl(thiscookie) {
return new Promise(async resolve => {
try {
if (thiscookie.indexOf('deviceid_pdj_jd') > -1) {
let arr = thiscookie.split(';');
for (const o of arr) {
if (o.indexOf('deviceid_pdj_jd') > -1) {
deviceid = o.split('=')[1];
}
}
resolve(thiscookie);
}
else {
deviceid = _uuid();
let option = {
url: encodeURI('https://daojia.jd.com/client?_jdrandom=' + (+new Date()) + '&_funid_=login/treasure&functionId=login/treasure&body={}&lat=&lng=&lat_pos=&lng_pos=&city_id=&channel=h5&platform=6.6.0&platCode=h5&appVersion=6.6.0&appName=paidaojia&deviceModel=appmodel&isNeedDealError=false&traceId=' + deviceid + '&deviceToken=' + deviceid + '&deviceId=' + deviceid + '&_jdrandom=' + (+new Date()) + '&_funid_=login/treasure'),
headers: {
"Cookie": 'deviceid_pdj_jd=' + deviceid + ';' + thiscookie + ';',
"Host": "daojia.jd.com",
'Content-Type': 'application/x-www-form-urlencoded;',
"User-Agent": 'jdapp;iPhone;10.0.10;14.1;' + deviceid + ';network/wifi;model/iPhone11,6;appBuild/167764;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1'
}
};
let ckstr = '';
await $.http.get(option).then(async response => {
//console.log(response);
let body = JSON.parse(response.body);
if (body.code == 0) {
for (const key in response.headers) {
if (key.toLowerCase().indexOf('cookie') > -1) {
ckstr = response.headers[key].toString();
}
}
ckstr += ';deviceid_pdj_jd=' + deviceid;
}
else {
console.log(body.msg);
}
});
resolve(ckstr);
}
} catch (error) {
console.log(error);
resolve('');
}
})
}
function _uuid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
/*********************************** API *************************************/
function ENV() { const e = "undefined" != typeof $task, t = "undefined" != typeof $loon, s = "undefined" != typeof $httpClient && !t, i = "function" == typeof require && "undefined" != typeof $jsbox; return { isQX: e, isLoon: t, isSurge: s, isNode: "function" == typeof require && !i, isJSBox: i, isRequest: "undefined" != typeof $request, isScriptable: "undefined" != typeof importModule } } function HTTP(e = { baseURL: "" }) { const { isQX: t, isLoon: s, isSurge: i, isScriptable: n, isNode: o } = ENV(), r = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)/; const u = {}; return ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"].forEach(l => u[l.toLowerCase()] = (u => (function (u, l) { l = "string" == typeof l ? { url: l } : l; const h = e.baseURL; h && !r.test(l.url || "") && (l.url = h ? h + l.url : l.url); const a = (l = { ...e, ...l }).timeout, c = { onRequest: () => { }, onResponse: e => e, onTimeout: () => { }, ...l.events }; let f, d; if (c.onRequest(u, l), t) f = $task.fetch({ method: u, ...l }); else if (s || i || o) f = new Promise((e, t) => { (o ? require("request") : $httpClient)[u.toLowerCase()](l, (s, i, n) => { s ? t(s) : e({ statusCode: i.status || i.statusCode, headers: i.headers, body: n }) }) }); else if (n) { const e = new Request(l.url); e.method = u, e.headers = l.headers, e.body = l.body, f = new Promise((t, s) => { e.loadString().then(s => { t({ statusCode: e.response.statusCode, headers: e.response.headers, body: s }) }).catch(e => s(e)) }) } const p = a ? new Promise((e, t) => { d = setTimeout(() => (c.onTimeout(), t(`${u} URL: ${l.url} exceeds the timeout ${a} ms`)), a) }) : null; return (p ? Promise.race([p, f]).then(e => (clearTimeout(d), e)) : f).then(e => c.onResponse(e)) })(l, u))), u } function API(e = "untitled", t = !1) { const { isQX: s, isLoon: i, isSurge: n, isNode: o, isJSBox: r, isScriptable: u } = ENV(); return new class { constructor(e, t) { this.name = e, this.debug = t, this.http = HTTP(), this.env = ENV(), this.node = (() => { if (o) { return { fs: require("fs") } } return null })(), this.initCache(); Promise.prototype.delay = function (e) { return this.then(function (t) { return ((e, t) => new Promise(function (s) { setTimeout(s.bind(null, t), e) }))(e, t) }) } } initCache() { if (s && (this.cache = JSON.parse($prefs.valueForKey(this.name) || "{}")), (i || n) && (this.cache = JSON.parse($persistentStore.read(this.name) || "{}")), o) { let e = "root.json"; this.node.fs.existsSync(e) || this.node.fs.writeFileSync(e, JSON.stringify({}), { flag: "wx" }, e => console.log(e)), this.root = {}, e = `${this.name}.json`, this.node.fs.existsSync(e) ? this.cache = JSON.parse(this.node.fs.readFileSync(`${this.name}.json`)) : (this.node.fs.writeFileSync(e, JSON.stringify({}), { flag: "wx" }, e => console.log(e)), this.cache = {}) } } persistCache() { const e = JSON.stringify(this.cache, null, 2); s && $prefs.setValueForKey(e, this.name), (i || n) && $persistentStore.write(e, this.name), o && (this.node.fs.writeFileSync(`${this.name}.json`, e, { flag: "w" }, e => console.log(e)), this.node.fs.writeFileSync("root.json", JSON.stringify(this.root, null, 2), { flag: "w" }, e => console.log(e))) } write(e, t) { if (this.log(`SET ${t}`), -1 !== t.indexOf("#")) { if (t = t.substr(1), n || i) return $persistentStore.write(e, t); if (s) return $prefs.setValueForKey(e, t); o && (this.root[t] = e) } else this.cache[t] = e; this.persistCache() } read(e) { return this.log(`READ ${e}`), -1 === e.indexOf("#") ? this.cache[e] : (e = e.substr(1), n || i ? $persistentStore.read(e) : s ? $prefs.valueForKey(e) : o ? this.root[e] : void 0) } delete(e) { if (this.log(`DELETE ${e}`), -1 !== e.indexOf("#")) { if (e = e.substr(1), n || i) return $persistentStore.write(null, e); if (s) return $prefs.removeValueForKey(e); o && delete this.root[e] } else delete this.cache[e]; this.persistCache() } notify(e, t = "", l = "", h = {}) { const a = h["open-url"], c = h["media-url"]; if (s && $notify(e, t, l, h), n && $notification.post(e, t, l + `${c ? "\n多
/*****************************************************************************/
/*********************************** SHA256 *************************************/
var hexcase = 0; var b64pad = ""; function hex_sha256(s) { return rstr2hex(rstr_sha256(str2rstr_utf8(s))) } function b64_sha256(s) { return rstr2b64(rstr_sha256(str2rstr_utf8(s))) } function any_sha256(s, e) { return rstr2any(rstr_sha256(str2rstr_utf8(s)), e) } function hex_hmac_sha256(k, d) { return rstr2hex(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))) } function b64_hmac_sha256(k, d) { return rstr2b64(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))) } function any_hmac_sha256(k, d, e) { return rstr2any(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d)), e) } function sha256_vm_test() { return hex_sha256("abc").toLowerCase() == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" } function rstr_sha256(s) { return binb2rstr(binb_sha256(rstr2binb(s), s.length * 8)) } function rstr_hmac_sha256(key, data) { var bkey = rstr2binb(key); if (bkey.length > 16) bkey = binb_sha256(bkey, key.length * 8); var ipad = Array(16), opad = Array(16); for (var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C } var hash = binb_sha256(ipad.concat(rstr2binb(data)), 512 + data.length * 8); return binb2rstr(binb_sha256(opad.concat(hash), 512 + 256)) } function rstr2hex(input) { try { hexcase } catch (e) { hexcase = 0 } var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var output = ""; var x; for (var i = 0; i < input.length; i++) { x = input.charCodeAt(i); output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F) } return output } function rstr2b64(input) { try { b64pad } catch (e) { b64pad = '' } var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var output = ""; var len = input.length; for (var i = 0; i < len; i += 3) { var triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i + 2) : 0); for (var j = 0; j < 4; j++) { if (i * 8 + j * 6 > input.length * 8) output += b64pad; else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F) } } return output } function rstr2any(input, encoding) { var divisor = encoding.length; var remainders = Array(); var i, q, x, quotient; var dividend = Array(Math.ceil(input.length / 2)); for (i = 0; i < dividend.length; i++) { dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1) } while (dividend.length > 0) { quotient = Array(); x = 0; for (i = 0; i < dividend.length; i++) { x = (x << 16) + dividend[i]; q = Math.floor(x / divisor); x -= q * divisor; if (quotient.length > 0 || q > 0) quotient[quotient.length] = q } remainders[remainders.length] = x; dividend = quotient } var output = ""; for (i = remainders.length - 1; i >= 0; i--)output += encoding.charAt(remainders[i]); var full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2))); for (i = output.length; i < full_length; i++)output = encoding[0] + output; return output } function str2rstr_utf8(input) { var output = ""; var i = -1; var x, y; while (++i < input.length) { x = input.charCodeAt(i); y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); i++ } if (x <= 0x7F) output += String.fromCharCode(x); else if (x <= 0x7FF) output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F), 0x80 | (x & 0x3F)); else if (x <= 0xFFFF) output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F)); else if (x <= 0x1FFFFF) output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F)) } return output } function str2rstr_utf16le(input) { var output = ""; for (var i = 0; i < input.length; i++)output += String.fromCharCode(input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF); return output } function str2rstr_utf16be(input) { var output = ""; for (var i = 0; i < input.length; i++)output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF); return output } function rstr2binb(inpu
/*********************************** SHA256 *************************************/