Skip to content

Commit

Permalink
Merge pull request vv314#44 from vv314/fix/grebAPI
Browse files Browse the repository at this point in the history
chore: upgrade gundamGrabV4
  • Loading branch information
vv314 authored Feb 26, 2023
2 parents 8f38c26 + d397ea2 commit 29f1bf6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/coupons/qualityShop.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function getTemplateData() {
async function grabCoupon(cookie) {
const tmplData = await getTemplateData(cookie)
const payload = await getPayload(tmplData.gundamId, tmplData.appJs)
const res = await fetch.post(`${HOST}/gundam/gundamGrabV3`, payload, {
const res = await fetch.post(`${HOST}/gundam/gundamGrabV4`, payload, {
cookie,
headers: {
Origin: actUrl.origin,
Expand Down
6 changes: 3 additions & 3 deletions lib/coupons/takeAway.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function getTemplateData(cookie) {
async function grabCoupon(cookie) {
const tmplData = await getTemplateData(cookie)
const payload = await getPayload(tmplData.gundamId, tmplData.appJs)
const res = await fetch.post(`${HOST}/gundam/gundamGrabV3`, payload, {
const res = await fetch.post(`${HOST}/gundam/gundamGrabV4`, payload, {
cookie,
headers: {
Origin: actUrl.origin,
Expand All @@ -41,10 +41,10 @@ async function grabCoupon(cookie) {
if (res.code == 0) return res.data

if (res.code == 3) {
throw { code: ECODE.AUTH, api: 'gundamGrabV3', msg: res.msg || res.message }
throw { code: ECODE.AUTH, api: 'gundamGrabV4', msg: res.msg || res.message }
}

throw { code: ECODE.API, api: 'gundamGrabV3', msg: res.msg || res.message }
throw { code: ECODE.API, api: 'gundamGrabV4', msg: res.msg || res.message }
}

export default {
Expand Down
32 changes: 24 additions & 8 deletions lib/payload.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import fetch from './fetch.js'

function parseInstanceID(moduleId) {
const regFloat = /(\d+\.\d+)/

return moduleId.match(regFloat)?.[1] ?? ''
}

function resolveMetadata(renderInfo, jsText) {
try {
for (let id of renderInfo) {
const reg = new RegExp(`red-envelope-${id}.+?(?=isOtherToAPP)`)
const res = jsText.match(reg)
for (const id of renderInfo) {
const regRedMod = new RegExp(`red-envelope-${id}.+?(?=isOtherToAPP)`)
const res = jsText.match(regRedMod)

if (res) return eval(`({id:"${res[0]}})`)
if (res) {
const data = eval(`({moduleId:"${res[0]}})`)

data.instanceID = data.instanceID ?? parseInstanceID(data.moduleId)

return data
}
}
} catch (e) {
return null
Expand Down Expand Up @@ -49,12 +61,16 @@ async function getPayload(gundamId, appJs) {
}

return {
actualLatitude: '',
actualLongitude: '',
actualLatitude: 0,
actualLongitude: 0,
app: -1,
platform: 3,
couponAllConfigIdOrderString: data.expandCouponIds.keys.join(','),
couponConfigIdOrderCommaString: data.priorityCouponIds.keys.join(','),
defaultGrabKey: data.HideRedBagChannelId.defaultKeys.join(',') || '',
grabKey: data.HideRedBagChannelId.keys.join(',') || '',
gundamId: gundamId,
instanceId: data.instanceID,
h5Fingerprint: '',
rubikCouponKey: data.cubeToken || '',
needTj: data.isStopTJCoupon
}
}
Expand Down
7 changes: 3 additions & 4 deletions test/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ test('获取 payload', async () => {

return getPayload(gundamId, appJs).then((res) =>
expect(res).toMatchObject({
actualLatitude: '',
actualLongitude: '',
actualLatitude: 0,
actualLongitude: 0,
couponConfigIdOrderCommaString: expect.any(String),
defaultGrabKey: expect.any(String),
grabKey: expect.any(String),
couponAllConfigIdOrderString: expect.any(String),
gundamId: gundamId,
needTj: expect.any(Boolean)
})
Expand Down

0 comments on commit 29f1bf6

Please sign in to comment.