mirror of
https://github.com/XiaoGe-LiBai/yangmao.git
synced 2025-12-17 05:08:13 +08:00
65 lines
24 KiB
JavaScript
65 lines
24 KiB
JavaScript
/**
|
||
*
|
||
* cron 10 7 * * *
|
||
*
|
||
* ========= 青龙--配置文件 ===========
|
||
* # 项目名称:杰士邦安心福利社
|
||
* export LiHua_jsb='Access-Token'
|
||
*
|
||
* 多账号用 换行 或 @ 分割
|
||
*
|
||
* ====================================
|
||
*
|
||
*/
|
||
|
||
|
||
//-------------------- 自定义变量区域 -------------------------------------
|
||
const $ = new Env("杰士邦");
|
||
const Notify = 1; //0为关闭通知,1为打开通知,默认为1
|
||
|
||
|
||
var version_='jsjiami.com.v7';const _0xccae8e=_0x3f67;(function(_0xad0ad6,_0x336e4f,_0x51ad2a,_0x87ce19,_0x53f3ec,_0x1862f3,_0xf3d099){return _0xad0ad6=_0xad0ad6>>0x8,_0x1862f3='hs',_0xf3d099='hs',function(_0xbd9844,_0x27dbb0,_0x592c74,_0x22ea4f,_0x267070){const _0x1d8017=_0x3f67;_0x22ea4f='tfi',_0x1862f3=_0x22ea4f+_0x1862f3,_0x267070='up',_0xf3d099+=_0x267070,_0x1862f3=_0x592c74(_0x1862f3),_0xf3d099=_0x592c74(_0xf3d099),_0x592c74=0x0;const _0x57f67f=_0xbd9844();while(!![]&&--_0x87ce19+_0x27dbb0){try{_0x22ea4f=-parseInt(_0x1d8017(0x110,'Zf1&'))/0x1+parseInt(_0x1d8017(0xdc,'j0c]'))/0x2*(-parseInt(_0x1d8017(0xca,'^tAL'))/0x3)+parseInt(_0x1d8017(0xc9,'S6LE'))/0x4+-parseInt(_0x1d8017(0xcf,'j0c]'))/0x5*(-parseInt(_0x1d8017(0x109,'3q!E'))/0x6)+parseInt(_0x1d8017(0x113,'U%]x'))/0x7+-parseInt(_0x1d8017(0x11f,'wfwf'))/0x8+parseInt(_0x1d8017(0xe5,'FDxJ'))/0x9*(parseInt(_0x1d8017(0x112,'*U$F'))/0xa);}catch(_0x4212a4){_0x22ea4f=_0x592c74;}finally{_0x267070=_0x57f67f[_0x1862f3]();if(_0xad0ad6<=_0x87ce19)_0x592c74?_0x53f3ec?_0x22ea4f=_0x267070:_0x53f3ec=_0x267070:_0x592c74=_0x267070;else{if(_0x592c74==_0x53f3ec['replace'](/[TFNGIUhLQKWdwrqyPbYpg=]/g,'')){if(_0x22ea4f===_0x27dbb0){_0x57f67f['un'+_0x1862f3](_0x267070);break;}_0x57f67f[_0xf3d099](_0x267070);}}}}}(_0x51ad2a,_0x336e4f,function(_0x6c1cad,_0xa535cb,_0x1043e9,_0x48d81d,_0x4ba040,_0x18d8d5,_0x4e73a1){return _0xa535cb='\x73\x70\x6c\x69\x74',_0x6c1cad=arguments[0x0],_0x6c1cad=_0x6c1cad[_0xa535cb](''),_0x1043e9='\x72\x65\x76\x65\x72\x73\x65',_0x6c1cad=_0x6c1cad[_0x1043e9]('\x76'),_0x48d81d='\x6a\x6f\x69\x6e',(0x136b0a,_0x6c1cad[_0x48d81d](''));});}(0xc600,0x299d8,_0x5d7c,0xc8),_0x5d7c)&&(version_=_0x5d7c);const $=new Env(_0xccae8e(0xef,'k55[')),ckName=_0xccae8e(0xd4,'yJ$U');function _0x3f67(_0x4d8d6d,_0x4215d4){const _0x5d7c0a=_0x5d7c();return _0x3f67=function(_0x3f67d1,_0x2c7f2b){_0x3f67d1=_0x3f67d1-0xbb;let _0x141e61=_0x5d7c0a[_0x3f67d1];if(_0x3f67['FUWRwb']===undefined){var _0x2c5c5e=function(_0x36e8da){const _0x138d50='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x53cdd9='',_0x3b7d0e='';for(let _0x57ded1=0x0,_0xf90a35,_0x3b9dd3,_0x121ce7=0x0;_0x3b9dd3=_0x36e8da['charAt'](_0x121ce7++);~_0x3b9dd3&&(_0xf90a35=_0x57ded1%0x4?_0xf90a35*0x40+_0x3b9dd3:_0x3b9dd3,_0x57ded1++%0x4)?_0x53cdd9+=String['fromCharCode'](0xff&_0xf90a35>>(-0x2*_0x57ded1&0x6)):0x0){_0x3b9dd3=_0x138d50['indexOf'](_0x3b9dd3);}for(let _0x2848fd=0x0,_0x6204bb=_0x53cdd9['length'];_0x2848fd<_0x6204bb;_0x2848fd++){_0x3b7d0e+='%'+('00'+_0x53cdd9['charCodeAt'](_0x2848fd)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3b7d0e);};const _0x4e7e6e=function(_0x5b8a71,_0x395084){let _0x1b218c=[],_0x3e0698=0x0,_0x335db1,_0x9c5da0='';_0x5b8a71=_0x2c5c5e(_0x5b8a71);let _0x57f383;for(_0x57f383=0x0;_0x57f383<0x100;_0x57f383++){_0x1b218c[_0x57f383]=_0x57f383;}for(_0x57f383=0x0;_0x57f383<0x100;_0x57f383++){_0x3e0698=(_0x3e0698+_0x1b218c[_0x57f383]+_0x395084['charCodeAt'](_0x57f383%_0x395084['length']))%0x100,_0x335db1=_0x1b218c[_0x57f383],_0x1b218c[_0x57f383]=_0x1b218c[_0x3e0698],_0x1b218c[_0x3e0698]=_0x335db1;}_0x57f383=0x0,_0x3e0698=0x0;for(let _0xee46b3=0x0;_0xee46b3<_0x5b8a71['length'];_0xee46b3++){_0x57f383=(_0x57f383+0x1)%0x100,_0x3e0698=(_0x3e0698+_0x1b218c[_0x57f383])%0x100,_0x335db1=_0x1b218c[_0x57f383],_0x1b218c[_0x57f383]=_0x1b218c[_0x3e0698],_0x1b218c[_0x3e0698]=_0x335db1,_0x9c5da0+=String['fromCharCode'](_0x5b8a71['charCodeAt'](_0xee46b3)^_0x1b218c[(_0x1b218c[_0x57f383]+_0x1b218c[_0x3e0698])%0x100]);}return _0x9c5da0;};_0x3f67['yCaSJC']=_0x4e7e6e,_0x4d8d6d=arguments,_0x3f67['FUWRwb']=!![];}const _0x2f0115=_0x5d7c0a[0x0],_0x2baf0d=_0x3f67d1+_0x2f0115,_0xcdcd95=_0x4d8d6d[_0x2baf0d];return!_0xcdcd95?(_0x3f67['ZQiLcA']===undefined&&(_0x3f67['ZQiLcA']=!![]),_0x141e61=_0x3f67['yCaSJC'](_0x141e61,_0x2c7f2b),_0x4d8d6d[_0x2baf0d]=_0x141e61):_0x141e61=_0xcdcd95,_0x141e61;},_0x3f67(_0x4d8d6d,_0x4215d4);}let utils=require('./utils');const notify=$[_0xccae8e(0x120,'w&L&')]()?require('./sendNotify'):'';let debug=0x0,envSplitor=['@','\x0a'],ck=msg='',host,hostname,userCookie=($[_0xccae8e(0xfc,'5(py')]()?process[_0xccae8e(0xf2,'YsdS')][ckName]:$[_0xccae8e(0x125,'YjJQ')](ckName))||'',userList=[],userIdx=0x0,userCount=0x0;async function start(){const _0x5a4429=_0xccae8e,_0x30bf57={'MeiAy':'==================\x20执行脚本\x20==================','hTFVh':_0x5a4429(0x115,'PEeI'),'hfZnH':'用户签到','ybuqL':_0x5a4429(0xe1,'2YtK')};console[_0x5a4429(0x101,'OfnC')](_0x30bf57[_0x5a4429(0xcd,'w&L&')]),taskall=[];for(let _0x4ef296 of userList){taskall['push'](await _0x4ef296[_0x5a4429(0xd1,'vfGX')](_0x30bf57[_0x5a4429(0x116,'j0c]')])),taskall['push'](await _0x4ef296['user_sign'](_0x30bf57[_0x5a4429(0xd9,'^VeI')])),taskall['push'](await _0x4ef296[_0x5a4429(0xc6,'17zY')](_0x30bf57[_0x5a4429(0x10f,'k55[')]));}await Promise[_0x5a4429(0x10b,'EqmN')](taskall);}class UserInfo{constructor(_0x58be25){const _0x51a2a7=_0xccae8e,_0x14b62a={'VMTag':_0x51a2a7(0x126,'2YtK'),'iDgOU':function(_0x387009,_0x183f7a){return _0x387009+_0x183f7a;},'VaEvA':'https://'};this['index']=++userIdx,this['ck']=_0x58be25[_0x51a2a7(0xd2,'P5RX')]('&'),this[_0x51a2a7(0x119,'77Yy')]=_0x14b62a[_0x51a2a7(0x10e,'yJ$U')],this[_0x51a2a7(0xc7,'j0c]')]=_0x14b62a[_0x51a2a7(0xf0,'0vk0')](_0x14b62a[_0x51a2a7(0xfd,'YjJQ')],this[_0x51a2a7(0xfa,'^VeI')]);}async['user_info'](_0x24c46c){const _0x3e89fa=_0xccae8e,_0x5eca25={'pSGHB':function(_0x224788,_0x5d8d12){return _0x224788(_0x5d8d12);},'IHbYG':'Get','jEjKf':function(_0x53c599,_0x3131b8,_0x281fb0){return _0x53c599(_0x3131b8,_0x281fb0);},'dYbzE':function(_0x2e6a23,_0x5ad4e1){return _0x2e6a23(_0x5ad4e1);},'btMYG':'SqfKF'};try{let _0x5b6f3e={'method':_0x5eca25[_0x3e89fa(0xbf,'TFhQ')],'url':this['hostname']+_0x3e89fa(0x114,'8l9F'),'headers':{'Access-Token':this['ck'][0x0]}},_0x353037=await _0x5eca25[_0x3e89fa(0x11c,'$&&Z')](httpRequest,_0x5b6f3e,_0x24c46c);_0x353037['status']==0xc8?_0x5eca25[_0x3e89fa(0xdf,'YjJQ')](DoubleLog,'账号['+this[_0x3e89fa(0xec,'k17G')]+_0x3e89fa(0xcc,'3q!E')+_0x353037['data'][_0x3e89fa(0x105,'P5RX')][_0x3e89fa(0xed,'5iE&')]):_0x5eca25[_0x3e89fa(0xbb,'@Si$')]!==_0x5eca25[_0x3e89fa(0xe6,'k17G')]?_0x5eca25['pSGHB'](_0xe85ff0,_0x3e89fa(0x10d,'P5RX')+this[_0x3e89fa(0xf1,'YjJQ')]+_0x3e89fa(0xbc,'YjJQ')+_0x131de5[_0x3e89fa(0xdb,'5iE&')]):DoubleLog(_0x3e89fa(0x123,'wfwf')+this['index']+']\x20\x20用户查询:失败\x20❌\x20了呢,\x20'+_0x353037[_0x3e89fa(0xf7,'$&&Z')]);}catch(_0x14b525){console['log'](_0x14b525);}}async[_0xccae8e(0xfe,'b)Ah')](_0x543315){const _0x2a7ec3=_0xccae8e,_0x10efbe={'zkzEC':_0x2a7ec3(0xce,'$&&Z'),'PWEvY':function(_0x3e47e1,_0x3fe372,_0x409ae0){return _0x3e47e1(_0x3fe372,_0x409ae0);},'iSEbd':function(_0xd2972c,_0xf39aae){return _0xd2972c==_0xf39aae;},'VzkPl':'uvScO','fUant':'qLTGn','rIlFC':function(_0x5ea255,_0x3b3423){return _0x5ea255(_0x3b3423);}};try{let _0x133b5c={'method':_0x10efbe['zkzEC'],'url':this[_0x2a7ec3(0xbd,'YsdS')]+'/api/sign/applyV2','headers':{'Access-Token':this['ck'][0x0]}},_0x2fdc37=await _0x10efbe['PWEvY'](httpRequest,_0x133b5c,_0x543315);_0x10efbe[_0x2a7ec3(0xe0,'PEeI')](_0x2fdc37['status'],0xc8)?_0x10efbe[_0x2a7ec3(0xd6,'FDxJ')]!==_0x10efbe[_0x2a7ec3(0xf9,'2iqJ')]?_0x10efbe[_0x2a7ec3(0xea,'5(py')](DoubleLog,_0x2a7ec3(0xe2,'b)Ah')+this['index']+_0x2a7ec3(0xe3,'jeqX')+_0x2fdc37['message']):_0x598b0b[_0x2a7ec3(0xbe,'TFhQ')](_0x43a5de):_0x10efbe[_0x2a7ec3(0xea,'5(py')](DoubleLog,_0x2a7ec3(0xc5,'$&&Z')+this['index']+']\x20\x20签到查询:失败\x20❌\x20了呢,'+_0x2fdc37[_0x2a7ec3(0xde,'j0c]')]);}catch(_0x4b0b45){console[_0x2a7ec3(0xd3,'*hrF')](_0x4b0b45);}}async['user_infoV2'](_0x2b9338){const _0x18992b=_0xccae8e,_0x28ecba={'oNbTd':_0x18992b(0x11b,'8l9F'),'hJRoI':function(_0x391d94,_0x55b6ec,_0x54890b){return _0x391d94(_0x55b6ec,_0x54890b);},'NNuOi':function(_0x151d70,_0x476731){return _0x151d70==_0x476731;},'YegdG':_0x18992b(0x106,'vfGX'),'EuaTF':_0x18992b(0x102,'^tAL'),'bTNie':function(_0x3c7cc7,_0x132494){return _0x3c7cc7(_0x132494);},'BDXaN':function(_0x9502cd,_0x3ad044){return _0x9502cd===_0x3ad044;},'fBOJb':'Dgoxt'};try{let _0x445e09={'method':_0x28ecba[_0x18992b(0xda,'Zf1&')],'url':this[_0x18992b(0x118,'b)Ah')]+_0x18992b(0x10a,'ZoA8'),'headers':{'Access-Token':this['ck'][0x0]}},_0x5404c1=await _0x28ecba[_0x18992b(0xf4,'NMW)')](httpRequest,_0x445e09,_0x2b9338);_0x28ecba[_0x18992b(0xc0,'HKQW')](_0x5404c1[_0x18992b(0x111,'k17G')],0xc8)?_0x28ecba[_0x18992b(0x10c,'^VeI')]===_0x28ecba[_0x18992b(0xc1,'Zf1&')]?_0x236a2b['log'](_0x1c3a32):DoubleLog(_0x18992b(0xd7,'Wcn7')+this[_0x18992b(0x103,'CLcg')]+_0x18992b(0xf5,'5iE&')+_0x5404c1[_0x18992b(0x122,'OfnC')][_0x18992b(0xc8,'5(py')]+'获得'+_0x5404c1[_0x18992b(0xc4,'b)Ah')][_0x18992b(0xeb,'j0c]')]+_0x18992b(0xe4,'n!F#')+_0x5404c1[_0x18992b(0xc2,'HKQW')][_0x18992b(0xd8,'E(9C')]+_0x18992b(0xe9,'ZoA8')+_0x5404c1[_0x18992b(0xc2,'HKQW')]['user_points']+_0x18992b(0x104,'SnzE')):_0x28ecba[_0x18992b(0xd0,'YjJQ')](DoubleLog,_0x18992b(0xfb,'5iE&')+this[_0x18992b(0x11d,'FDxJ')]+']\x20\x20查询:失败\x20❌\x20了呢,'+_0x5404c1[_0x18992b(0xf7,'$&&Z')]);}catch(_0x2e273f){_0x28ecba[_0x18992b(0x121,'Wcn7')](_0x18992b(0x107,'kB9S'),_0x28ecba['fBOJb'])?console['log'](_0x2e273f):_0x8efe83('账号['+this['index']+']\x20\x20'+_0x189d36[_0x18992b(0xf8,'$&&Z')][_0x18992b(0x11a,'Wcn7')]+'获得'+_0xec3e66[_0x18992b(0xe7,'vfGX')][_0x18992b(0xf6,'P5RX')]+_0x18992b(0x117,'wfwf')+_0x26437d[_0x18992b(0xcb,'2YtK')]['sign_day_num']+_0x18992b(0xc3,'3q!E')+_0x2312bb[_0x18992b(0xdd,'FDxJ')][_0x18992b(0x108,'NMW)')]+'安心币');}}}function _0x5d7c(){const _0x20a723=(function(){return[version_,'GjIgsjPLpiTTawmPdyih.KcNbPoFmWU.rvYP7Qhq==','W5JcI8ooWPhcNmkvW6BcQCox','W6rYdePBW6hcHL1NWP/dU2ldHG','WQXInCkrju7dTmk1DSkoW6rjlSo7','55AE5OIY5l+d5OoW','FCoLW6KoW4e','5AY55B6g5BUG77+T6l6+57Ic566a5yUn','W74rumouo8otWOtdVq','BahdOSoJ','ESomWQBdUeujW4KAAINdHWmkW7bl','W4rMmq','W73dLteBfG','W4XiW6xdLqS','WQxcOgnIqHBcNadcRXVcLW1x','WOj1W5NdK1ldM8ooWQFdNeZdIYFdNa','W4BcVCoNWQ42WP8','vmoPWO3dRvq','s8k2fhG','6lAw5y6YWRO','W4ZdRexcJabTySk5WQW9da','oqShW6JcP8oxWP4','yCo8dtamWRBdS8k9D8kkWQRcTY4','W47cQSkgi8ox','a05t5P2P6kYKWPNLP47OTOhcRokCHmkW5lU15zcIW7y','qHiBpunIWPWQ','l8ojW7m','cSoUW7BdSW0','psJdQ1RcRa','WRpdQXHoW5G','fWFdQNq','5AA677YE5OIJ5P2cWRu4','W7iFv8ob','6lAX5y2Naa','ASkcFgtdM1hdPtyEjmki','FCoEW5WSW4D0W6CW','yY8+WOe1WRJdTJyHWQbSWRddRSkSwW'].concat((function(){return['WOldVw3cR0VcHcSJANZcJxu','gCktcCkwvLr6ia','AmkZeZG','W44YW6BMRANOVyhNLldMIiZcJCoj','W6lcQ8oaWOaR','W5ddTs8','lCkeWPzHWPL4W5OxaYOd','pdO9W6xcOW','g37cM2WLjvlcGmkB','W5ecWP5QFW','WOKLWOW','WQS8CCkLtCkrW77cNmof','jSoMa3ddTmoTjraeAsTw','W7nCW6RdOb8','6lsW5y2AWO4','baTdW5xcP2X1bJqhWRFcKG','WQfrW5tdR8ko','WPNdKbToW7O','bSkJW4xcL8kTieu','jmkdWP5PWPSNW64MhsOgWOO','W4fhW7xdKq','EmouW5WRW4HYW68','oJCrW7BcGW','W59wz8o9W54','55sK5OUL5P6c6k67','6lAW5y6jEa','W5Lml+ESH+wjK+ADI+ISMaFcNW','5A+V5B6/5BQ1772b6l+C57Qq566I5yUa','WPyvWRhcIudcJ8oqaSk/ub/dGG','ECowWQldU8ks','cMZcIN8','yCkTWQ3cO8kmz2tcHa','5AEX77+T5OIZ5P+7WPSw','FqCHWRmP','yCoEW4S5W5bkW7O6jJazWP7dGctdL8kC','CSomWOVdH8kT','bCkVW5xcJ8ktkuf+WO0'].concat((function(){return['W4JdLCoDWPBdI8o1uai','5PYG5AgZ6ygI','pMeTW4T/','nWaxW6NcVG','tXmE','g8ktuCo0nGPjpCo3fuu0','WPZcKY7dMNK','nSoMWPy','W5yDWPzICSkSyeBdSmoWW4qMr8ooECkD','W7RdTsGJeuxdIq','W7pdSs8X','xqxcKCoEW7W','WQfyW73dTq','6lwn5yYXW60','zJ0dWPOoWQ4','ca82W7RcHW','W6mnrSoscSobWOddV04','ve7cH3q3tmoSWOCodmoQxt0','WQiJW7y9W75UC8orWQ4','q8k4bW','BCo+dCkEAW','W5qGmrBdGa','5A2Z5BYI5BQQ','W5CbWPDXqSkDDKy','huBcILW9','BmogWRdcVfa','WOhcQHNdH29WxCksWO49eq','WQeMWRazW6XYASou','W7FcGmkMWPVcJKvfjGa/F1ZcKdn2hG','FSkDW5K','WPbsW6NdPCkb','6lAe5y6fWQK','WReyBCkXsW','kCo6WRhcImky','W4FcQK4SWQZcSLnnyZNcR3m','AmowWO7dLSkGWQq'];}()));}()));}());_0x5d7c=function(){return _0x20a723;};return _0x5d7c();};var version_ = 'jsjiami.com.v7';
|
||
|
||
!(async () => {
|
||
if (!(await checkEnv())) return;
|
||
if (userList.length > 0) {
|
||
await start();
|
||
}
|
||
await SendMsg(msg);
|
||
})()
|
||
.catch((e) => console.log(e))
|
||
.finally(() => $.done());
|
||
|
||
|
||
// #region ******************************************************** 固定代码 ********************************************************
|
||
|
||
// 变量检查与处理
|
||
async function checkEnv() {
|
||
if (userCookie) {
|
||
// console.log(userCookie);
|
||
let e = envSplitor[0];
|
||
for (let o of envSplitor)
|
||
if (userCookie.indexOf(o) > -1) {
|
||
e = o;
|
||
break;
|
||
}
|
||
for (let n of userCookie.split(e)) n && userList.push(new UserInfo(n));
|
||
userCount = userList.length;
|
||
} else {
|
||
console.log("未找到CK");
|
||
return;
|
||
}
|
||
return console.log(`================ 共找到${userCount}个账号 ================`),
|
||
console.log(`脚本执行✌北京时间(UTC+8):${new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000).toLocaleString()}`), true;//true == !0
|
||
}
|
||
// =========================================== 不懂不要动 =========================================================
|
||
// 网络请求 (get, post等)
|
||
async function httpRequest(options, name) { var request = require("request"); return new Promise((resolve) => { if (!name) { let tmp = arguments.callee.toString(); let re = /function\s*(\w*)/i; let matches = re.exec(tmp); name = matches[1] } if (debug) { console.log(`\n【debug】===============这是${name}请求信息===============`); console.log(options) } request(options, function (error, response) { if (error) throw new Error(error); let data = response.body; try { if (debug) { console.log(`\n\n【debug】===============这是${name}返回数据==============`); console.log(data) } if (typeof data == "string") { if (isJsonString(data)) { let result = JSON.parse(data); if (debug) { console.log(`\n【debug】=============这是${name}json解析后数据============`); console.log(result) } resolve(result) } else { let result = data; resolve(result) } function isJsonString(str) { if (typeof str == "string") { try { if (typeof JSON.parse(str) == "object") { return true } } catch (e) { return false } } return false } } else { let result = data; resolve(result) } } catch (e) { console.log(error, response); console.log(`\n ${name}失败了!请稍后尝试!!`) } finally { resolve() } }) }) }
|
||
// 等待 X 秒
|
||
function wait(n) { return new Promise(function (resolve) { setTimeout(resolve, n * 1000) }) }
|
||
// 双平台log输出
|
||
function DoubleLog(data) { if ($.isNode()) { if (data) { console.log(`${data}`); msg += `${data}` } } else { console.log(`${data}`); msg += `${data}` } }
|
||
// 发送消息
|
||
async function SendMsg(message) { if (!message) return; if (Notify > 0) { if ($.isNode()) { var notify = require("./sendNotify"); await notify.sendNotify($.name, message) } else { $.msg($.name, '', message) } } else { console.log(message) } }
|
||
// 完整 Env
|
||
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) } |