import axios from "axios"; import { HttpsProxyAgent } from "https-proxy-agent"; import getDateInTimezone from "./getDateInTimezone.js"; /** * 获取Web端联赛数据 * @param {*} marketType 0: 早盘赛事, 1: 今日赛事 * @param {*} locale en_US or zh_CN * @returns */ export const pinnacleWebLeagues = async (marketType = 1, locale = "zh_CN") => { const dateString = marketType == 1 ? getDateInTimezone(-4) : getDateInTimezone(-4, Date.now()+24*60*60*1000); const nowTime = Date.now(); const axiosConfig = { baseURL: "https://www.part987.com", url: "/sports-service/sv/compact/leagues", method: "GET", headers: { "accept": "application/json, text/plain, */*", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36", "x-app-data": "directusToken=TwEdnphtyxsfMpXoJkCkWaPsL2KJJ3lo;lang=zh_CN;dpVXz=ZDfaFZUP9" }, params: { btg: 1, c: "", d: dateString, l: true, mk: marketType, pa: 0, pn: -1, sp: 29, tm: 0, locale, _: nowTime, withCredentials: true }, timeout: 10000, }; const proxy = process.env.NODE_HTTP_PROXY; if (proxy) { axiosConfig.proxy = false; axiosConfig.httpsAgent = new HttpsProxyAgent(proxy); } return axios(axiosConfig).then(res => res.data?.[0]?.[2]?.map(item => { const [ id, , name ] = item; return [id, { id, name }]; }) ?? []); } /** * 获取Web比赛列表 */ export const pinnacleWebGames = async (leagues=[], marketType=1, locale="zh_CN") => { const dateString = marketType == 1 ? getDateInTimezone(-4) : getDateInTimezone(-4, Date.now()+24*60*60*1000); const nowTime = Date.now(); const axiosConfig = { baseURL: "https://www.part987.com", url: "/sports-service/sv/odds/events", method: "GET", headers: { "accept": "application/json, text/plain, */*", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36", "x-app-data": "directusToken=TwEdnphtyxsfMpXoJkCkWaPsL2KJJ3lo;lang=zh_CN;dpVXz=ZDfaFZUP9" }, params: { sp: 29, lg: leagues.join(','), ev: "", mk: marketType, btg: 1, ot: 1, d: dateString, o: 0, l: 100, v: 0, me: 0, more: false, tm: 0, pa: 0, c: "", g: "QQ==", cl: 100, pimo: "0,1,8,39,2,3,6,7,4,5", inl: false, _: nowTime, locale }, timeout: 10000, }; const proxy = process.env.NODE_HTTP_PROXY; if (proxy) { axiosConfig.proxy = false; axiosConfig.httpsAgent = new HttpsProxyAgent(proxy); } return axios(axiosConfig).then(res => res.data.n?.[0]?.[2]?.map(league => { const [leagueId, leagueName, games] = league; return games.map(game => { const [id, teamHomeName, teamAwayName, , timestamp] = game; const startTime = getDateInTimezone('+8', timestamp, true); return { id, leagueId, leagueName, teamHomeName, teamAwayName, timestamp, startTime } }) }).flat().filter(game => { const { teamHomeName, teamAwayName } = game; return !teamHomeName.startsWith('主队') && !teamAwayName.startsWith('客队'); }) ?? []); }