faker3/jd_cacheIsvToken.js

64 lines
22 KiB
JavaScript
Raw Normal View History

2024-06-28 15:38:28 +08:00
/*
缓存IsvToken
如果你的网络环境不佳你可以使用此脚本提前缓存默认缓存到本地缓存方式基于调用 getToken 模块脚本更多功能详见如下Readme支持配置代理和自定义缓存等
每次运行都会覆盖本地缓存请勿频繁运行若非必要则不建议定时运行此脚本否则请保持运行间隔在25分钟以上
7 7 7 7 * jd_cacheIsvToken.js
- ### 配置代理
- #### 全局代理
```bash
## 启用代理
export JD_ISV_GLOBAL_PROXY="true"
## 代理组件库相关控制变量
# 定义 HTTP 代理地址必填
export GLOBAL_AGENT_HTTP_PROXY="" # http://127.0.0.1:8080
# 过滤不需要代理的地址必填
export GLOBAL_AGENT_NO_PROXY='127.0.0.1,172.17.0.1,*.telegram.org,oapi.dingtalk.com' # 用英文逗号分割多个地址这里特别注意要把用到的内网ip过滤掉
```
全局代理适用于本仓库绝大多数脚本更多配置方法详见 [gajus/global-agent](https://github.com/gajus/global-agent)
需要额外安装代理依赖库才能使用 `npm install -g global-agent`
> 如果你正在使用 Arcadia 面板则无需重复安装此代理依赖库并且可以通过命令选项 `--agent` 在任意脚本上便捷的实现全局代理功能具体详见配置文件和文档
- #### 获取 `Token` 局部代理
```bash
export JD_ISV_TOKEN_PROXY="" # 代理接口地址
```
目前受限于官方接口策略同一IP段请求多个账号后会频繁响应 `403`因此可能需要配合代理使用使用代理时会自动重试请求至多3次
需要额外安装代理依赖库才能使用 `npm install -g hpagent`
- ##### 通过 API 提取的动态代理
如果你需要使用的是代理商接口所动态提供的代理地址那么请定义下方的变量
```bash
export JD_ISV_TOKEN_PROXY_API="" # 代理接口地址http://example.com/api/getProxy?sevret=xxx
export JD_ISV_TOKEN_PROXY_API_MAX="" # 每个代理地址的使用次数默认为1次
```
为了避免不必要的浪费建议将接口每次响应的代理地址数量设置为1个另外建议将接口响应格式设置为单行文本的 `ip:port` 格式同时也支持 `json` 格式不过仅适配了部分代理商
启用此模式后由环境变量 `JD_ISV_TOKEN_PROXY_API` 指定的固定代理地址将会自动被忽略届时会使用接口响应数据所动态提供的代理地址
- ### 自定义 `Token` 缓存
- #### 自定义缓存文件路径
```bash
export JD_ISV_TOKEN_CUSTOM_CACHE="" # 绝对路径建议以 token.json 命名
```
> 此文件默认存储在仓库 `function/cache` 目录下
- #### 使用 `Redis` 数据库
```bash
export JD_ISV_TOKEN_REDIS_CACHE_URL="" # 数据库地址redis://password@127.0.0.1:6379/0
export JD_ISV_TOKEN_REDIS_CACHE_KEY="" # 自定义提取或提交的键名规则详见下方说明
export JD_ISV_TOKEN_REDIS_CACHE_SUBMIT="" # 是否向数据库提交新的缓存tokentrue/false默认是
```
> 需要额外安装依赖库才能使用 `npm install -g redis`默认从键名为用户名的字符串对象中提取键值用户名是解码后的
> 如果你想自定义键名格式则需要将用户名位置设为 `<pt_pin>` 例如`isv_token:<pt_pin>`否则将自动在末尾追加
*/
const $ = new Env('缓存IsvToken')
const jdCookie = require('./jdCookie')
const common = require('./function/jdCommon')
const notify = require('./function/sendJDNotify')
const getToken = require('./function/getToken')
var version_='jsjiami.com.v7';function llIiI1iI(_0x3f1577,_0x11d530){const _0x2a3079=iiI1Ii1I();return llIiI1iI=function(_0x3b69f0,_0x11d281){_0x3b69f0=_0x3b69f0-0x7c;let _0x148a20=_0x2a3079[_0x3b69f0];if(llIiI1iI['WPgqgq']===undefined){var _0x5ebcb1=function(_0x1bd297){const _0x523181='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x2c7d63='',_0x2537a6='';for(let _0x1dd946=0x0,_0x30958e,_0x587529,_0x5a7dc4=0x0;_0x587529=_0x1bd297['charAt'](_0x5a7dc4++);~_0x587529&&(_0x30958e=_0x1dd946%0x4?_0x30958e*0x40+_0x587529:_0x587529,_0x1dd946++%0x4)?_0x2c7d63+=String['fromCharCode'](0xff&_0x30958e>>(-0x2*_0x1dd946&0x6)):0x0){_0x587529=_0x523181['indexOf'](_0x587529);}for(let _0x1f2974=0x0,_0x378e28=_0x2c7d63['length'];_0x1f2974<_0x378e28;_0x1f2974++){_0x2537a6+='%'+('00'+_0x2c7d63['charCodeAt'](_0x1f2974)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x2537a6);};const _0x20e616=function(_0xe00ffb,_0x564cf5){let _0x3aa79a=[],_0x269f78=0x0,_0x4cf528,_0x37367f='';_0xe00ffb=_0x5ebcb1(_0xe00ffb);let _0x2d47bc;for(_0x2d47bc=0x0;_0x2d47bc<0x100;_0x2d47bc++){_0x3aa79a[_0x2d47bc]=_0x2d47bc;}for(_0x2d47bc=0x0;_0x2d47bc<0x100;_0x2d47bc++){_0x269f78=(_0x269f78+_0x3aa79a[_0x2d47bc]+_0x564cf5['charCodeAt'](_0x2d47bc%_0x564cf5['length']))%0x100,_0x4cf528=_0x3aa79a[_0x2d47bc],_0x3aa79a[_0x2d47bc]=_0x3aa79a[_0x269f78],_0x3aa79a[_0x269f78]=_0x4cf528;}_0x2d47bc=0x0,_0x269f78=0x0;for(let _0xf0882e=0x0;_0xf0882e<_0xe00ffb['length'];_0xf0882e++){_0x2d47bc=(_0x2d47bc+0x1)%0x100,_0x269f78=(_0x269f78+_0x3aa79a[_0x2d47bc])%0x100,_0x4cf528=_0x3aa79a[_0x2d47bc],_0x3aa79a[_0x2d47bc]=_0x3aa79a[_0x269f78],_0x3aa79a[_0x269f78]=_0x4cf528,_0x37367f+=String['fromCharCode'](_0xe00ffb['charCodeAt'](_0xf0882e)^_0x3aa79a[(_0x3aa79a[_0x2d47bc]+_0x3aa79a[_0x269f78])%0x100]);}return _0x37367f;};llIiI1iI['pbAQVI']=_0x20e616,_0x3f1577=arguments,llIiI1iI['WPgqgq']=!![];}const _0x5ead9d=_0x2a3079[0x0],_0x2b93c7=_0x3b69f0+_0x5ead9d,_0x1186c7=_0x3f1577[_0x2b93c7];return!_0x1186c7?(llIiI1iI['dyVyCs']===undefined&&(llIiI1iI['dyVyCs']=!![]),_0x148a20=llIiI1iI['pbAQVI'](_0x148a20,_0x11d281),_0x3f1577[_0x2b93c7]=_0x148a20):_0x148a20=_0x1186c7,_0x148a20;},llIiI1iI(_0x3f1577,_0x11d530);}const III1i11I=llIiI1iI;(function(Il11i1I,Illli1Il,iI1iiII1,IiII1i1,iili1i11,lIilIll1,i1iiIl11){return Il11i1I=Il11i1I>>0x1,lIilIll1='hs',i1iiIl11='hs',function(lIIiii11,II11i1ii,IllIll,li1iiIil,ilII1il){const I111Il1=llIiI1iI;li1iiIil='tfi',lIilIll1=li1iiIil+lIilIll1,ilII1il='up',i1iiIl11+=ilII1il,lIilIll1=IllIll(lIilIll1),i1iiIl11=IllIll(i1iiIl11),IllIll=0x0;const II11lil=lIIiii11();while(!![]&&--IiII1i1+II11i1ii){try{li1iiIil=parseInt(I111Il1(0xce,'1w]^'))/0x1+-parseInt(I111Il1(0x7f,'uCta'))/0x2+parseInt(I111Il1(0xf7,'p6Xn'))/0x3+-parseInt(I111Il1(0xe9,'12BW'))/0x4+parseInt(I111Il1(0xb4,'1ud1'))/0x5+-parseInt(I111Il1(0xf0,'2ptK'))/0x6+-parseInt(I111Il1(0x94,'1w]^'))/0x7*(-parseInt(I111Il1(0x104,'C%P^'))/0x8);}catch(lll1lii1){li1iiIil=IllIll;}finally{ilII1il=II11lil[lIilIll1]();if(Il11i1I<=IiII1i1)IllIll?iili1i11?li1iiIil=ilII1il:iili1i11=ilII1il:IllIll=ilII1il;else{if(IllIll==iili1i11['replace'](/[pDEGlkSUHuKWVqCOdfry=]/g,'')){if(li1iiIil===II11i1ii){II11lil['un'+lIilIll1](ilII1il);break;}II11lil[i1iiIl11](ilII1il);}}}}}(iI1iiII1,Illli1Il,function(lill1lIi,lli1lll,i1ll1ilI,I1Ili111,I11ll1l,l11lI,iI1l1II){return lli1lll='\x73\x70\x6c\x69\x74',lill1lIi=arguments[0x0],lill1lIi=lill1lIi[lli1lll](''),i1ll1ilI=`\x72\x65\x76\x65\x72\x73\x65`,lill1lIi=lill1lIi[i1ll1ilI]('\x76'),I1Ili111=`\x6a\x6f\x69\x6e`,(0x146f7a,lill1lIi[I1Ili111](''));});}(0x198,0x800b6,iiI1Ii1I,0xce),iiI1Ii1I)&&(version_=III1i11I(0xb7,'yeB&'));let cookie='',originCookie='';const cookiesArr=Object[III1i11I(0x98,'mzz3')](jdCookie)[III1i11I(0xd5,'QWAc')](il11Ii1l=>jdCookie[il11Ii1l])[III1i11I(0xbf,'MKYC')](IIlll1i=>IIlll1i);function iiI1Ii1I(){const lIlI1lll=(function(){return[...[version_,'KSjWlsujrViamqidUy.VckpoWmfr.DGCvHl7OuED==','W6JcICorq8oJW4uW5BYL5AAQ44ke5lIe5lMZ6lwn5y2w','eSkkW4SeW4m','W7ddGfa','W714WRq','ybHQC2GdCMpcGSkQ','W65Da8oBW68OoW','WPWotHbPW7hdQuFdQSkBW6z2','WPPlD104wclcUqK','W
// 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"])