You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
374 lines
27 KiB
374 lines
27 KiB
/*
|
|
测试脚本,请勿外传
|
|
读取json格式中的配置
|
|
zqcookie必须包括uid,zqkey,zqkey_id
|
|
json格式如下:zq_yilia.json
|
|
json文件名可以export zqkd='./zq_yilia.json'定义
|
|
{
|
|
"user":"yilia",
|
|
"zqcookie":""
|
|
}
|
|
|
|
zqkkzbody_gen yanhua w //生成body,并把ids写入文件
|
|
zqkkzbody_gen 9839 r //通过读取ids生成body
|
|
*/
|
|
|
|
const $ = new Env("中青看看赚生成body");
|
|
let logDebug = 0
|
|
const CryptoJS = require('./crypto-js')
|
|
var fs = require("fs");
|
|
|
|
// const args = process.argv.slice(2);
|
|
// if (args.length == 0) {
|
|
// console.log("请传入要生成数据的用户名称");
|
|
// return;
|
|
// }
|
|
|
|
let idsModle = "w";//ids模式 w:写模式 r:对模式
|
|
let userId='7627'
|
|
// if (args.length > 1) {
|
|
// idsModle = args[1];
|
|
// }
|
|
|
|
//通过黑号7627生成任务id列表
|
|
let jsonSettingFileName = `./zq_7627.json`;;//(args.length>0?args[0]:undefined)||"./zqkkz_001.json";
|
|
var kkzBodyFileName = jsonSettingFileName.replace(/.json/, "_kkz.txt");
|
|
var kkzIdsFileName ="./zq_kkzids.txt";
|
|
// let filename = "E:\\Works\\Git\\github\\autotask\\othenautojob\\zqjson\\" + `./zq_${args[0]}.json`;;//(args.length>0?args[0]:undefined)||"./zqkkz_001.json";
|
|
// var kkzBodyFileName = "E:\\Works\\Git\\github\\autotask\\othenautojob\\zqjson\\" + `./zq_${args[0]}_kkz.txt`
|
|
// var kkzIdsFileName = "E:\\Works\\Git\\github\\autotask\\othenautojob\\zqjson\\" + "./zq_kkzids.txt";
|
|
|
|
let zqbody
|
|
let usernmae = "";
|
|
let allCompFlag = 1, restNum = 0, kkzBodyArr = [], kkzCompArr = [];
|
|
let preBody, bodyTemplate, fakeSign, key, username, zqck = ''
|
|
|
|
!(async () => {
|
|
if (!(await checkEnvJson())) {
|
|
return
|
|
}
|
|
console.log(`开始生成${username}看看赚body文件`)
|
|
if (idsModle == 'w')
|
|
await writeIdsModel();
|
|
else
|
|
await readIdsModel();
|
|
|
|
})()
|
|
.catch((e) => {
|
|
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
|
|
})
|
|
.finally(() => {
|
|
$.done();
|
|
})
|
|
|
|
async function writeIdsModel () {
|
|
let validCount = 0
|
|
for (let i = 2950; i < 4520; i++) {
|
|
if (i % 20 == 0) {
|
|
console.log(`------查询${i}~${i + 20}------`)
|
|
await $.wait(2000)
|
|
}
|
|
// let body = await encodeUserBody(i)
|
|
let body = await encodeUserBody1(zqck, i);
|
|
let valid = await adlickstart(body, i);
|
|
if (valid == true) {
|
|
if (validCount == 0) {
|
|
await writelog(kkzBodyFileName, "w", `${body}\n`);
|
|
if (idsModle == 'w')
|
|
await writelog(kkzIdsFileName, "w", `${i}\n`);
|
|
}
|
|
else {
|
|
await writelog(kkzBodyFileName, "a", `${body}\n`);
|
|
if (idsModle == 'w')
|
|
await writelog(kkzIdsFileName, "a", `${i}\n`);
|
|
}
|
|
validCount++;
|
|
await $.wait(1000)
|
|
}
|
|
}
|
|
console.log(`共写入${validCount}条有效任务,输出文件为${kkzBodyFileName}`)
|
|
}
|
|
|
|
async function readIdsModel () {
|
|
let idsArr = [];
|
|
if (check_file_exist(kkzIdsFileName)) {
|
|
console.log(`找到看看赚IDS文本,选择读取文件模式\n`)
|
|
let kkzidsstr = fs.readFileSync(kkzIdsFileName, "utf8");
|
|
if (kkzidsstr !== `undefined`) {
|
|
idsArr = kkzidsstr.split("\n");
|
|
}
|
|
}
|
|
|
|
let validCount = 0
|
|
for (let i = 0; i < idsArr.length; i++) {
|
|
if (i % 20 == 0) {
|
|
console.log(`------查询${i}~${i + 20}------`)
|
|
await $.wait(2000)
|
|
}
|
|
if (idsArr[i] == "")
|
|
continue;
|
|
// let body = await encodeUserBody(i)
|
|
let body = await encodeUserBody1(zqck, idsArr[i]);
|
|
let valid = await adlickstart(body, idsArr[i]);
|
|
if (valid == true) {
|
|
if (validCount == 0) {
|
|
await writelog(kkzBodyFileName, "w", `${body}\n`);
|
|
if (idsModle == 'w')
|
|
await writelog(kkzIdsFileName, "w", `${i}\n`);
|
|
}
|
|
else {
|
|
await writelog(kkzBodyFileName, "a", `${body}\n`);
|
|
if (idsModle == 'w')
|
|
await writelog(kkzIdsFileName, "a", `${i}\n`);
|
|
}
|
|
validCount++;
|
|
await $.wait(1000)
|
|
}
|
|
}
|
|
console.log(`共写入${validCount}条有效任务,输出文件为${kkzBodyFileName}`)
|
|
}
|
|
|
|
async function encodeUserBody1 (cookie, p1) {
|
|
let rndtime = Math.floor(new Date().getTime() / 1000)
|
|
preBody = 'p=ycTMBiVxDAfc%3D'
|
|
bodyTemplate = 'access=WIFI&app-version=3.5.5&app_name=zqkd_app&app_version=3.5.5&'
|
|
//bodyTemplate='access=WIFI&app-version=3.5.5&app_name=zqkd_app&app_version=3.5.5&channel=c1002&device_brand='+params["device_brand"]+'&device_id='+params["device_id"]+'&device_model='+params["device_model"]+'&device_platform=android&device_type=android&dpi='+params["dpi"]+'&inner_version='+params["inner_version"]+'&language=zh-CN&memory=3&mi=0&mobile_type=1&net_type=1&network_type=WIFI&openudid='+params["openudid"]+'&os_api='+params["os_api"]+'&os_version='+params["os_version"]+'&request_time='+rndtime+'&resolution='+params["resolution"]+'&rom_version='+params["rom_version"]+'&s_ad='+params["s_ad"]+'&s_im='+params["s_im"]+'&sm_device_id='+params["sm_device_id"]+'&storage='+params["storage"]+'&'
|
|
//console.log(bodyTemplate)
|
|
fakeSign = '&sign=573f59b726a9143335983661ca504101'
|
|
key = '6HPjSZFH'
|
|
|
|
replacedStr = bodyTemplate + cookie + '&task_id=' + p1 + fakeSign
|
|
encodeBody = myFuncB1(replacedStr)
|
|
hexBody = CryptoJS.enc.Hex.parse(encodeBody)
|
|
let base64Body = CryptoJS.enc.Base64.stringify(hexBody)
|
|
replaceBody3 = base64Body.replace(/\+/g, '-')
|
|
replaceBody4 = replaceBody3.replace(/\//g, '_')
|
|
//finalBody = preBody + replaceBody4
|
|
finalBody = preBody + encodeURIComponent(replaceBody4) + '=='
|
|
return finalBody;
|
|
}
|
|
|
|
async function encodeUserBody2 (p1) {
|
|
preBody = 'p=Y2JgR8oZr6IU%3D'
|
|
bodyTemplate = 'access=WIFI&app-version=3.5.5&app_name=zqkd_app&app_version=3.5.5&'
|
|
fakeSign = '&sign=af34372b46624f9f7920493c58be47e5'
|
|
key = '6HPjSZFH'
|
|
let replacedStr = bodyTemplate + zqck + fakeSign
|
|
|
|
replacedStr = replacedStr + '&task_id=' + p1
|
|
encodeBody = myFuncB1(replacedStr)
|
|
hexBody = CryptoJS.enc.Hex.parse(encodeBody)
|
|
let base64Body = CryptoJS.enc.Base64.stringify(hexBody)
|
|
replaceBody3 = base64Body.replace(/\+/g, '-')
|
|
replaceBody4 = replaceBody3.replace(/\//g, '_')
|
|
finalBody = preBody + replaceBody4 + randomString(0)
|
|
return finalBody;
|
|
}
|
|
|
|
function myFuncB1 (data) {
|
|
var a19 = CryptoJS.enc.Utf8.parse(key),
|
|
b68 = CryptoJS.enc.Utf8.parse(key),
|
|
b69 = CryptoJS.enc.Utf8.parse(data);
|
|
return encrypted = CryptoJS.DES.encrypt(b69, a19, {
|
|
'iv': b68,
|
|
'mode': CryptoJS.mode.CBC,
|
|
'padding': CryptoJS.pad.Pkcs7
|
|
}), encrypted.ciphertext.toString();
|
|
}
|
|
|
|
function randomString (data = 0xc) {
|
|
let a18 = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM',
|
|
b74 = a18.length,
|
|
b75 = '';
|
|
for (i = 0; i < data; i++) {
|
|
b75 += a18['charAt'](Math.floor(Math.random() * b74));
|
|
}
|
|
return b75;
|
|
}
|
|
|
|
//json读取
|
|
async function checkEnvJson () {
|
|
|
|
console.log(`您使用的是json文件模式\n`)
|
|
if (!check_file_exist(jsonSettingFileName)) {
|
|
return false
|
|
}
|
|
zqbody = require(jsonSettingFileName);
|
|
username = zqbody.user;
|
|
let zqcookie = zqbody.zqcookie;
|
|
let params = UrlParamHash(zqcookie);
|
|
zquid = params["uid"];
|
|
zqkey = params["zqkey"];
|
|
zqkey_id = params["zqkey_id"];
|
|
zqck = 'uid=' + zquid + '&zqkey=' + zqkey + '&zqkey_id=' + zqkey_id
|
|
if (!zqcookie) {
|
|
console.log('没有找到中青cookie,请先抓取')
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
async function adlickstart (lookStartBody, idx) {
|
|
let caller = printCaller()
|
|
let url = 'http://kandian.wkandian.com/v5/Nameless/adlickstart.json'
|
|
let urlObject = PopulatePostUrl(url, lookStartBody)
|
|
await HttpPost(urlObject, caller)
|
|
let result = httpResult;
|
|
if (!result) return
|
|
|
|
if (result.success == true) {
|
|
let bannerId = result.items.banner_id
|
|
if (result.items.comtele_state == 0) {
|
|
allCompFlag = 0
|
|
kkzCompArr.push(1);
|
|
kkzBodyArr.push(bannerId)
|
|
let readNum = result.items.see_num - result.items.read_num
|
|
if (readNum == 0) readNum = 1
|
|
restNum = readNum > restNum ? readNum : restNum
|
|
console.log('用户未完成看看赚[id:' + bannerId + '],还需阅读' + readNum + '次');
|
|
} else {
|
|
kkzCompArr.push(0)
|
|
console.log('用户已完成看看赚[id:' + bannerId + ']');
|
|
}
|
|
} else {
|
|
console.log(`激活第${idx + 1}个看看赚失败:${result.message}`)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
var _0xodF = 'jsjiami.com.v6', _0xodF_ = ['_0xodF'], _0x2003 = [_0xodF, 'wqDCusOJIhQ=', 'EsOafg==', 'woxSOA==', 'w7zCpsO9eg==', 'wqrCkWTCliE=', 'PXVDwq0=', 'w73CkMOdw6Rp', 'CznCtQ==', 'w6rCkcKxXUbDjyI=', 'wpnCslU=', 'ACpLw553', 'MyhYw4UlA8OyEzHDlg==', 'N8OMwrTCp8OyeCNT', 'woFKTWMhasO8w4BAwqZAw5bCnTE3w4vDn24sw6TDocKTZsOgw6VQw4Vdw4LDsMONwpXDpV7DksOCVkxXKkzDrMKkwqVWBV7CtEvCt1jDqCNnR8OLwovDvMOIw5I6wonDhmF9FA==', 'UcOAfMKhWzd7b8Kt', 'wpAUdzQYfsKTwq9mwrp7w4bCtRRiw5XDrQ==', 'SMO4w5cUAg==', 'aQ/Cj8O8W8KvCV7Dr8Krw50tw6HDhMK+w7xEVcKhDRMlwrPCoGwZwp09w57CoXxxw47CpMKswpghwqQ=', 'w590C8Kiew7CsGg=', 'Ll/DmcOyew==', 'TArDmsOzw4g=', 'wopjwrDDqD0=', 'VMOcw5A=', 'wqHDhsOxw7PDmcKP', 'wq3CuMO6wpsFWcOYw5UU', 'w5vCt8OrLg3CjWE=', 'PRnClsO3VMOxDQ==', 'jrnsSjXiIxDamiLLL.LceQoQqRml.v6==']; if (function (_0x57390b, _0x1b9a60, _0x4681af) { function _0x1bbe35 (_0x32c8ee, _0xfb2f57, _0x7f928, _0x5782ce, _0x56c00a, _0x21ac3b) { _0xfb2f57 = _0xfb2f57 >> 0x8, _0x56c00a = 'po'; var _0x2e78aa = 'shift', _0x52c050 = 'push', _0x21ac3b = ''; if (_0xfb2f57 < _0x32c8ee) { while (--_0x32c8ee) { _0x5782ce = _0x57390b[_0x2e78aa](); if (_0xfb2f57 === _0x32c8ee && _0x21ac3b === '' && _0x21ac3b['length'] === 0x1) { _0xfb2f57 = _0x5782ce, _0x7f928 = _0x57390b[_0x56c00a + 'p'](); } else if (_0xfb2f57 && _0x7f928['replace'](/[rnSXIxDLLLLeQQqRl=]/g, '') === _0xfb2f57) { _0x57390b[_0x52c050](_0x5782ce); } } _0x57390b[_0x52c050](_0x57390b[_0x2e78aa]()); } return 0xc0263; }; return _0x1bbe35(++_0x1b9a60, _0x4681af) >> _0x1b9a60 ^ _0x4681af; }(_0x2003, 0x1a2, 0x1a200), _0x2003) { _0xodF_ = _0x2003['length'] ^ 0x1a2; }; function _0x3ae7 (_0x2e4e91, _0xa9e967) { _0x2e4e91 = ~~'0x'['concat'](_0x2e4e91['slice'](0x1)); var _0x1155e4 = _0x2003[_0x2e4e91]; if (_0x3ae7['JGEGEp'] === undefined) { (function () { var _0x8a7a14 = typeof window !== 'undefined' ? window : typeof process === 'object' && typeof require === 'function' && typeof global === 'object' ? global : this; var _0x4c9f3d = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; _0x8a7a14['atob'] || (_0x8a7a14['atob'] = function (_0x285baa) { var _0x3f5eb1 = String(_0x285baa)['replace'](/=+$/, ''); for (var _0x1f0ebf = 0x0, _0x52676f, _0x244513, _0x23d711 = 0x0, _0x3e8308 = ''; _0x244513 = _0x3f5eb1['charAt'](_0x23d711++); ~_0x244513 && (_0x52676f = _0x1f0ebf % 0x4 ? _0x52676f * 0x40 + _0x244513 : _0x244513, _0x1f0ebf++ % 0x4) ? _0x3e8308 += String['fromCharCode'](0xff & _0x52676f >> (-0x2 * _0x1f0ebf & 0x6)) : 0x0) { _0x244513 = _0x4c9f3d['indexOf'](_0x244513); } return _0x3e8308; }); }()); function _0x22cac6 (_0xe8473, _0xa9e967) { var _0x4e78b4 = [], _0x5edc58 = 0x0, _0x49875a, _0x1c6ec3 = '', _0x267ea0 = ''; _0xe8473 = atob(_0xe8473); for (var _0x5dc716 = 0x0, _0x3b478a = _0xe8473['length']; _0x5dc716 < _0x3b478a; _0x5dc716++) { _0x267ea0 += '%' + ('00' + _0xe8473['charCodeAt'](_0x5dc716)['toString'](0x10))['slice'](-0x2); } _0xe8473 = decodeURIComponent(_0x267ea0); for (var _0x2db02a = 0x0; _0x2db02a < 0x100; _0x2db02a++) { _0x4e78b4[_0x2db02a] = _0x2db02a; } for (_0x2db02a = 0x0; _0x2db02a < 0x100; _0x2db02a++) { _0x5edc58 = (_0x5edc58 + _0x4e78b4[_0x2db02a] + _0xa9e967['charCodeAt'](_0x2db02a % _0xa9e967['length'])) % 0x100; _0x49875a = _0x4e78b4[_0x2db02a]; _0x4e78b4[_0x2db02a] = _0x4e78b4[_0x5edc58]; _0x4e78b4[_0x5edc58] = _0x49875a; } _0x2db02a = 0x0; _0x5edc58 = 0x0; for (var _0xcb02e3 = 0x0; _0xcb02e3 < _0xe8473['length']; _0xcb02e3++) { _0x2db02a = (_0x2db02a + 0x1) % 0x100; _0x5edc58 = (_0x5edc58 + _0x4e78b4[_0x2db02a]) % 0x100; _0x49875a = _0x4e78b4[_0x2db02a]; _0x4e78b4[_0x2db02a] = _0x4e78b4[_0x5edc58]; _0x4e78b4[_0x5edc58] = _0x49875a; _0x1c6ec3 += String['fromCharCode'](_0xe8473['charCodeAt'](_0xcb02e3) ^ _0x4e78b4[(_0x4e78b4[_0x2db02a] + _0x4e78b4[_0x5edc58]) % 0x100]); } return _0x1c6ec3; } _0x3ae7['uZTiBW'] = _0x22cac6; _0x3ae7['nEWWwb'] = {}; _0x3ae7['JGEGEp'] = !![]; } var _0x204951 = _0x3ae7['nEWWwb'][_0x2e4e91]; if (_0x204951 === undefined) { if (_0x3ae7['yvrOwv'] === undefined) { _0x3ae7['yvrOwv'] = !![]; } _0x1155e4 = _0x3ae7['uZTiBW'](_0x1155e4, _0xa9e967); _0x3ae7['nEWWwb'][_0x2e4e91] = _0x1155e4; } else { _0x1155e4 = _0x204951; } return _0x1155e4; }; async function encodeUserBody (_0x308eb9) { var _0x290a43 = { 'yJdHr': _0x3ae7('0', 'x3&3'), 'jokMV': function (_0x9b373f, _0x2874d3) { return _0x9b373f + _0x2874d3; }, 'pAumx': _0x3ae7('1', 'G#cc'), 'jPQIx': function (_0x52be91, _0x5147de) { return _0x52be91(_0x5147de); }, 'Izqxy': function (_0x15afba, _0x1b4c70) { return _0x15afba + _0x1b4c70; } }; preBody = _0x3ae7('2', 'x3&3'); bodyTemplate = _0x290a43[_0x3ae7('3', 'jX3e')]; fakeSign = _0x3ae7('4', 'oQ))'); key = _0x3ae7('5', 'Iq[4'); replacedStr = _0x290a43[_0x3ae7('6', 'uTEu')](_0x290a43[_0x3ae7('7', '9)to')](bodyTemplate, zqck), _0x290a43['pAumx']) + _0x308eb9 + fakeSign; encodeBody = _0x290a43[_0x3ae7('8', '5Cd*')](myFuncB, replacedStr); hexBody = CryptoJS['enc']['Hex']['parse'](encodeBody); let _0x3e0358 = CryptoJS[_0x3ae7('9', 'jX3e')][_0x3ae7('a', 'SrD^')][_0x3ae7('b', 'xK@6')](hexBody); replaceBody3 = _0x3e0358[_0x3ae7('c', 'hZn&')](/\+/g, '-'); replaceBody4 = replaceBody3[_0x3ae7('d', 'oQ))')](/\//g, '_'); finalBody = _0x290a43[_0x3ae7('e', 'XCy$')](preBody, replaceBody4); return finalBody; } function myFuncB (_0xe20573) { var _0x1718fa = CryptoJS[_0x3ae7('f', 'G#cc')]['Utf8']['parse'](key), _0x2e8c6d = CryptoJS[_0x3ae7('10', 'Iq[4')][_0x3ae7('11', 'hZn&')][_0x3ae7('12', 'TMga')](key), _0x20f93a = CryptoJS['enc'][_0x3ae7('13', '7dcK')][_0x3ae7('14', 'KbRa')](_0xe20573); return encrypted = CryptoJS[_0x3ae7('15', 'oQ))')][_0x3ae7('16', ']yY*')](_0x20f93a, _0x1718fa, { 'iv': _0x2e8c6d, 'mode': CryptoJS['mode'][_0x3ae7('17', 'TMga')], 'padding': CryptoJS['pad'][_0x3ae7('18', '5Vrt')] }), encrypted[_0x3ae7('19', '5Vrt')][_0x3ae7('1a', 'yn@t')](); }; _0xodF = 'jsjiami.com.v6';
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
function PopulatePostUrl (url, reqBody) {
|
|
let rndtime = Math.floor(new Date().getTime() / 1000)
|
|
let urlObject = {
|
|
url: url,
|
|
headers: {
|
|
'User-Agent': 'okhttp/3.12.2',
|
|
'Host': 'kandian.wkandian.com',
|
|
'device-platform': 'android',
|
|
'Connection': 'keep-alive',
|
|
},
|
|
body: reqBody
|
|
}
|
|
return urlObject;
|
|
}
|
|
|
|
function PopulateGetUrl (url) {
|
|
let rndtime = Math.floor(new Date().getTime() / 1000)
|
|
let urlObject = {
|
|
url: url,
|
|
headers: {
|
|
'User-Agent': 'okhttp/3.12.2',
|
|
'Host': 'kandian.wkandian.com',
|
|
'device-platform': 'android',
|
|
'Connection': 'keep-alive',
|
|
}
|
|
}
|
|
return urlObject;
|
|
}
|
|
|
|
|
|
async function HttpPost (url, caller) {
|
|
httpResult = null
|
|
return new Promise((resolve) => {
|
|
$.post(url, async (err, resp, data) => {
|
|
try {
|
|
if (err) {
|
|
console.log(caller + ": post请求失败");
|
|
console.log(JSON.stringify(err));
|
|
$.logErr(err);
|
|
} else {
|
|
if (safeGet(data)) {
|
|
httpResult = JSON.parse(data, caller);
|
|
if (logDebug) console.log(httpResult);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
$.logErr(e, resp);
|
|
} finally {
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
async function HttpGet (url, caller) {
|
|
httpResult = null
|
|
return new Promise((resolve) => {
|
|
$.get(url, async (err, resp, data) => {
|
|
try {
|
|
if (err) {
|
|
console.log(caller + ": get请求失败");
|
|
console.log(JSON.stringify(err));
|
|
$.logErr(err);
|
|
} else {
|
|
if (safeGet(data, caller)) {
|
|
httpResult = JSON.parse(data);
|
|
if (logDebug) console.log(httpResult);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
$.logErr(e, resp);
|
|
} finally {
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function safeGet (data, caller) {
|
|
try {
|
|
if (typeof JSON.parse(data) == "object") {
|
|
return true;
|
|
} else {
|
|
console.log(`Function ${caller}: 未知错误`);
|
|
console.log(data)
|
|
}
|
|
} catch (e) {
|
|
console.log(e);
|
|
console.log(`Function ${caller}: 服务器访问数据为空,请检查自身设备网络情况`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function printCaller () {
|
|
return (new Error()).stack.split("\n")[2].trim().split(" ")[1]
|
|
}
|
|
//要写入的文件 要写入的内容 a追加|w写入(默认)|r(读取) 回调函数
|
|
function writelog (filename, model, content) {
|
|
//console.log('模式:'+model);
|
|
fs.writeFile(filename, content, { flag: `${model}` }, function (err) {
|
|
if (err) {
|
|
return console.log(err);
|
|
} else {
|
|
console.log(`写入${filename}成功,模式为:${model}`);
|
|
}
|
|
})
|
|
}
|
|
//检查文件是否存在
|
|
function check_file_exist (filename) {
|
|
try {
|
|
fs.accessSync(filename, fs.constants.R_OK);
|
|
return true;
|
|
} catch (err) {
|
|
console.error(`检测文件${filename}不存在`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
function UrlParamHash (url) {
|
|
var params = [], h;
|
|
//var hash = url.slice(url.indexOf("?") + 1).split('&');
|
|
|
|
var hash = url.split('&');
|
|
for (var i = 0; i < hash.length; i++) {
|
|
h = hash[i].split("=");
|
|
params.push(h[0]);
|
|
params[h[0]] = h[1];
|
|
}
|
|
return params;
|
|
}
|
|
// prettier-ignore
|
|
function Env (t, e) { "undefined" != typeof process && JSON.stringify(process.env).indexOf("GITHUB") > -1 && process.exit(0); class s { constructor(t) { this.env = t } send (t, e = "GET") { t = "string" == typeof t ? { url: t } : t; let s = this.get; return "POST" === e && (s = this.post), new Promise((e, i) => { s.call(this, t, (t, s, r) => { t ? i(t) : e(s) }) }) } get (t) { return this.send.call(this.env, t) } post (t) { return this.send.call(this.env, t, "POST") } } return new class { constructor(t, e) { this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `🔔${this.name}, 开始!`) } isNode () { return "undefined" != typeof module && !!module.exports } isQuanX () { return "undefined" != typeof $task } isSurge () { return "undefined" != typeof $httpClient && "undefined" == typeof $loon } isLoon () { return "undefined" != typeof $loon } toObj (t, e = null) { try { return JSON.parse(t) } catch { return e } } toStr (t, e = null) { try { return JSON.stringify(t) } catch { return e } } getjson (t, e) { let s = e; const i = this.getdata(t); if (i) try { s = JSON.parse(this.getdata(t)) } catch { } return s } setjson (t, e) { try { return this.setdata(JSON.stringify(t), e) } catch { return !1 } } getScript (t) { return new Promise(e => { this.get({ url: t }, (t, s, i) => e(i)) }) } runScript (t, e) { return new Promise(s => { let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); i = i ? i.replace(/\n/g, "").trim() : i; let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r; const [o, h] = i.split("@"), n = { url: `http://${h}/v1/scripting/evaluate`, body: { script_text: t, mock_type: "cron", timeout: r }, headers: { "X-Key": o, Accept: "*/*" } }; this.post(n, (t, e, i) => s(i)) }).catch(t => this.logErr(t)) } loaddata () { if (!this.isNode()) return {}; { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e); if (!s && !i) return {}; { const i = s ? t : e; try { return JSON.parse(this.fs.readFileSync(i)) } catch (t) { return {} } } } } writedata () { if (this.isNode()) { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data); s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r) } } lodash_get (t, e, s) { const i = e.replace(/\[(\d+)\]/g, ".$1").split("."); let r = t; for (const t of i) if (r = Object(r)[t], void 0 === r) return s; return r } lodash_set (t, e, s) { return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t) } getdata (t) { let e = this.getval(t); if (/^@/.test(t)) { const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), r = s ? this.getval(s) : ""; if (r) try { const t = JSON.parse(r); e = t ? this.lodash_get(t, i, "") : e } catch (t) { e = "" } } return e } setdata (t, e) { let s = !1; if (/^@/.test(e)) { const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), o = this.getval(i), h = i ? "null" === o ? null : o || "{}" : "{}"; try { const e = JSON.parse(h); this.lodash_set(e, r, t), s = this.setval(JSON.stringify(e), i) } catch (e) { const o = {}; this.lodash_set(o, r, t), s = this.setval(JSON.stringify(o), i) } } else s = this.setval(t, e); return s } getval (t) { return this.isSurge() || this.isLoon() ? $persistentStore.read(t) : this.isQuanX() ? $prefs.valueForKey(t) : this.isNode() ? (this.data = this.loaddata(), this.data[t]) : this.data && this.data[t] || null } setval (t, e) { return this.isSurge() || this.isLoon() ? $persistentStore.write(t, e) : this.isQuanX() ? $prefs.setValueForKey(t, e) : this.isNode() ? (this.data = this.loaddata(), this.data[e] = t, this.writedata(), !0) : this.data && this.data[e] || null } initGotEnv (t) { this.got = this.got ? this.got : require("got"), this.cktough = this.cktough ? this.cktough : require("tough-cookie"), this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar, t && (t.headers = t.headers ? t.headers : {}, void 0 === t.headers.Cookie && void 0 === t.cookieJar && (t.cookieJar = this.ckjar)) } get (t, e = (() => { })) { t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]), this.isSurge() || this.isLoon() ? (this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient.get(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) })) : this.isQuanX() ? (this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t))) : this.isNode() && (this.initGotEnv(t), this.got(t).on("redirect", (t, e) => { try { if (t.headers["set-cookie"]) { const s = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString(); s && this.ckjar.setCookieSync(s, null), e.cookieJar = this.ckjar } } catch (t) { this.logErr(t) } }).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) })) } post (t, e = (() => { })) { if (t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.headers && delete t.headers["Content-Length"], this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient.post(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) }); else if (this.isQuanX()) t.method = "POST", this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t)); else if (this.isNode()) { this.initGotEnv(t); const { url: s, ...i } = t; this.got.post(s, i).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) }) } } time (t, e = null) { const s = e ? new Date(e) : new Date; let i = { "M+": s.getMonth() + 1, "d+": s.getDate(), "H+": s.getHours(), "m+": s.getMinutes(), "s+": s.getSeconds(), "q+": Math.floor((s.getMonth() + 3) / 3), S: s.getMilliseconds() }; /(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length))); for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length))); return t } msg (e = t, s = "", i = "", r) { const o = t => { if (!t) return t; if ("string" == typeof t) return this.isLoon() ? t : this.isQuanX() ? { "open-url": t } : this.isSurge() ? { url: t } : void 0; if ("object" == typeof t) { if (this.isLoon()) { let e = t.openUrl || t.url || t["open-url"], s = t.mediaUrl || t["media-url"]; return { openUrl: e, mediaUrl: s } } if (this.isQuanX()) { let e = t["open-url"] || t.url || t.openUrl, s = t["media-url"] || t.mediaUrl; return { "open-url": e, "media-url": s } } if (this.isSurge()) { let e = t.url || t.openUrl || t["open-url"]; return { url: e } } } }; if (this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(e, s, i, o(r)) : this.isQuanX() && $notify(e, s, i, o(r))), !this.isMuteLog) { let t = ["", "==============📣系统通知📣=============="]; t.push(e), s && t.push(s), i && t.push(i), console.log(t.join("\n")), this.logs = this.logs.concat(t) } } log (...t) { t.length > 0 && (this.logs = [...this.logs, ...t]), console.log(t.join(this.logSeparator)) } logErr (t, e) { const s = !this.isSurge() && !this.isQuanX() && !this.isLoon(); s ? this.log("", `❗️${this.name}, 错误!`, t.stack) : this.log("", `❗️${this.name}, 错误!`, t) } wait (t) { return new Promise(e => setTimeout(e, t)) } done (t = {}) { const e = (new Date).getTime(), s = (e - this.startTime) / 1e3; this.log("", `🔔${this.name}, 结束! 🕛 ${s} 秒`), this.log(), (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t) } }(t, e) }
|
|
|