|
| 1 | +/* |
| 2 | + APP:百观 |
| 3 | + 功能:完成任务,获得积分 |
| 4 | + 链接:https://app.tmuyun.com/webChannels/invite?inviteCode=GYY759&tenantId=44&accountId=64642aef7dee05371934932b |
| 5 | + 抓包:https://vapp.tmuyun.com/ 任意-请求头中 x-session-id 或使用 手机号#密码 两者互不影响 |
| 6 | + 变量:bgCookie='xxxx@12345678910#abcdefg ' 多个账号用 @ 或者 换行 分割 |
| 7 | + 定时一天三次 |
| 8 | + cron: 10 8,10,19 * * * |
| 9 | + */ |
| 10 | + const $ = new Env('百观') |
| 11 | + const notify = $.isNode() ? require('./sendNotify') : ''; |
| 12 | + const CryptoJS = require("crypto-js"); |
| 13 | + const salt = "FR*r!isE5W"; |
| 14 | + const appid = 44; |
| 15 | + let cookiesArr = [], |
| 16 | + message = "", |
| 17 | + channelId = ["606566eaad61a43e7054b600", "628b9aa7fe3fc15d06739c58", "628b9dcf7c2ef004af2f8e70", "628b4ea7de224a649d227366"] |
| 18 | + cookie = ($.isNode() ? process.env.bgCookie : $.getdata("bgCookie")) || `` |
| 19 | + helpAu = ($.isNode() ? process.env.jrychelpAu : $.getdata("jrychelpAu")) || true |
| 20 | + !(async () => { |
| 21 | + await requireConfig(); |
| 22 | + for (let i = 0; i < cookiesArr.length; i++) { |
| 23 | + if (cookiesArr[i]) { |
| 24 | + sessionid = '' |
| 25 | + msg = ''; |
| 26 | + $.index = i + 1; |
| 27 | + $.nickName = ''; |
| 28 | + $.userId = ''; |
| 29 | + $.mobile = ''; |
| 30 | + $.userIdStr = ''; |
| 31 | + $.vehicleToken = ''; |
| 32 | + $.taskList = {} |
| 33 | + $.queryList = {} |
| 34 | + await getCookie(cookiesArr[i]) |
| 35 | + await account_detail(); |
| 36 | + console.log(`\n******开始【🐳百观账号${$.index}】${$.nickName}|${$.mobile}*********\n`); |
| 37 | + await main() |
| 38 | + } |
| 39 | + } |
| 40 | + if ($.isNode() && message) { |
| 41 | + await notify.sendNotify(`${$.name}`, `${message}`) |
| 42 | + } |
| 43 | + })() |
| 44 | + .catch((e) => $.logErr(e)) |
| 45 | + .finally(() => $.done()) |
| 46 | + |
| 47 | + async function main() { |
| 48 | + if ($.userId) { |
| 49 | + console.log(`【获取任务列表】`) |
| 50 | + await numberCenter() |
| 51 | + console.log(`【开始完成任务】`) |
| 52 | + await article() |
| 53 | + for (i = 0; i < $.taskList.length; i++) { |
| 54 | + if ($.taskList[i].completed === 1) { |
| 55 | + console.log(`[${$.taskList[i].name}]已完成`) |
| 56 | + continue |
| 57 | + } else { |
| 58 | + console.log(`去完成任务:${$.taskList[i].name}`) |
| 59 | + await doTask($.taskList[i]) |
| 60 | + } |
| 61 | + } |
| 62 | + if (helpAu == true) { |
| 63 | + console.log(`【环境变量:jrychelpAu 默认为True 前往助力作者】`) |
| 64 | + await invite() |
| 65 | + } |
| 66 | + console.log(`【查询账号信息】`) |
| 67 | + await account_detail() |
| 68 | + console.log(`拥有:[${$.integral}]积分 | 等级:[${$.grade}]-${$.grade_name}`) |
| 69 | + msg += `拥有:[${$.integral}]积分 \n等级:[${$.grade}]-${$.grade_name}\n\n` |
| 70 | + await showMsg() |
| 71 | + } else console.log(`获取userId失败,退出任务`) |
| 72 | + } |
| 73 | + async function doTask(task) { |
| 74 | + let type = JSON.stringify(task.id); |
| 75 | + let num = Number(task.frequency) - Number(task.finish_times) |
| 76 | + //console.log(`去完成:${task.name},id:${type}`) |
| 77 | + switch (type) { |
| 78 | + case '786': //签到 |
| 79 | + await signin() |
| 80 | + break; |
| 81 | + case '780': //新闻资讯阅读 |
| 82 | + for (j = 0; j < num && j < $.acticleList.length; j++) { |
| 83 | + console.log(`去浏览:${$.acticleList[j].list_title}`) |
| 84 | + await read($.acticleList[j].id) |
| 85 | + await $.wait(1500) |
| 86 | + } |
| 87 | + break; |
| 88 | + case '777': //分享资讯给好友 |
| 89 | + for (j = 0; j < num && j < $.acticleList.length; j++) { |
| 90 | + console.log(`去分享:${$.acticleList[j].list_title}`) |
| 91 | + await share($.acticleList[j].id) |
| 92 | + await $.wait(1500) |
| 93 | + } |
| 94 | + break; |
| 95 | + case '779': //新闻资讯评论 |
| 96 | + for (j = 0; j < num && j < $.acticleList.length; j++) { |
| 97 | + console.log(`去评论:${$.acticleList[j].list_title}`) |
| 98 | + await comment($.acticleList[j].id) |
| 99 | + await $.wait(1500) |
| 100 | + } |
| 101 | + break; |
| 102 | + case '778': //新闻资讯点赞 |
| 103 | + for (j = 0; j < num && j < $.acticleList.length; j++) { |
| 104 | + console.log(`去点赞:${$.acticleList[j].list_title}`) |
| 105 | + await like($.acticleList[j].id) |
| 106 | + await $.wait(1500) |
| 107 | + } |
| 108 | + break; |
| 109 | + default: |
| 110 | + console.log(`${task.name}暂未上线,请反馈作者`); |
| 111 | + } |
| 112 | + } |
| 113 | + /** |
| 114 | + * |
| 115 | + * 获取登录Code |
| 116 | + */ |
| 117 | + async function credential_auth() { |
| 118 | + let url = { |
| 119 | + url: `https://passport.tmuyun.com/web/oauth/credential_auth`, |
| 120 | + body: `client_id=62&password=${encodeURIComponent($.pwd)}&phone_number=${$.mobile}`, |
| 121 | + headers: { |
| 122 | + 'Host': 'passport.tmuyun.com', |
| 123 | + 'Content-Type': 'application/x-www-form-urlencoded', |
| 124 | + 'Accept-Encoding': 'gzip, deflate, br' |
| 125 | + } |
| 126 | + } |
| 127 | + return new Promise(resolve => { |
| 128 | + $.post(url, async (err, resp, data) => { |
| 129 | + try { |
| 130 | + if (err) { |
| 131 | + console.log(`${err}`) |
| 132 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 133 | + } else { |
| 134 | + if (data) { |
| 135 | + data = JSON.parse(data); |
| 136 | + //console.log(JSON.stringify(data)); |
| 137 | + if (data.code === 0) { |
| 138 | + await login(data.data.authorization_code.code) |
| 139 | + } else { |
| 140 | + console.log(data.message) |
| 141 | + } |
| 142 | + } else { |
| 143 | + console.log("没有返回数据") |
| 144 | + } |
| 145 | + } |
| 146 | + } catch (e) { |
| 147 | + $.logErr(e, resp) |
| 148 | + } finally { |
| 149 | + resolve(data); |
| 150 | + } |
| 151 | + }) |
| 152 | + }) |
| 153 | + } |
| 154 | + /** |
| 155 | + * |
| 156 | + * 登录 |
| 157 | + */ |
| 158 | + async function login(code) { |
| 159 | + let body = 'code=' + code |
| 160 | + sessionid = '63777162fe3fc118b09fab89' |
| 161 | + return new Promise(resolve => { |
| 162 | + $.post(taskPostUrl('/api/zbtxz/login', body), async (err, resp, data) => { |
| 163 | + try { |
| 164 | + if (err) { |
| 165 | + console.log(`${err}`) |
| 166 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 167 | + } else { |
| 168 | + if (data) { |
| 169 | + data = JSON.parse(data); |
| 170 | + //console.log(JSON.stringify(data)); |
| 171 | + if (data.code === 0) { |
| 172 | + sessionid = data.data.session.id |
| 173 | + } else { |
| 174 | + //console.log(JSON.stringify(data)) |
| 175 | + } |
| 176 | + } else { |
| 177 | + console.log("没有返回数据") |
| 178 | + } |
| 179 | + } |
| 180 | + } catch (e) { |
| 181 | + $.logErr(e, resp) |
| 182 | + } finally { |
| 183 | + resolve(data); |
| 184 | + } |
| 185 | + }) |
| 186 | + }) |
| 187 | + } |
| 188 | + /** |
| 189 | + * |
| 190 | + * 获取账号信息 |
| 191 | + */ |
| 192 | + async function account_detail() { |
| 193 | + let body = '' |
| 194 | + return new Promise(resolve => { |
| 195 | + $.get((taskUrl("/api/user_mumber/account_detail", body)), async (err, resp, data) => { |
| 196 | + try { |
| 197 | + if (err) { |
| 198 | + console.log(`${err}`) |
| 199 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 200 | + } else { |
| 201 | + if (data) { |
| 202 | + data = JSON.parse(data); |
| 203 | + //console.log(JSON.stringify(data)); |
| 204 | + if (data.code === 0) { |
| 205 | + $.userId = data.data.rst.id |
| 206 | + $.nickName = data.data.rst.nick_name |
| 207 | + $.mobile = data.data.rst.mobile |
| 208 | + $.grade = data.data.rst.grade |
| 209 | + $.grade_name = data.data.rst.grade_name |
| 210 | + $.integral = data.data.rst.total_integral |
| 211 | + } else { |
| 212 | + //console.log(JSON.stringify(data)) |
| 213 | + } |
| 214 | + } else { |
| 215 | + console.log("没有返回数据") |
| 216 | + } |
| 217 | + } |
| 218 | + } catch (e) { |
| 219 | + $.logErr(e, resp) |
| 220 | + } finally { |
| 221 | + resolve(data); |
| 222 | + } |
| 223 | + }) |
| 224 | + }) |
| 225 | + } |
| 226 | + /** |
| 227 | + * |
| 228 | + * 获取任务列表 |
| 229 | + */ |
| 230 | + async function numberCenter() { |
| 231 | + let body = '' |
| 232 | + return new Promise(resolve => { |
| 233 | + $.get((taskUrl("/api/user_mumber/numberCenter", body)), async (err, resp, data) => { |
| 234 | + try { |
| 235 | + if (err) { |
| 236 | + console.log(`${err}`) |
| 237 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 238 | + } else { |
| 239 | + if (data) { |
| 240 | + data = JSON.parse(data); |
| 241 | + //console.log(JSON.stringify(data)); |
| 242 | + if (data.code === 0) { |
| 243 | + console.log(`获取成功!`) |
| 244 | + $.taskList = data.data.rst['user_task_list'] |
| 245 | + //console.log(JSON.stringify($.taskList)) |
| 246 | + } else { |
| 247 | + console.log(JSON.stringify(data)) |
| 248 | + } |
| 249 | + } else { |
| 250 | + console.log("没有返回数据") |
| 251 | + } |
| 252 | + } |
| 253 | + } catch (e) { |
| 254 | + $.logErr(e, resp) |
| 255 | + } finally { |
| 256 | + resolve(data); |
| 257 | + } |
| 258 | + }) |
| 259 | + }) |
| 260 | + } |
| 261 | + /** |
| 262 | + * |
| 263 | + * 签到 |
| 264 | + */ |
| 265 | + async function signin() { |
| 266 | + let body = '' |
| 267 | + return new Promise(resolve => { |
| 268 | + $.get((taskUrl("/api/user_mumber/sign", body)), async (err, resp, data) => { |
| 269 | + try { |
| 270 | + if (err) { |
| 271 | + console.log(`${err}`) |
| 272 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 273 | + } else { |
| 274 | + if (data) { |
| 275 | + data = JSON.parse(data); |
| 276 | + //console.log(JSON.stringify(data)); |
| 277 | + if (data.code === 0) { |
| 278 | + console.log(`签到成功!获得:${data.data.signIntegral}积分`) |
| 279 | + } else { |
| 280 | + console.log(data.message) |
| 281 | + } |
| 282 | + } else { |
| 283 | + console.log("没有返回数据") |
| 284 | + } |
| 285 | + } |
| 286 | + } catch (e) { |
| 287 | + $.logErr(e, resp) |
| 288 | + } finally { |
| 289 | + resolve(data); |
| 290 | + } |
| 291 | + }) |
| 292 | + }) |
| 293 | + } |
| 294 | + /** |
| 295 | + * |
| 296 | + * 获取文章 |
| 297 | + */ |
| 298 | + async function article() { |
| 299 | + let body = `?channel_id=${channelId[Math.floor(Math.random()*channelId.length)]}&isDiFangHao=false&is_new=1&list_count=${Math.floor(Math.random()*5+1)*10}&size=10&start=${Date.now()}` |
| 300 | + return new Promise(resolve => { |
| 301 | + $.get((taskUrl("/api/article/channel_list", body)), async (err, resp, data) => { |
| 302 | + try { |
| 303 | + if (err) { |
| 304 | + console.log(`${err}`) |
| 305 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 306 | + } else { |
| 307 | + if (data) { |
| 308 | + data = JSON.parse(data); |
| 309 | + //console.log(JSON.stringify(data)); |
| 310 | + if (data.code === 0) { |
| 311 | + $.acticleList = data.data['article_list'] |
| 312 | + } else { |
| 313 | + console.log(data.message) |
| 314 | + } |
| 315 | + } else { |
| 316 | + console.log("没有返回数据") |
| 317 | + } |
| 318 | + } |
| 319 | + } catch (e) { |
| 320 | + $.logErr(e, resp) |
| 321 | + } finally { |
| 322 | + resolve(data); |
| 323 | + } |
| 324 | + }) |
| 325 | + }) |
| 326 | + } |
| 327 | + /** |
| 328 | + * |
| 329 | + * 浏览新闻资讯 |
| 330 | + */ |
| 331 | + async function read(id) { |
| 332 | + let body = `?id=${id}` |
| 333 | + return new Promise(resolve => { |
| 334 | + $.get((taskUrl("/api/article/detail", body)), async (err, resp, data) => { |
| 335 | + try { |
| 336 | + if (err) { |
| 337 | + console.log(`${err}`) |
| 338 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 339 | + } else { |
| 340 | + if (data) { |
| 341 | + data = JSON.parse(data); |
| 342 | + //console.log(JSON.stringify(data)); |
| 343 | + if (data.code === 0) { |
| 344 | + console.log(`浏览成功!`) |
| 345 | + if (data.data['score_notify']) console.log(`浏览任务完成,获得[${data.data.score_notify.integral}]积分`) |
| 346 | + } else { |
| 347 | + console.log(data.message) |
| 348 | + } |
| 349 | + } else { |
| 350 | + console.log("没有返回数据") |
| 351 | + } |
| 352 | + } |
| 353 | + } catch (e) { |
| 354 | + $.logErr(e, resp) |
| 355 | + } finally { |
| 356 | + resolve(data); |
| 357 | + } |
| 358 | + }) |
| 359 | + }) |
| 360 | + } |
| 361 | + /** |
| 362 | + * |
| 363 | + * 分享资讯给好友 |
| 364 | + */ |
| 365 | + async function share() { |
| 366 | + let body = `member_type=3&memberType=3` |
| 367 | + return new Promise(resolve => { |
| 368 | + $.post((taskPostUrl("/api/user_mumber/doTask", body)), async (err, resp, data) => { |
| 369 | + try { |
| 370 | + if (err) { |
| 371 | + console.log(`${err}`) |
| 372 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 373 | + } else { |
| 374 | + if (data) { |
| 375 | + data = JSON.parse(data); |
| 376 | + //console.log(JSON.stringify(data)); |
| 377 | + if (data.code === 0) { |
| 378 | + console.log(`分享成功!`) |
| 379 | + if (data.data) console.log(`分享任务完成,获得[${data.data.score_notify.integral}]积分`) |
| 380 | + } else { |
| 381 | + console.log(data.message) |
| 382 | + } |
| 383 | + } else { |
| 384 | + console.log("没有返回数据") |
| 385 | + } |
| 386 | + } |
| 387 | + } catch (e) { |
| 388 | + $.logErr(e, resp) |
| 389 | + } finally { |
| 390 | + resolve(data); |
| 391 | + } |
| 392 | + }) |
| 393 | + }) |
| 394 | + } |
| 395 | + /** |
| 396 | + * |
| 397 | + * 新闻资讯评论 |
| 398 | + */ |
| 399 | + async function comment(id) { |
| 400 | + let body = `channel_article_id=${id}&content=1` |
| 401 | + return new Promise(resolve => { |
| 402 | + $.post((taskPostUrl("/api/comment/create", body)), async (err, resp, data) => { |
| 403 | + try { |
| 404 | + if (err) { |
| 405 | + console.log(`${err}`) |
| 406 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 407 | + } else { |
| 408 | + if (data) { |
| 409 | + data = JSON.parse(data); |
| 410 | + //console.log(JSON.stringify(data)); |
| 411 | + if (data.code === 0) { |
| 412 | + console.log(`评论成功!`) |
| 413 | + if (data.data) console.log(`评论任务完成,获得[${data.data.score_notify.integral}]积分`) |
| 414 | + } else { |
| 415 | + console.log(data.message) |
| 416 | + } |
| 417 | + } else { |
| 418 | + console.log("没有返回数据") |
| 419 | + } |
| 420 | + } |
| 421 | + } catch (e) { |
| 422 | + $.logErr(e, resp) |
| 423 | + } finally { |
| 424 | + resolve(data); |
| 425 | + } |
| 426 | + }) |
| 427 | + }) |
| 428 | + } |
| 429 | + /** |
| 430 | + * |
| 431 | + * 新闻资讯点赞 |
| 432 | + */ |
| 433 | + async function like(id) { |
| 434 | + let body = `id=${id}&action=true` |
| 435 | + return new Promise(resolve => { |
| 436 | + $.post((taskPostUrl("/api/favorite/like", body)), async (err, resp, data) => { |
| 437 | + try { |
| 438 | + if (err) { |
| 439 | + console.log(`${err}`) |
| 440 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 441 | + } else { |
| 442 | + if (data) { |
| 443 | + data = JSON.parse(data); |
| 444 | + //console.log(JSON.stringify(data)); |
| 445 | + if (data.code === 0) { |
| 446 | + console.log(`点赞成功!`) |
| 447 | + if (data.data) console.log(`点赞任务完成,获得[${data.data.score_notify.integral}]积分`) |
| 448 | + } else { |
| 449 | + console.log(data.message) |
| 450 | + } |
| 451 | + } else { |
| 452 | + console.log("没有返回数据") |
| 453 | + } |
| 454 | + } |
| 455 | + } catch (e) { |
| 456 | + $.logErr(e, resp) |
| 457 | + } finally { |
| 458 | + resolve(data); |
| 459 | + } |
| 460 | + }) |
| 461 | + }) |
| 462 | + } |
| 463 | + /** |
| 464 | + * |
| 465 | + * 使用本地服务 |
| 466 | + */ |
| 467 | + async function local() { |
| 468 | + let body = `member_type=6&memberType=6` |
| 469 | + return new Promise(resolve => { |
| 470 | + $.post((taskPostUrl("/api/user_mumber/doTask", body)), async (err, resp, data) => { |
| 471 | + try { |
| 472 | + if (err) { |
| 473 | + console.log(`${err}`) |
| 474 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 475 | + } else { |
| 476 | + if (data) { |
| 477 | + data = JSON.parse(data); |
| 478 | + //console.log(JSON.stringify(data)); |
| 479 | + if (data.code === 0) { |
| 480 | + console.log(`使用成功!`) |
| 481 | + if (data.data) console.log(`使用成功,获得[${data.data.score_notify.integral}]积分`) |
| 482 | + } else { |
| 483 | + console.log(data.message) |
| 484 | + } |
| 485 | + } else { |
| 486 | + console.log("没有返回数据") |
| 487 | + } |
| 488 | + } |
| 489 | + } catch (e) { |
| 490 | + $.logErr(e, resp) |
| 491 | + } finally { |
| 492 | + resolve(data); |
| 493 | + } |
| 494 | + }) |
| 495 | + }) |
| 496 | + } |
| 497 | + /** |
| 498 | + * |
| 499 | + * 助力 |
| 500 | + */ |
| 501 | + async function invite() { |
| 502 | + let body = `ref_code=GYY759` |
| 503 | + return new Promise(resolve => { |
| 504 | + $.post((taskPostUrl("/api/account/update_ref_code", body)), async (err, resp, data) => { |
| 505 | + try { |
| 506 | + if (err) { |
| 507 | + console.log(`${err}`) |
| 508 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 509 | + } else { |
| 510 | + if (data) { |
| 511 | + data = JSON.parse(data); |
| 512 | + //console.log(JSON.stringify(data)); |
| 513 | + if (data.code === 0) { |
| 514 | + console.log(`助力成功!`) |
| 515 | + } else { |
| 516 | + console.log(data.message) |
| 517 | + } |
| 518 | + } else { |
| 519 | + console.log("没有返回数据") |
| 520 | + } |
| 521 | + } |
| 522 | + } catch (e) { |
| 523 | + $.logErr(e, resp) |
| 524 | + } finally { |
| 525 | + resolve(data); |
| 526 | + } |
| 527 | + }) |
| 528 | + }) |
| 529 | + } |
| 530 | + /** |
| 531 | + * |
| 532 | + * API |
| 533 | + */ |
| 534 | + function taskUrl(type, body) { |
| 535 | + getSign(type) |
| 536 | + return { |
| 537 | + url: `https://vapp.tmuyun.com${type}${body}`, |
| 538 | + headers: { |
| 539 | + "X-SESSION-ID": sessionid, |
| 540 | + "X-REQUEST-ID": requestid, |
| 541 | + "X-TIMESTAMP": timestamp, |
| 542 | + "X-SIGNATURE": sign, |
| 543 | + "Cache-Control": `no-cache`, |
| 544 | + "X-TENANT-ID": 44, |
| 545 | + 'Host': 'vapp.tmuyun.com', |
| 546 | + 'Connection': 'Keep-Alive', |
| 547 | + "Content-Type": `application/x-www-form-urlencoded`, |
| 548 | + 'User-Agent': `1.2.2;${requestid};iPad13,4;IOS;16.2;Appstore` |
| 549 | + }, |
| 550 | + } |
| 551 | + } |
| 552 | + |
| 553 | + function taskPostUrl(type, body) { |
| 554 | + getSign(type) |
| 555 | + return { |
| 556 | + url: `https://vapp.tmuyun.com${type}`, |
| 557 | + body: `${body}`, |
| 558 | + headers: { |
| 559 | + "X-SESSION-ID": sessionid, |
| 560 | + "X-REQUEST-ID": requestid, |
| 561 | + "X-TIMESTAMP": timestamp, |
| 562 | + "X-SIGNATURE": sign, |
| 563 | + "Cache-Control": `no-cache`, |
| 564 | + "X-TENANT-ID": 44, |
| 565 | + 'Host': 'vapp.tmuyun.com', |
| 566 | + 'Connection': 'Keep-Alive', |
| 567 | + "Content-Type": `application/x-www-form-urlencoded`, |
| 568 | + 'User-Agent': `1.2.2;${requestid};iPad13,4;IOS;16.2;Appstore` |
| 569 | + }, |
| 570 | + } |
| 571 | + } |
| 572 | + /** |
| 573 | + * 获取X-SIGNATURE |
| 574 | + */ |
| 575 | + function getSign(type) { |
| 576 | + timestamp = Date.now() |
| 577 | + requestid = uuid() |
| 578 | + sign = CryptoJS.SHA256(`${type}&&${sessionid}&&${requestid}&&${timestamp}&&${salt}&&${appid}`).toString() |
| 579 | + //console.log(sign) |
| 580 | + } |
| 581 | + |
| 582 | + function uuid() { |
| 583 | + function S4() { |
| 584 | + return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); |
| 585 | + } |
| 586 | + return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); |
| 587 | + } |
| 588 | + /** |
| 589 | + * |
| 590 | + * RSA加密 |
| 591 | + */ |
| 592 | + async function RSA_Encrypt(data) { |
| 593 | + let url = { |
| 594 | + url: `https://www.bejson.com/Bejson/Api/Rsa/pubEncrypt`, |
| 595 | + headers: { |
| 596 | + "Accept": "application/json, text/javascript, */*; q=0.01", |
| 597 | + "Accept-Encoding": " gzip, deflate, br", |
| 598 | + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", |
| 599 | + "Host": "www.bejson.com", |
| 600 | + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36", |
| 601 | + }, |
| 602 | + body: `publicKey=-----BEGIN+PUBLIC+KEY-----%0D%0AMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD6XO7e9YeAOs%2BcFqwa7ETJ%2BWXizPqQeXv68i5vqw9pFREsrqiBTRcg7wB0RIp3rJkDpaeVJLsZqYm5TW7FWx%2FiOiXFc%2BzCPvaKZric2dXCw27EvlH5rq%2BzwIPDAJHGAfnn1nmQH7wR3PCatEIb8pz5GFlTHMlluw4ZYmnOwg%2BthwIDAQAB%0D%0A-----END+PUBLIC+KEY-----&encStr=${data}&etype=rsa2` |
| 603 | + } |
| 604 | + return new Promise(resolve => { |
| 605 | + $.post(url, async (err, resp, data) => { |
| 606 | + try { |
| 607 | + if (err) { |
| 608 | + console.log(`${err}`) |
| 609 | + console.log(`${$.name} API请求失败,请检查网路重试`) |
| 610 | + } else { |
| 611 | + if (data) { |
| 612 | + data = JSON.parse(data); |
| 613 | + //console.log(JSON.stringify(data)); |
| 614 | + if (data.code === 200) { |
| 615 | + |
| 616 | + } else { |
| 617 | + console.log(data.msg) |
| 618 | + } |
| 619 | + } else { |
| 620 | + console.log("没有返回数据") |
| 621 | + } |
| 622 | + } |
| 623 | + } catch (e) { |
| 624 | + $.logErr(e, resp) |
| 625 | + } finally { |
| 626 | + resolve(data.data); |
| 627 | + } |
| 628 | + }) |
| 629 | + }) |
| 630 | + } |
| 631 | + /** |
| 632 | + * |
| 633 | + * 消息推送 |
| 634 | + */ |
| 635 | + function showMsg() { |
| 636 | + message += `=== ${$.nickName} | ${$.mobile} ===\n`; |
| 637 | + message += msg |
| 638 | + //console.log(message) |
| 639 | + } |
| 640 | + /** |
| 641 | + * |
| 642 | + * cookie处理 |
| 643 | + */ |
| 644 | + function requireConfig() { |
| 645 | + if (cookie) { |
| 646 | + if (cookie.indexOf("@") != -1) { |
| 647 | + cookie.split("@").forEach((item) => { |
| 648 | + cookiesArr.push(item); |
| 649 | + }); |
| 650 | + } else if (cookie.indexOf("\n") != -1) { |
| 651 | + cookie.split("\n").forEach((item) => { |
| 652 | + cookiesArr.push(item); |
| 653 | + }); |
| 654 | + } else { |
| 655 | + cookiesArr.push(cookie); |
| 656 | + } |
| 657 | + console.log(`\n============================================= \n脚本执行 - 北京时间(UTC+8):${new Date(new Date().getTime() +new Date().getTimezoneOffset() * 3 * 1000 + 8 * 3 * 3 * 1000).toLocaleString()} \n=============================================\n`) |
| 658 | + console.log(`\n=========共有${cookiesArr.length}个${$.name}账号Cookie=========\n`); |
| 659 | + } else { |
| 660 | + console.log(`\n【缺少bgCookies环境变量或者Cookies为空!】`) |
| 661 | + return; |
| 662 | + } |
| 663 | + } |
| 664 | + /** |
| 665 | + * cookie转换 |
| 666 | + */ |
| 667 | + async function getCookie(rawCookie) { |
| 668 | + if (rawCookie.includes('#')) { |
| 669 | + $.pwd = await RSA_Encrypt(rawCookie.split('#')[1]) |
| 670 | + $.mobile = rawCookie.split('#')[0] |
| 671 | + await credential_auth() |
| 672 | + } else { |
| 673 | + sessionid = rawCookie; |
| 674 | + } |
| 675 | + } |
| 676 | + // prettier-ignore |
| 677 | + function Env(t,e){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)} |
0 commit comments