Skip to content

Commit 0f14566

Browse files
committed
更新[京东618]: 1.增加商店签到, 2.优化等待时间 感谢 @Wenmoux
1 parent e7a715b commit 0f14566

2 files changed

Lines changed: 168 additions & 26 deletions

File tree

jd/jd.618.adapt.js

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $.VAL_headers = $.getdata('chavy_headers_jd816')
77
$.log('', `🔔 ${$.name}, 开始!`, '')
88
await getData()
99
await getActs()
10+
await getShops()
1011
await execActs()
1112
showmsg()
1213
})()
@@ -38,6 +39,31 @@ function getData() {
3839
})
3940
}
4041

42+
function getShops() {
43+
return new Promise((resove) => {
44+
$.post(taskurl('cakebaker_bigBrandHomeData'), (error, response, data) => {
45+
try {
46+
$.log(`❕ ${$.name}, 获取商店!`)
47+
if (error) throw new Error(error)
48+
$.shopActs = []
49+
JSON.parse(data).data.result.bigBrandList.forEach((_shopa) => {
50+
const _shopact = {
51+
_raw: _shopa,
52+
id: _shopa.venderId,
53+
name: _shopa.name,
54+
}
55+
$.shopActs.push(_shopact)
56+
})
57+
$.log(` 商店数量 = ${$.shopActs.length}`, '')
58+
} catch (e) {
59+
$.log(`❗️ ${$.name}, 获取商店!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
60+
} finally {
61+
resove()
62+
}
63+
})
64+
})
65+
}
66+
4167
function getActs() {
4268
return new Promise((resove) => {
4369
$.post(taskurl('cakebaker_getTaskDetail'), (error, response, data) => {
@@ -97,10 +123,16 @@ async function execActs() {
97123
$.log(` ${subataskIdx + 1}. ${subatask.name.slice(0, 15)}...`)
98124
await sendtask(subact, subatask, true)
99125
$.log(` @认领任务: ${subatask.isClaimSuc ? '🟢' : '🔴'}`)
100-
$.log(` @等待: ${subact.waitDuration} 秒`)
101-
await new Promise($.wait(subact.waitDuration * 1000))
102-
await sendtask(subact, subatask)
103-
$.log(` @完成任务: ${subatask.isExecSuc ? '🟢' : '🔴'}`, '')
126+
if (subatask.isskip) {
127+
$.log(` @跳过: ${subatask.msg}`)
128+
$.log(` @等待: 0.5 秒`, '')
129+
await new Promise($.wait(500))
130+
} else {
131+
$.log(` @等待: ${subact.waitDuration} 秒`)
132+
await new Promise($.wait(subact.waitDuration * 1000))
133+
await sendtask(subact, subatask)
134+
$.log(` @完成任务: ${subatask.isExecSuc ? '🟢' : '🔴'}`, '')
135+
}
104136
}
105137
$.log('')
106138
}
@@ -112,15 +144,33 @@ async function execActs() {
112144
$.log(` ${taskIdx + 1}. ${task.name}`)
113145
await sendtask(_act, task, true)
114146
$.log(` @认领任务: ${task.isClaimSuc ? '🟢' : '🔴'}`)
115-
$.log(` @等待: ${_act.waitDuration} 秒`)
116-
await new Promise($.wait(_act.waitDuration * 1000))
117-
await sendtask(_act, task)
118-
$.log(` @完成任务: ${task.isExecSuc ? '🟢' : '🔴'}`, '')
147+
if (task.isskip || task.ishot) {
148+
$.log(` @跳过: ${task.msg}`)
149+
$.log(` @等待: 0.5 秒`, '')
150+
await new Promise($.wait(500))
151+
} else {
152+
$.log(` @等待: ${_act.waitDuration} 秒`)
153+
await new Promise($.wait(_act.waitDuration * 1000))
154+
await sendtask(_act, task)
155+
$.log(` @完成任务: ${task.isExecSuc ? '🟢' : '🔴'}`, '')
156+
}
119157
}
120158
$.log('')
121159
}
122160
$.log('')
123161
}
162+
163+
// 商店签到
164+
$.log(` ${$.acts.length + 1}. 商店签到 (${$.shopActs.length})`)
165+
for (let _shopIdx = 0; _shopIdx < $.shopActs.length; _shopIdx++) {
166+
const shop = $.shopActs[_shopIdx]
167+
$.log(` ${_shopIdx + 1}. ${shop.name}`)
168+
await signshop(shop)
169+
shop.msg = /,/.test(shop.msg) ? shop.msg.split(',')[1] : shop.msg
170+
$.log(` @签到: ${shop.isSuc ? '🟢 已领取!' : shop.code === 402 ? '⚪️ 无效活动!' : `🔴 ${shop.msg}`}`)
171+
$.log(` @等待: 1 秒`, '')
172+
await new Promise($.wait(1000))
173+
}
124174
}
125175

126176
// 商品类活动
@@ -171,19 +221,40 @@ function sendtask(act, task, isClaim = false) {
171221
safeStr: JSON.stringify({ secretp: $.secretp }),
172222
}
173223

174-
if (isClaim) task.isClaimSuc = true
175-
else task.isExecSuc = true
176-
resove()
177-
178224
$.post(taskurl('cakebaker_ckCollectScore', JSON.stringify(body)), (error, response, data) => {
179225
try {
180226
const _data = JSON.parse(data)
181-
const _issuc = _data.data.bizCode === 0
227+
const _issuc = _data.data.bizCode === 0 || _data.data.bizCode === -5 || _data.data.bizCode === -15
182228
if (isClaim) task.isClaimSuc = _issuc
183229
else task.isExecSuc = _issuc
230+
task.isskip = _data.data.bizCode === -5
231+
task.ishot = _data.data.bizCode === -15
232+
task.msg = _data.data.bizMsg || '无'
184233
} catch (e) {
185234
if (isClaim) task.isClaimSuc = false
186235
else task.isExecSuc = false
236+
task.isskip = false
237+
task.ishot = false
238+
task.msg = error || e
239+
} finally {
240+
resove()
241+
}
242+
})
243+
})
244+
}
245+
246+
function signshop(shop) {
247+
return new Promise((resove) => {
248+
const body = { channel: 2, venderId: shop.id }
249+
$.post(taskurl('interact_center_sign_collectGift', JSON.stringify(body)), (error, response, data) => {
250+
try {
251+
const _data = JSON.parse(data)
252+
shop.isSuc = _data.code === 407000005 || _data.code === 200 ? true : false
253+
shop.code = _data.code
254+
shop.msg = _data.msg
255+
} catch (e) {
256+
shop.isSuc = false
257+
shop.msg = error || e
187258
} finally {
188259
resove()
189260
}

jd/jd.618.js

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $.VAL_headers = $.getdata('chavy_headers_jd816')
77
$.log('', `🔔 ${$.name}, 开始!`, '')
88
await getData()
99
await getActs()
10+
await getShops()
1011
await execActs()
1112
showmsg()
1213
})()
@@ -38,6 +39,31 @@ function getData() {
3839
})
3940
}
4041

42+
function getShops() {
43+
return new Promise((resove) => {
44+
$.post(taskurl('cakebaker_bigBrandHomeData'), (error, response, data) => {
45+
try {
46+
$.log(`❕ ${$.name}, 获取商店!`)
47+
if (error) throw new Error(error)
48+
$.shopActs = []
49+
JSON.parse(data).data.result.bigBrandList.forEach((_shopa) => {
50+
const _shopact = {
51+
_raw: _shopa,
52+
id: _shopa.venderId,
53+
name: _shopa.name,
54+
}
55+
$.shopActs.push(_shopact)
56+
})
57+
$.log(` 商店数量 = ${$.shopActs.length}`, '')
58+
} catch (e) {
59+
$.log(`❗️ ${$.name}, 获取商店!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, `data = ${data}`, '')
60+
} finally {
61+
resove()
62+
}
63+
})
64+
})
65+
}
66+
4167
function getActs() {
4268
return new Promise((resove) => {
4369
$.post(taskurl('cakebaker_getTaskDetail'), (error, response, data) => {
@@ -97,10 +123,16 @@ async function execActs() {
97123
$.log(` ${subataskIdx + 1}. ${subatask.name.slice(0, 15)}...`)
98124
await sendtask(subact, subatask, true)
99125
$.log(` @认领任务: ${subatask.isClaimSuc ? '🟢' : '🔴'}`)
100-
$.log(` @等待: ${subact.waitDuration} 秒`)
101-
await new Promise($.wait(subact.waitDuration * 1000))
102-
await sendtask(subact, subatask)
103-
$.log(` @完成任务: ${subatask.isExecSuc ? '🟢' : '🔴'}`, '')
126+
if (subatask.isskip) {
127+
$.log(` @跳过: ${subatask.msg}`)
128+
$.log(` @等待: 0.5 秒`, '')
129+
await new Promise($.wait(500))
130+
} else {
131+
$.log(` @等待: ${subact.waitDuration} 秒`)
132+
await new Promise($.wait(subact.waitDuration * 1000))
133+
await sendtask(subact, subatask)
134+
$.log(` @完成任务: ${subatask.isExecSuc ? '🟢' : '🔴'}`, '')
135+
}
104136
}
105137
$.log('')
106138
}
@@ -112,15 +144,33 @@ async function execActs() {
112144
$.log(` ${taskIdx + 1}. ${task.name}`)
113145
await sendtask(_act, task, true)
114146
$.log(` @认领任务: ${task.isClaimSuc ? '🟢' : '🔴'}`)
115-
$.log(` @等待: ${_act.waitDuration} 秒`)
116-
await new Promise($.wait(_act.waitDuration * 1000))
117-
await sendtask(_act, task)
118-
$.log(` @完成任务: ${task.isExecSuc ? '🟢' : '🔴'}`, '')
147+
if (task.isskip || task.ishot) {
148+
$.log(` @跳过: ${task.msg}`)
149+
$.log(` @等待: 0.5 秒`, '')
150+
await new Promise($.wait(500))
151+
} else {
152+
$.log(` @等待: ${_act.waitDuration} 秒`)
153+
await new Promise($.wait(_act.waitDuration * 1000))
154+
await sendtask(_act, task)
155+
$.log(` @完成任务: ${task.isExecSuc ? '🟢' : '🔴'}`, '')
156+
}
119157
}
120158
$.log('')
121159
}
122160
$.log('')
123161
}
162+
163+
// 商店签到
164+
$.log(` ${$.acts.length + 1}. 商店签到 (${$.shopActs.length})`)
165+
for (let _shopIdx = 0; _shopIdx < $.shopActs.length; _shopIdx++) {
166+
const shop = $.shopActs[_shopIdx]
167+
$.log(` ${_shopIdx + 1}. ${shop.name}`)
168+
await signshop(shop)
169+
shop.msg = /,/.test(shop.msg) ? shop.msg.split(',')[1] : shop.msg
170+
$.log(` @签到: ${shop.isSuc ? '🟢 已领取!' : shop.code === 402 ? '⚪️ 无效活动!' : `🔴 ${shop.msg}`}`)
171+
$.log(` @等待: 1 秒`, '')
172+
await new Promise($.wait(1000))
173+
}
124174
}
125175

126176
// 商品类活动
@@ -171,19 +221,40 @@ function sendtask(act, task, isClaim = false) {
171221
safeStr: JSON.stringify({ secretp: $.secretp }),
172222
}
173223

174-
if (isClaim) task.isClaimSuc = true
175-
else task.isExecSuc = true
176-
resove()
177-
178224
$.post(taskurl('cakebaker_ckCollectScore', JSON.stringify(body)), (error, response, data) => {
179225
try {
180226
const _data = JSON.parse(data)
181-
const _issuc = _data?.data?.bizCode === 0
227+
const _issuc = _data.data.bizCode === 0 || _data.data.bizCode === -5 || _data.data.bizCode === -15
182228
if (isClaim) task.isClaimSuc = _issuc
183229
else task.isExecSuc = _issuc
230+
task.isskip = _data.data.bizCode === -5
231+
task.ishot = _data.data.bizCode === -15
232+
task.msg = _data.data.bizMsg || '无'
184233
} catch (e) {
185234
if (isClaim) task.isClaimSuc = false
186235
else task.isExecSuc = false
236+
task.isskip = false
237+
task.ishot = false
238+
task.msg = error || e
239+
} finally {
240+
resove()
241+
}
242+
})
243+
})
244+
}
245+
246+
function signshop(shop) {
247+
return new Promise((resove) => {
248+
const body = { channel: 2, venderId: shop.id }
249+
$.post(taskurl('interact_center_sign_collectGift', JSON.stringify(body)), (error, response, data) => {
250+
try {
251+
const _data = JSON.parse(data)
252+
shop.isSuc = _data.code === 407000005 || _data.code === 200 ? true : false
253+
shop.code = _data.code
254+
shop.msg = _data.msg
255+
} catch (e) {
256+
shop.isSuc = false
257+
shop.msg = error || e
187258
} finally {
188259
resove()
189260
}

0 commit comments

Comments
 (0)