Skip to content

Commit d397ea2

Browse files
committed
chore: upgrade gundamGrabV4
1 parent 8f38c26 commit d397ea2

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

lib/coupons/qualityShop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function getTemplateData() {
2929
async function grabCoupon(cookie) {
3030
const tmplData = await getTemplateData(cookie)
3131
const payload = await getPayload(tmplData.gundamId, tmplData.appJs)
32-
const res = await fetch.post(`${HOST}/gundam/gundamGrabV3`, payload, {
32+
const res = await fetch.post(`${HOST}/gundam/gundamGrabV4`, payload, {
3333
cookie,
3434
headers: {
3535
Origin: actUrl.origin,

lib/coupons/takeAway.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function getTemplateData(cookie) {
3030
async function grabCoupon(cookie) {
3131
const tmplData = await getTemplateData(cookie)
3232
const payload = await getPayload(tmplData.gundamId, tmplData.appJs)
33-
const res = await fetch.post(`${HOST}/gundam/gundamGrabV3`, payload, {
33+
const res = await fetch.post(`${HOST}/gundam/gundamGrabV4`, payload, {
3434
cookie,
3535
headers: {
3636
Origin: actUrl.origin,
@@ -41,10 +41,10 @@ async function grabCoupon(cookie) {
4141
if (res.code == 0) return res.data
4242

4343
if (res.code == 3) {
44-
throw { code: ECODE.AUTH, api: 'gundamGrabV3', msg: res.msg || res.message }
44+
throw { code: ECODE.AUTH, api: 'gundamGrabV4', msg: res.msg || res.message }
4545
}
4646

47-
throw { code: ECODE.API, api: 'gundamGrabV3', msg: res.msg || res.message }
47+
throw { code: ECODE.API, api: 'gundamGrabV4', msg: res.msg || res.message }
4848
}
4949

5050
export default {

lib/payload.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import fetch from './fetch.js'
22

3+
function parseInstanceID(moduleId) {
4+
const regFloat = /(\d+\.\d+)/
5+
6+
return moduleId.match(regFloat)?.[1] ?? ''
7+
}
8+
39
function resolveMetadata(renderInfo, jsText) {
410
try {
5-
for (let id of renderInfo) {
6-
const reg = new RegExp(`red-envelope-${id}.+?(?=isOtherToAPP)`)
7-
const res = jsText.match(reg)
11+
for (const id of renderInfo) {
12+
const regRedMod = new RegExp(`red-envelope-${id}.+?(?=isOtherToAPP)`)
13+
const res = jsText.match(regRedMod)
814

9-
if (res) return eval(`({id:"${res[0]}})`)
15+
if (res) {
16+
const data = eval(`({moduleId:"${res[0]}})`)
17+
18+
data.instanceID = data.instanceID ?? parseInstanceID(data.moduleId)
19+
20+
return data
21+
}
1022
}
1123
} catch (e) {
1224
return null
@@ -49,12 +61,16 @@ async function getPayload(gundamId, appJs) {
4961
}
5062

5163
return {
52-
actualLatitude: '',
53-
actualLongitude: '',
64+
actualLatitude: 0,
65+
actualLongitude: 0,
66+
app: -1,
67+
platform: 3,
68+
couponAllConfigIdOrderString: data.expandCouponIds.keys.join(','),
5469
couponConfigIdOrderCommaString: data.priorityCouponIds.keys.join(','),
55-
defaultGrabKey: data.HideRedBagChannelId.defaultKeys.join(',') || '',
56-
grabKey: data.HideRedBagChannelId.keys.join(',') || '',
5770
gundamId: gundamId,
71+
instanceId: data.instanceID,
72+
h5Fingerprint: '',
73+
rubikCouponKey: data.cubeToken || '',
5874
needTj: data.isStopTJCoupon
5975
}
6076
}

test/payload.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ test('获取 payload', async () => {
3636

3737
return getPayload(gundamId, appJs).then((res) =>
3838
expect(res).toMatchObject({
39-
actualLatitude: '',
40-
actualLongitude: '',
39+
actualLatitude: 0,
40+
actualLongitude: 0,
4141
couponConfigIdOrderCommaString: expect.any(String),
42-
defaultGrabKey: expect.any(String),
43-
grabKey: expect.any(String),
42+
couponAllConfigIdOrderString: expect.any(String),
4443
gundamId: gundamId,
4544
needTj: expect.any(Boolean)
4645
})

0 commit comments

Comments
 (0)