-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ts
122 lines (104 loc) · 3.3 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { signURL } from "./sign.ts";
import { splitURLAndParams } from "./utils.ts";
import {
GetTicketSalesListResult,
GetUserCouponsByUserIdAndTradeIdResult,
PayOrderParams,
PayOrderResult,
QueryBookDaysByServiceIdResult,
queryUserByUserIdResult,
QueryVenueServicesResult,
SingleTicketOrderParams,
SingleTicketOrderResult,
} from "./types.ts";
export function queryUserByUserId(
netUserId: string,
): Promise<queryUserByUserIdResult> {
const url = new URL(
"https://api.xports.cn/aisports-api/api/miniApp/user/queryUserByNetUserId",
);
url.searchParams.set("netUserId", netUserId);
signURL(url);
return fetch(url).then((res) => res.json());
}
export function queryVenueServices(): Promise<QueryVenueServicesResult> {
const url = new URL(
"https://api.xports.cn/aisports-api/api/venue/queryVenueServices",
);
signURL(url);
return fetch(url).then((res) => res.json());
}
export function queryBookDaysByServiceId(
serviceId: string,
): Promise<QueryBookDaysByServiceIdResult> {
const url = new URL(
"https://api.xports.cn/aisports-api/api/miniApp/field/queryBookDays",
);
url.searchParams.set("serviceId", serviceId);
signURL(url);
return fetch(url).then((res) => res.json());
}
export function getTicketSalesList(
serviceId: string,
date: string,
): Promise<GetTicketSalesListResult> {
const url = new URL(
"https://api.xports.cn/aisports-api/api/ticket/getTicketSaleList",
);
url.searchParams.set("serviceId", serviceId);
url.searchParams.set("date", date);
signURL(url);
return fetch(url).then((res) => res.json());
}
export function getUserCouponsByUserIdAndTradeId(
newUserId: string,
tradeId: string,
): Promise<GetUserCouponsByUserIdAndTradeIdResult> {
const url = new URL(
"https://api.xports.cn/aisports-api/api/pay/getUseCoupons",
);
url.searchParams.set("netUserId", newUserId);
url.searchParams.set("tradeId", tradeId);
signURL(url);
return fetch(url).then((res) => res.json());
}
export function singleTicketOrder(
{ netUserId, serviceId, date, ticketInfo }: SingleTicketOrderParams,
): Promise<SingleTicketOrderResult> {
const url = new URL(
"https://api.xports.cn/aisports-api/api/ticket/singleTicketOrder",
);
url.searchParams.set("netUserId", netUserId);
url.searchParams.set("serviceId", serviceId);
url.searchParams.set("date", date);
url.searchParams.set("ticketInfo", JSON.stringify(ticketInfo));
signURL(url);
const [postURL, postParams] = splitURLAndParams(url);
return fetch(postURL, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: postParams.toString(),
}).then((res) => res.json());
}
export function payOrder(
{ netUserId, tradeId, payGroup }: PayOrderParams,
): Promise<PayOrderResult> {
const url = new URL(
"https://api.xports.cn/aisports-api/api/pay/payOrder",
);
url.searchParams.set("netUserId", netUserId);
url.searchParams.set("tradeId", tradeId);
url.searchParams.set("tradeTypeCode", "83");
url.searchParams.set("payGroup", JSON.stringify(payGroup));
signURL(url);
const [postURL, postParams] = splitURLAndParams(url);
return fetch(postURL, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: postParams.toString(),
}).then((res) => res.json());
}