-
Notifications
You must be signed in to change notification settings - Fork 63
/
request.py
338 lines (319 loc) · 13 KB
/
request.py
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import requests
from config import token
# 根据项目id获取所有场次和在售状态
def get_sessions(show_id) -> list | None:
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json'
}
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/show/pub/v3/show/" + show_id + "/sessions_dynamic_data"
response = requests.get(url=url, headers=headers).json()
if response["statusCode"] == 200:
return response["data"]["sessionVOs"]
else:
print("get_sessions异常:" + str(response))
return None
# 根据场次id获取座位信息
def get_seat_plans(show_id, session_id) -> list:
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json'
}
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/show/pub/v3/show/" + show_id + "/show_session/" + session_id + "/seat_plans_static_data"
response = requests.get(url=url, headers=headers).json()
if response["statusCode"] == 200:
return response["data"]["seatPlans"]
else:
raise Exception("get_seat_plans异常:" + str(response))
# 获取座位余票
def get_seat_count(show_id, session_id) -> list:
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json'
}
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/show/pub/v3/show/" + show_id + "/show_session/" + session_id + "/seat_plans_dynamic_data"
response = requests.get(url=url, headers=headers).json()
if response["statusCode"] == 200:
return response["data"]["seatPlans"]
else:
raise Exception("get_seat_count异常:" + str(response))
# 获取门票类型(快递送票EXPRESS,电子票E_TICKET,现场取票VENUE,电子票或现场取票VENUE_E)
def get_deliver_method(show_id, session_id, seat_plan_id, price: int, qty: int) -> str:
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json',
'access-token': token
}
data = {
"items": [
{
"skus": [
{
"seatPlanId": seat_plan_id, # 644fcf080f4f4e0001f1519d
"sessionId": session_id, # 644fcb7dca916100017dda3d
"showId": show_id, # 644fcb2aca916100017dcfef
"skuId": seat_plan_id,
"skuType": "SINGLE",
"ticketPrice": price, # 388
"qty": qty # 2
}
],
"spu": {
"id": show_id,
"spuType": "SINGLE"
}
}
]
}
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/trade/buyer/order/v3/pre_order"
response = requests.post(url=url, headers=headers, json=data).json()
if response["statusCode"] == 200:
return response["data"]["supportDeliveries"][0]["name"]
else:
raise Exception("获取门票类型异常:" + str(response))
# 获取观演人信息
def get_audiences() -> list | None:
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json',
'access-token': token
}
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/user/buyer/v3/user_audiences"
response = requests.get(url=url, headers=headers).json()
if response["statusCode"] == 200:
return response["data"]
else:
print("get_audiences异常:" + str(response))
return None
# 获取收货地址
def get_address() -> dict | None:
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json',
'access-token': token
}
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/user/buyer/v3/user/addresses/default"
response = requests.get(url=url, headers=headers).json()
if response["statusCode"] == 200:
return response["data"]
else:
print("get_address异常:" + str(response))
return None
# 获取快递费
def get_express_fee(show_id, session_id, seat_plan_id, price: int, qty: int, location_city_id: str) -> dict:
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json',
'access-token': token
}
data = {
"items": [
{
"skus": [
{
"seatPlanId": seat_plan_id, # 644fcf080f4f4e0001f1519d
"sessionId": session_id, # 644fcb7dca916100017dda3d
"showId": show_id, # 644fcb2aca916100017dcfef
"skuId": seat_plan_id,
"skuType": "SINGLE",
"ticketPrice": price, # 388
"qty": qty, # 2
"deliverMethod": "EXPRESS"
}
],
"spu": {
"id": show_id,
"spuType": "SINGLE"
}
}
],
"locationCityId": location_city_id # 460102
}
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/trade/buyer/order/v3/price_items"
response = requests.post(url=url, headers=headers, json=data).json()
if response["statusCode"] == 200:
return response["data"][0]
else:
raise Exception("获取快递费异常:" + str(response))
# 提交订单(快递送票EXPRESS,电子票E_TICKET,现场取票VENUE,电子票或现场取票VENUE_E)
def create_order(show_id, session_id, seat_plan_id, price: int, qty: int, deliver_method, express_fee: int, receiver,
cellphone,
address_id, detail_address, location_city_id, audience_ids: list):
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36',
'Content-Type': 'application/json',
'access-token': token
}
if deliver_method == "EXPRESS":
data = {
"priceItemParam": [
{
"applyTickets": [],
"priceItemName": "票款总额",
"priceItemVal": price * qty,
"priceItemType": "TICKET_FEE",
"priceItemSpecies": "SEAT_PLAN",
"direction": "INCREASE",
"priceDisplay": "¥" + str(price * qty)
},
{
"applyTickets": [],
"priceItemName": "快递费",
"priceItemVal": express_fee,
"priceItemId": show_id,
"priceItemSpecies": "SEAT_PLAN",
"priceItemType": "EXPRESS_FEE",
"direction": "INCREASE",
"priceDisplay": "¥" + str(express_fee)
}
],
"items": [
{
"skus": [
{
"seatPlanId": seat_plan_id,
"sessionId": session_id,
"showId": show_id,
"skuId": seat_plan_id,
"skuType": "SINGLE",
"ticketPrice": price,
"qty": qty,
"deliverMethod": deliver_method
}
],
"spu": {
"id": show_id,
"spuType": "SINGLE"
}
}
],
"contactParam": {
"receiver": receiver, # 张三
"cellphone": cellphone # 13812345678
},
"one2oneAudiences": [{"audienceId": i, "sessionId": session_id} for i in audience_ids],
"addressParam": {
"address": detail_address, # 星巴克咖啡门口
"district": location_city_id[4:],
"city": location_city_id[2:4],
"province": location_city_id[0:2],
"addressId": address_id
}
}
elif deliver_method == "E_TICKET":
data = {
"priceItemParam": [
{
"applyTickets": [],
"priceItemName": "票款总额",
"priceItemVal": price * qty,
"priceItemType": "TICKET_FEE",
"priceItemSpecies": "SEAT_PLAN",
"direction": "INCREASE",
"priceDisplay": "¥" + str(price * qty)
}
],
"items": [
{
"skus": [
{
"seatPlanId": seat_plan_id,
"sessionId": session_id,
"showId": show_id,
"skuId": seat_plan_id,
"skuType": "SINGLE",
"ticketPrice": price,
"qty": qty,
"deliverMethod": deliver_method
}
],
"spu": {
"id": show_id,
"spuType": "SINGLE"
}
}
],
"many2OneAudience": {
"audienceId": audience_ids[0],
"sessionIds": [
session_id
]
}
}
elif deliver_method == "VENUE":
data = {
"priceItemParam": [
{
"applyTickets": [],
"priceItemName": "票款总额",
"priceItemVal": price * qty,
"priceItemType": "TICKET_FEE",
"priceItemSpecies": "SEAT_PLAN",
"direction": "INCREASE",
"priceDisplay": "¥" + str(price * qty)
}
],
"items": [
{
"skus": [
{
"seatPlanId": seat_plan_id,
"sessionId": session_id,
"showId": show_id,
"skuId": seat_plan_id,
"skuType": "SINGLE",
"ticketPrice": price,
"qty": qty,
"deliverMethod": deliver_method
}
],
"spu": {
"id": show_id,
"spuType": "SINGLE"
}
}
],
"one2oneAudiences": [{"audienceId": i, "sessionId": session_id} for i in audience_ids]
}
elif deliver_method == "VENUE_E":
data = {
"priceItemParam": [
{
"applyTickets": [],
"priceItemName": "票款总额",
"priceItemVal": price * qty,
"priceItemType": "TICKET_FEE",
"priceItemSpecies": "SEAT_PLAN",
"direction": "INCREASE",
"priceDisplay": "¥" + str(price * qty)
}
],
"items": [
{
"skus": [
{
"seatPlanId": seat_plan_id,
"sessionId": session_id,
"showId": show_id,
"skuId": seat_plan_id,
"skuType": "SINGLE",
"ticketPrice": price,
"qty": qty,
"deliverMethod": deliver_method
}
],
"spu": {
"id": show_id,
"spuType": "SINGLE"
}
}
]
}
else:
raise Exception("不支持的deliver_method:" + str(deliver_method))
url = "https://m.piaoxingqiu.com/cyy_gatewayapi/trade/buyer/order/v3/create_order"
response = requests.post(url=url, headers=headers, json=data).json()
if response["statusCode"] == 200:
print("下单成功!请尽快支付!")
else:
raise Exception("下单异常:" + str(response))