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.
286 lines
22 KiB
286 lines
22 KiB
/*
|
|
测试脚本,禁止外传
|
|
多用户版本
|
|
config里面
|
|
export zqkdCookie='xxx@xxx'
|
|
ck包含uid,zqkey,zqkey_id三个变量就行
|
|
*/
|
|
|
|
const $ = new Env("zq奖励自动领取");
|
|
let logDebug = 0
|
|
const CryptoJS = require('./crypto-js')
|
|
var fs = require("fs");
|
|
let tsxx=''
|
|
|
|
let filename = `./${process.env.zqjson || "./zq_yilia"}.json`;
|
|
|
|
let userCookie = ($.isNode() ? process.env.zqkdCookie : $.getdata('zqkdCookie')) || '';
|
|
let userCookieArr = []
|
|
|
|
let zqbody
|
|
let usernmae="",zqcookie="";
|
|
let preBody,bodyTemplate,fakeSign,key,zqck=''
|
|
let params
|
|
|
|
let useProxy = undefined;
|
|
if (process.env.zqjson == "zq_9839") {
|
|
console.log("使用代理服务");
|
|
useProxy = process.env.zqjson;
|
|
}
|
|
|
|
let reward=[
|
|
"first_share_article",
|
|
"watch_video_reward",
|
|
"new_fresh_five_video_reward",
|
|
"watch_article_reward",
|
|
"task_kankan_reward",
|
|
"box_three",
|
|
"box_six",
|
|
"box_nine",
|
|
"read_article_video_reward_five",
|
|
"beread_reward_three"
|
|
]
|
|
!(async () => {
|
|
|
|
if(!(await checkEnvJson())) {
|
|
return
|
|
}
|
|
console.log(`开始领取奖励`)
|
|
for (let k=0;k<reward.length;k++){
|
|
for (let i=0;i<userCookieArr.length;i++){
|
|
console.log(`用户${i+1}领取奖励:${reward[k]}`)
|
|
cookie=userCookieArr[i]
|
|
let body = await encodeUserBody(cookie,reward[k])
|
|
//console.log("\t\t\""+body+"\",")
|
|
await toGetReward(body,k,reward[k]);
|
|
await $.wait(1000)
|
|
}
|
|
console.log(`${reward[k]}领取完毕,等待领取下一个奖励`)
|
|
await $.wait(2000)
|
|
}
|
|
console.log(`complete`)
|
|
|
|
})()
|
|
.catch((e) => {
|
|
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
|
|
})
|
|
.finally(() => {
|
|
$.done();
|
|
})
|
|
|
|
//json读取
|
|
async function checkEnvJson () {
|
|
|
|
console.log(`您使用的是json文件模式\n`)
|
|
if (!check_file_exist(filename)) {
|
|
return false
|
|
}
|
|
zqbody = require(filename);
|
|
username = zqbody.user;
|
|
zqcookie = zqbody.zqcookie;
|
|
userCookieArr.push(replaceCookie(zqcookie))
|
|
return true
|
|
}
|
|
|
|
async function checkEnv() {
|
|
if(userCookie) {
|
|
if(userCookie.indexOf('@') > -1) {
|
|
let userCookies = userCookie.split('@')
|
|
for(let i=0; i<userCookies.length; i++) {
|
|
userCookieArr.push(replaceCookie(userCookies[i]))
|
|
}
|
|
} else {
|
|
userCookieArr.push(replaceCookie(userCookie))
|
|
}
|
|
} else {
|
|
console.log('未找到userCookie')
|
|
return false
|
|
}
|
|
if(userCookieArr.length == 0) {
|
|
console.log('未找到有效的userCookie')
|
|
return false
|
|
}
|
|
|
|
console.log(`共找到${userCookieArr.length}个用户`)
|
|
return true
|
|
}
|
|
function replaceCookie(userCookieItem) {
|
|
let replaceItem = ''
|
|
let zqkey = ''
|
|
let zqkey_id = ''
|
|
if(userCookieItem.indexOf('zqkey=') > -1) {
|
|
zqkey = userCookieItem.match(/zqkey=([\w-]+)/)[1]
|
|
} else if (userCookieItem.indexOf('cookie=') > -1) {
|
|
zqkey = userCookieItem.match(/cookie=([\w-]+)/)[1]
|
|
}
|
|
if(userCookieItem.indexOf('zqkey_id=') > -1) {
|
|
zqkey_id = userCookieItem.match(/zqkey_id=([\w-]+)/)[1]
|
|
} else if (userCookieItem.indexOf('cookie_id=') > -1) {
|
|
zqkey_id = userCookieItem.match(/cookie_id=([\w-]+)/)[1]
|
|
}
|
|
if(userCookieItem.indexOf('uid=') > -1) {
|
|
uid = userCookieItem.match(/uid=([\w-]+)/)[1]
|
|
}
|
|
|
|
replaceItem = `uid=${uid}&version_code=63&zqkey=${zqkey}&zqkey_id=${zqkey_id}`
|
|
|
|
return replaceItem
|
|
}
|
|
|
|
//领取奖励
|
|
async function toGetReward(rewardBody,idx,showstr) {
|
|
let caller = printCaller()
|
|
let url = 'https://kandian.wkandian.com/v5/CommonReward/toGetReward.json'
|
|
let urlObject = PopulatePostUrl(url,rewardBody)
|
|
await HttpPost(urlObject,caller)
|
|
let result = httpResult;
|
|
if(!result) return
|
|
|
|
if (!showstr) showstr='任务';
|
|
if(result.success == true) {
|
|
if(result.items && result.items.score) {
|
|
if(result.items.title && result.items.title.indexOf('签到成功') > -1) showstr = '签到'
|
|
console.log(`领取第${idx+1}个【${showstr}奖励】成功,获得${result.items.score}金币`)
|
|
tsxx += `领取第${idx+1}个【${showstr}奖励】成功,获得${result.items.score}金币\n`
|
|
}
|
|
} else {
|
|
console.log(`领取第${idx+1}个奖励失败:${JSON.stringify(result)}`)
|
|
}
|
|
}
|
|
|
|
var _0xod5='jsjiami.com.v6',_0xod5_=['_0xod5'],_0x4b8e=[_0xod5,'YBTCh23CocK8w7/DvsOcSsKtKG/DgWfCjxE=','wrZHTkjCiGzCiMKSFsKTwpzDs8KUWyh0w4Ytw7hpwoXCoSTCiinDtzDDm8OkAMOSTMKEw6o4TSVMJMOGwqlrf3hmw5tjUXTCkMONKD1lwq45SgDDgg1GNsOkCxsdwrLDgMKdw68Fwq5EwqPDl8K6QHtVOMOOw4t4KMKNw5jCm8K8w5EpAcKxwqIkwp89OMOZw4ZABDfDnMKeCMKWKlPDpkcTesKNEMKnIsKEw60SwrEAdnbCvjHCv8OFeiDCrMK0wrbCjsOyYsO4YMOEwr9KYCBKwpVEwqNiw5ccw4lpwooFG8OrAsK3D8KWw7cawq3CvifCnMK5CMOewpLCpHjCnQ/CtTsLc8K0QMK4aRDDqU/CqF0zHMOhanY+wqlqwo7CtjE5w4NSUw/DgcOMT8KIw4U5w64Lwo0iWcKoa8O9R8KnT8KSE8KNwrTDu8K1w6ZsRcK7w555O8K6P8OuwpQkwoFVVcKww7M0IMOmP0nCnMONw4sPw7Yuw7nCgMKsesO3M8KkwoTCkcOLw6DDu3HCrsOTwoBuwr93HMKXwosUfcOqwrfDogE4w7HDtSAMf8OrCWHClGZMw5sFQFfChsOeSMKTUsKyG8OvVsKWOXB8wqBTw5JDwovDhSbDi0Bgw4fDqcO1wqfCnsKofsOKwrDDusKA','bMKbFCTCmsOgwoJiw7XDu0DDncOUwoPDtFcswrHCuHI5wprCi8OGMTBEa3jDn8K5wpLCsn3DuwrCjMKjwog8wqDDljzCvCUxSsOyw7bCnMKICMKZwoFhw5XCnRTDnDxUOxHDuA/DmMO5w7VGw4JtDVfCv8OCa8Oww4XCgy4RCTfDqUw2wr7ChMKjYMOIeV7DkVMsWmjCoyUNwqwQGcO+VgvCocKbwpLDr8KjaMORchgOw5FXw4wWw6vCjQxwXCbDj8KSKBjDsMKfw5AYGwNtAsKLwqFlwogJExvDtDbDv2ouwqVIwrjDisORw7XCgsOybcOUw6t6M8O0U8KQPiwowqnCrMOmNkPDpSY4wo3CgsK6HwvDvB7CqmFtZMOVwq0jTMOUw6FWAsKlw6okeABxG1wFwqnCtcKQHHPDmG7CrcKHwp/Ch8Ksw7MgMmzDqWABXcKrw5vDu8O9dzhLb8KxdMKUwpTCu8O+KwzCs8KzcMKbwoHConvCkVzDp8K1w7NZw6HDpG8ywqPCi1IbAWjDp8OQMXU=','Dw0wXcKJ','XVnCj0bCtA==','wqjDhh7CucK4','bMKPZWNw','wpzCtybCm1s=','E8OYPsKQw4AdH0Y=','ZMOFwqHCisOa','dD3DusKYw44=','dUfCnQ==','IsK/w7kDwpw=','wqIrw4U=','VsKLCGl/wr3CisKuBQ==','wp7DhTvCm8Kzw4jDnw==','wrILw4zCoHg=','HWA/w4bCux5zd8Kd','woVnLMObw5o=','GhEzW8KP','TXV7w5LDrxA1bsOVcA==','E2nClQ==','H8KdF28=','Vg7ClSHDtA==','DA88QMKCw7HCoQ==','wqjChCE=','w6kPNQ==','ZMKQcA==','UcOxWcKo','aGBrVMKX','QgnDsg==','OsKIAyTCkA==','yfjwsjiIaMmZi.Bkkcom.Av6ZBty=='];if(function(_0x47f5ac,_0xf0291,_0x4dd851){function _0x5b3ac9(_0xbc85c2,_0x48ca48,_0x2adda3,_0x5e1e48,_0x3127ae,_0x3a7dc9){_0x48ca48=_0x48ca48>>0x8,_0x3127ae='po';var _0x3d5231='shift',_0x49c81f='push',_0x3a7dc9='';if(_0x48ca48<_0xbc85c2){while(--_0xbc85c2){_0x5e1e48=_0x47f5ac[_0x3d5231]();if(_0x48ca48===_0xbc85c2&&_0x3a7dc9===''&&_0x3a7dc9['length']===0x1){_0x48ca48=_0x5e1e48,_0x2adda3=_0x47f5ac[_0x3127ae+'p']();}else if(_0x48ca48&&_0x2adda3['replace'](/[yfwIMZBkkAZBty=]/g,'')===_0x48ca48){_0x47f5ac[_0x49c81f](_0x5e1e48);}}_0x47f5ac[_0x49c81f](_0x47f5ac[_0x3d5231]());}return 0xc06c8;};return _0x5b3ac9(++_0xf0291,_0x4dd851)>>_0xf0291^_0x4dd851;}(_0x4b8e,0x1c0,0x1c000),_0x4b8e){_0xod5_=_0x4b8e['length']^0x1c0;};function _0x4619(_0x61a5c,_0x2a7856){_0x61a5c=~~'0x'['concat'](_0x61a5c['slice'](0x1));var _0x13988b=_0x4b8e[_0x61a5c];if(_0x4619['LcWLUz']===undefined){(function(){var _0x23ec42=typeof window!=='undefined'?window:typeof process==='object'&&typeof require==='function'&&typeof global==='object'?global:this;var _0x42b063='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';_0x23ec42['atob']||(_0x23ec42['atob']=function(_0x14037a){var _0x353ae8=String(_0x14037a)['replace'](/=+$/,'');for(var _0xa78538=0x0,_0x13a727,_0x5b4321,_0xc21eac=0x0,_0x5b99d4='';_0x5b4321=_0x353ae8['charAt'](_0xc21eac++);~_0x5b4321&&(_0x13a727=_0xa78538%0x4?_0x13a727*0x40+_0x5b4321:_0x5b4321,_0xa78538++%0x4)?_0x5b99d4+=String['fromCharCode'](0xff&_0x13a727>>(-0x2*_0xa78538&0x6)):0x0){_0x5b4321=_0x42b063['indexOf'](_0x5b4321);}return _0x5b99d4;});}());function _0x2612ef(_0x55fa4d,_0x2a7856){var _0x311d10=[],_0x1d2f71=0x0,_0x4d778a,_0x1c6967='',_0x27340f='';_0x55fa4d=atob(_0x55fa4d);for(var _0x508a9a=0x0,_0x25f5cc=_0x55fa4d['length'];_0x508a9a<_0x25f5cc;_0x508a9a++){_0x27340f+='%'+('00'+_0x55fa4d['charCodeAt'](_0x508a9a)['toString'](0x10))['slice'](-0x2);}_0x55fa4d=decodeURIComponent(_0x27340f);for(var _0x560b96=0x0;_0x560b96<0x100;_0x560b96++){_0x311d10[_0x560b96]=_0x560b96;}for(_0x560b96=0x0;_0x560b96<0x100;_0x560b96++){_0x1d2f71=(_0x1d2f71+_0x311d10[_0x560b96]+_0x2a7856['charCodeAt'](_0x560b96%_0x2a7856['length']))%0x100;_0x4d778a=_0x311d10[_0x560b96];_0x311d10[_0x560b96]=_0x311d10[_0x1d2f71];_0x311d10[_0x1d2f71]=_0x4d778a;}_0x560b96=0x0;_0x1d2f71=0x0;for(var _0x3ba2c5=0x0;_0x3ba2c5<_0x55fa4d['length'];_0x3ba2c5++){_0x560b96=(_0x560b96+0x1)%0x100;_0x1d2f71=(_0x1d2f71+_0x311d10[_0x560b96])%0x100;_0x4d778a=_0x311d10[_0x560b96];_0x311d10[_0x560b96]=_0x311d10[_0x1d2f71];_0x311d10[_0x1d2f71]=_0x4d778a;_0x1c6967+=String['fromCharCode'](_0x55fa4d['charCodeAt'](_0x3ba2c5)^_0x311d10[(_0x311d10[_0x560b96]+_0x311d10[_0x1d2f71])%0x100]);}return _0x1c6967;}_0x4619['NNHgsR']=_0x2612ef;_0x4619['uBYTQM']={};_0x4619['LcWLUz']=!![];}var _0x1f43b7=_0x4619['uBYTQM'][_0x61a5c];if(_0x1f43b7===undefined){if(_0x4619['XsMzlh']===undefined){_0x4619['XsMzlh']=!![];}_0x13988b=_0x4619['NNHgsR'](_0x13988b,_0x2a7856);_0x4619['uBYTQM'][_0x61a5c]=_0x13988b;}else{_0x13988b=_0x1f43b7;}return _0x13988b;};async function encodeUserBody(_0xe0317d,_0x36faba){var _0xa0e181={'mrQau':_0x4619('0','G*vg'),'OlJCp':function(_0x37784d,_0x34f447){return _0x37784d+_0x34f447;},'MpqHA':function(_0x54fdc4,_0x3b6498){return _0x54fdc4+_0x3b6498;},'DfUNj':_0x4619('1','oP9p'),'mqvvQ':_0x4619('2','9fVn'),'wqDwZ':'&sign=01e8102fab93e458542c5155a3b8b734','fmDas':function(_0x336ed2,_0x25176f){return _0x336ed2+_0x25176f;},'SZkZw':function(_0x475b97,_0x5bc32b){return _0x475b97(_0x5bc32b);},'uNjvr':function(_0x4e8d1a,_0x17c036){return _0x4e8d1a+_0x17c036;}};let _0xe7fd91=Math[_0x4619('3','eJ9#')](new Date()['getTime']()/0x3e8);preBody=_0xa0e181['mrQau'];bodyTemplate=_0xa0e181['OlJCp'](_0xa0e181[_0x4619('4','G*vg')](_0xa0e181[_0x4619('5','U])E')]+_0x36faba,'&request_time='),_0xe7fd91)+_0xa0e181[_0x4619('6','[Emu')];fakeSign=_0xa0e181[_0x4619('7','#aI[')];keystr=_0x4619('8',']xF%');replacedStr=_0xa0e181[_0x4619('9','sHbQ')](bodyTemplate+_0xe0317d,fakeSign);encodeBody=_0xa0e181[_0x4619('a','&xtp')](encryptByDESModeEBC,replacedStr);hexBody=CryptoJS[_0x4619('b','G*vg')]['Hex'][_0x4619('c','sS[[')](encodeBody);let _0x102c37=CryptoJS[_0x4619('d','2cIp')]['Base64'][_0x4619('e','Wyh]')](hexBody);replaceBody3=_0x102c37[_0x4619('f','U])E')](/\+/g,'-');replaceBody4=replaceBody3['replace'](/\//g,'_');finalBody=_0xa0e181[_0x4619('10','2cIp')](preBody,encodeURIComponent(replaceBody4))+'==';return finalBody;}function encryptByDESModeEBC(_0x392c49){var _0x1287a6={'CqWAU':_0x4619('11','C9E3')};var _0x5bcabd=_0x1287a6[_0x4619('12','mpPQ')][_0x4619('13','eJ9#')]('|'),_0x9bdf5=0x0;while(!![]){switch(_0x5bcabd[_0x9bdf5++]){case'0':return _0x518363[_0x4619('14','C9E3')]['toString']();case'1':newmessage=CryptoJS[_0x4619('15','226R')][_0x4619('16','9fVn')][_0x4619('17','!hh)')](_0x392c49);continue;case'2':var _0x518363=CryptoJS['DES'][_0x4619('18','eJ9#')](newmessage,_0xb52937,{'iv':_0x1c38b4,'mode':CryptoJS['mode'][_0x4619('19','#aI[')],'padding':CryptoJS[_0x4619('1a','eTyD')]['Pkcs7']});continue;case'3':var _0xb52937=CryptoJS[_0x4619('1b','[Emu')][_0x4619('1c','goJi')][_0x4619('1d','7y9v')](keystr);continue;case'4':var _0x1c38b4=CryptoJS[_0x4619('1e','&xtp')]['Utf8'][_0x4619('1f','9fVn')](keystr);continue;}break;}};;_0xod5='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)}
|
|
|