Skip to content

Commit

Permalink
fix: new netunion
Browse files Browse the repository at this point in the history
  • Loading branch information
vv314 committed Sep 2, 2023
1 parent 29f1bf6 commit 8bdd128
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 179 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ token=Js3xxxxFyy_Aq-rOnxMte6vKPV4AAAAA6QwAADgqRBSfcmNqyuG8CQ7JDL7xxxxNGbfF7tPNV5
3. 点击右上角 `Fork` 按钮
2. 添加 Actions secrets
1. 导航到 Fork 后的仓库主页面
2. 在仓库菜单栏中,点击 `⚙️Settings`(设置)
3. 点击侧边栏 `Secrets`(密码)条目
2. 在仓库菜单栏中,点击 `⚙️Settings`
3. 点击侧边栏 `Secrets and variables - Actions`条目
4. 点击 `New repository secret` 创建仓库密码
1.`Name` 输入框中填入 `TOKEN`
2.`Value` 输入框中填入从 cookie 中提取的 token 值(详见下文 TOKEN 配置)
2.`Secret` 输入框中填入从 cookie 中提取的 token 值(详见下文 TOKEN 配置)
5. 点击 `Add secret` 保存配置

_Fork 后的项目可执行 `npm run sync` 同步上游更新,详细参考【脚本更新】章节_
Expand Down
169 changes: 169 additions & 0 deletions lib/coupons/DCwpqO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import fetch from '../fetch.js'
import { getRenderList, getTemplateData } from '../template.js'
import { ECODE } from './const.js'

const gundamId = '1VlhFT'
const fetchStatus = {
CAN_FETCH: 0,
FETCH_ALREADY: 1,
OUT_OF_STOCK: 2,
INVALID_USER_TYPE: 3,
CANNOT_FETCH: 4,
FETCHED_BY_UUID: 5
}

function getActUrl(gundamId) {
return new URL(
`https://market.waimai.meituan.com/gd2/single.html?el_biz=waimai&el_page=gundam.loader&tenant=gundam&gundam_id=${gundamId}`
)
}

function resolveMetadata(renderList, jsText) {
try {
for (const instanceId of renderList) {
const regRedMod = new RegExp(
`gdc-new-ticket-wall-${instanceId}.+?(?=openUserCheck)`
)
const res = jsText.match(regRedMod)

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

data.instanceId = instanceId

return data
}
}
} catch (e) {
return null
}

return null
}

async function getTicketConfig(gdId, appJs) {
const renderList = await getRenderList(gdId)
const jsText = await fetch(appJs).then((res) => res.text())
const data = resolveMetadata(renderList, jsText)
const ticketConfig = data.ticketConfig.makeOptions1.ticketInfo1

return {
...ticketConfig,
instanceId: data.instanceId
}
}

async function getParams(gdId, channelUrl, instanceId) {
return {
couponReferId: channelUrl,
actualLng: 0,
actualLat: 0,
geoType: 2,
versiom: 1,
isInDpEnv: 0,
gdPageId: gdId,
instanceId: instanceId
}
}

function formatCoupons(coupons, info) {
return coupons.map((item) => ({
name: item.couponName,
etime: item.couponEndTime,
amount: item.couponValue,
amountLimit: item.priceLimit,
useCondition: info.useCondition ?? '',
actName: info.actName
}))
}

async function getLotteryInfo(cookie, couponIds) {
const res = await fetch.get(
`https://promotion.waimai.meituan.com/lottery/couponcomponent/info/v2`,
{
cookie,
params: {
couponReferIds: couponIds.join(','),
actualLng: 0,
actualLat: 0,
geoType: 2,
sceneId: 1,
isInDpEnv: 0,
cType: 'wm_wxapp'
}
}
)
const couponList = res.data.couponList.filter(
(data) =>
data.status === fetchStatus.CAN_FETCH ||
data.status === fetchStatus.FETCH_ALREADY
)

return couponList
}

async function grabCoupon(cookie) {
const actUrl = getActUrl(gundamId)
const tmplData = await getTemplateData(cookie, gundamId)
const ticketConfig = await getTicketConfig(tmplData.gdId, tmplData.appJs)
const lotteryCoupons = await getLotteryInfo(cookie, [
ticketConfig.channelUrl ?? ''
])
const results = []

for (const coupon of lotteryCoupons) {
if (coupon.status === fetchStatus.FETCH_ALREADY) {
results.push(coupon)

continue
}

const res = await fetch.post(
`https://promotion.waimai.meituan.com/lottery/couponcomponent/fetchcomponentcoupon/v2`,
{
appVersion: '',
cType: 'wm_wxapp',
fpPlatform: 3,
mtFingerprint: '',
wxOpenId: ''
},
{
cookie,
params: {
couponReferId: coupon.couponReferId,
actualLng: 0,
actualLat: 0,
geoType: 2,
version: 1,
isInDpEnv: 0,
gdPageId: tmplData.gdId,
pageId: tmplData.pageId,
instanceId: ticketConfig.instanceId ?? '',
sceneId: 1
},
headers: {
mtgsig: '{}',
Origin: actUrl.origin,
Referer: actUrl.origin + '/'
}
}
)

if (res.code == 0) {
results.push(coupon)
} else {
// console.log('抢券失败', res)
}
}

return formatCoupons(results, {
actName: tmplData.actName,
useCondition: ticketConfig.desc
})
}

export default {
grabCoupon: grabCoupon,
getActUrl: getActUrl
}
export { getParams }
8 changes: 7 additions & 1 deletion lib/coupons/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ const ECODE = {
}
const HOST = 'https://mediacps.meituan.com'

export { ECODE, HOST }
const couponId = {
main: { gid: '2KAWnD', name: '外卖红包' },
shop: { gid: '4luWGh', name: '品质优惠天天领' }
// { gid: '1VlhFT', aid: '443084', name: '周末小吃街' }
}

export { couponId, ECODE, HOST }
56 changes: 56 additions & 0 deletions lib/coupons/gundamGrab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import fetch from '../fetch.js'
import { getTemplateData } from '../template.js'
import getPayload from '../payload.js'
import { ECODE, HOST } from './const.js'

function getActUrl(gundamId) {
return new URL(
`https://market.waimai.meituan.com/gd/single.html?el_biz=waimai&el_page=gundam.loader&gundam_id=${gundamId}`
)
}

function formatCoupons(coupons, actName) {
return coupons.map((item) => ({
name: item.couponName,
etime: item.etime,
amount: item.couponAmount,
amountLimit: item.amountLimit,
useCondition: item.useCondition,
actName: actName
}))
}

async function grabCoupon(cookie, gundamId) {
const actUrl = getActUrl(gundamId)
const tmplData = await getTemplateData(cookie, gundamId)
const payload = await getPayload(tmplData.gdId, tmplData.appJs)
const res = await fetch.post(`${HOST}/gundam/gundamGrabV4`, payload, {
cookie,
headers: {
Origin: actUrl.origin,
Referer: actUrl.origin + '/'
}
})

if (res.code == 0) {
return formatCoupons(res.data.coupons, tmplData.actName)
}

const apiInfo = {
api: 'gundamGrabV4',
name: tmplData.actName,
msg: res.msg || res.message
}

if (res.code == 3) {
throw { code: ECODE.AUTH, ...apiInfo }
}

throw { code: ECODE.API, ...apiInfo }
}

export default {
grabCoupon: grabCoupon,
getActUrl: getActUrl
}
export { getPayload }
53 changes: 26 additions & 27 deletions lib/coupons/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetch, { createCookieJar } from '../fetch.js'
import qualityShop from './qualityShop.js'
import takeAwayCoupon from './takeAway.js'
import { ECODE, HOST } from './const.js'
import gundamGrab from './gundamGrab.js'
import DCwpqO from './DCwpqO.js'
import { couponId, ECODE, HOST } from './const.js'

function createMTCookie(token) {
const cookieJar = createCookieJar(token)
Expand Down Expand Up @@ -40,47 +40,46 @@ async function getUserInfo(cookie) {
throw { code: ECODE.API, api: 'gundamLogin', msg: res.msg || res.message }
}

function formatCoupons(coupons) {
return coupons.map((item) => ({
name: item.couponName,
etime: item.etime,
amount: item.couponAmount,
amountLimit: item.amountLimit,
useCondition: item.useCondition
}))
}

async function runTask(cookie) {
try {
// 优先检测登录状态
const userInfo = await getUserInfo(cookie)
let grabResult = []
const grabResult = []

const takeAwayCouponResult = await takeAwayCoupon.grabCoupon(cookie)
// 主活动,失败时向外抛出异常
const mainResult = await gundamGrab.grabCoupon(cookie, couponId.main.gid)

grabResult = grabResult.concat(takeAwayCouponResult.coupons)
grabResult.push(...mainResult)

try {
const qualityShopCouponResult = await qualityShop.grabCoupon(cookie)

grabResult = grabResult.concat(qualityShopCouponResult.coupons)
} catch (e) {
// 品质商家红包仅对某些用户群体生效
const qualityShopResult = await gundamGrab.grabCoupon(
cookie,
couponId.shop.gid
)

grabResult.push(...qualityShopResult)
} catch {
// 仅对某些用户群体生效
}

// try {
// const DCwpqOResult = await DCwpqO.grabCoupon(cookie)

// grabResult.push(...DCwpqOResult)
// } catch (e) {
// console.log('eeee', e)
// // 仅对某些用户群体生效
// }

return {
code: ECODE.SUCC,
data: {
user: userInfo,
coupons: formatCoupons(grabResult)
coupons: grabResult
},
msg: '成功'
}
} catch (e) {
const data = {
// seems no usage and references
actUrl: takeAwayCoupon.getActUrl().href
}
let code, msg

// console.log('getCoupons error', e)
Expand All @@ -104,7 +103,7 @@ async function runTask(cookie) {
msg = '程序异常'
}

return { code, data, msg, error: e }
return { code, msg, error: e }
}
}

Expand Down
52 changes: 0 additions & 52 deletions lib/coupons/qualityShop.js

This file was deleted.

Loading

0 comments on commit 8bdd128

Please sign in to comment.