import type { ApiResponse } from "@/lib/api" import type { ShuidiGame, ShuidiOrderInfo, ShuidiOrderResult, ShuidiPackageList, ShuidiRegion, } from "@/lib/models/shuidi" import { phpFetch, phpPost } from "./http" // ==================== 水滴静态/固态(jinyou) ==================== // - 游戏列表:POST /jinyou/api/gameList(不带 cookie) // - 套餐列表:POST /jinyou/Jinyoujt/getPackage?type=1(1:静态 2:固态),需带 cookie // - 线路列表:GET /jinyou/api/regionSurplusOuts?product_id=&is_unshar=&game_id=(不带 cookie) type JinyouResult = { code: number msg?: string data?: T } export async function fetchShuidiGameList(): Promise< ApiResponse > { const res = await phpFetch>( "POST", "/jinyou/api/gameList", ) if (!res.success) return res const data = res.data?.data return { success: true, data: Array.isArray(data) ? data : [], } } export async function fetchShuidiPackages( type: 1 | 2 = 1, ): Promise> { const res = await phpPost>( `/jinyou/Jinyoujt/getPackage?type=${type}`, { cookie: document.cookie }, ) if (!res.success) return res const data = res.data?.data if (!data || typeof data !== "object") { return { success: true, data: { game: {}, line: {} } } } return { success: true, data: { game: data.game ?? {}, line: data.line ?? {}, }, } } export async function fetchShuidiRegions(params: { product_id: number is_unshar: 0 | 1 game_id: number | "" }): Promise> { const query = new URLSearchParams({ product_id: String(params.product_id), is_unshar: String(params.is_unshar), game_id: String(params.game_id), }) // 余量数据时效性强,禁止浏览器缓存 const res = await phpFetch>( "GET", `/jinyou/api/regionSurplusOuts?${query.toString()}`, undefined, { cache: "no-store" }, ) if (!res.success) return res const region = res.data?.data?.region if (!region || typeof region !== "object") { return { success: true, data: { province_surplus_outs: {} }, } } return { success: true, data: { surplus_out_total: region.surplus_out_total, province_surplus_outs: region.province_surplus_outs ?? {}, }, } } // ==================== 下单 ==================== // 与 juipnet Index.cshtml pay() 一致:body 为 { cookie, order_info } // code 1-开通成功 2-返回支付宝支付主体 3-返回微信支付主体 -1-错误 export async function createShuidiOrder( orderInfo: ShuidiOrderInfo, ): Promise> { const res = await phpPost>( "/jinyou/jinyoujt/create_order", { cookie: document.cookie, order_info: orderInfo }, ) if (!res.success) return res const raw = res.data ?? {} return { success: true, data: { code: Number(raw.code) || 0, msg: typeof raw.msg === "string" ? raw.msg : undefined, data: typeof raw.data === "string" ? raw.data : undefined, }, } }