MCPcopy Create free account
hub / github.com/Semporia/Scripts / getAllBook

Function getAllBook

jd_bookshop.js:418–446  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

416
417// 获得图书
418function getAllBook() {
419 let body = `activityId=${ACT_ID}&actorUuid=${$.actorUuid}&pin=${encodeURIComponent($.token)}`
420 return new Promise(resolve => {
421 $.post(taskPostUrl('dingzhi/book/develop/getAllBook', body), async (err, resp, data) => {
422 try {
423 if (err) {
424 console.log(`${$.name} API请求失败,请检查网路重试`)
425 } else {
426 if (safeGet(data)) {
427 data = JSON.parse(data);
428 if (data.result && data.data) {
429
430 const book = data.data.bookConfigList[0]
431 let num = Math.trunc(data.data.haveScore / book.buyBookScore)
432 console.log(`拥有${data.data.haveScore}积分,可购买${num}本`)
433 if (num > 0) {
434 await buyBook(book.uuid, num)
435 }
436 }
437 }
438 }
439 } catch (e) {
440 $.logErr(e, resp)
441 } finally {
442 resolve(data);
443 }
444 })
445 })
446}
447
448// 购买图书
449function buyBook(bookUuid, num) {

Callers 1

jdBeautyFunction · 0.85

Calls 6

buyBookFunction · 0.85
taskPostUrlFunction · 0.70
safeGetFunction · 0.70
postMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected