-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathPolyt.cs
334 lines (303 loc) · 12.7 KB
/
Polyt.cs
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
using AutoTicket.Model.Polyt;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutoTicket
{
public class Polyt : BaseTicket
{
private const string checkLoginUrl = "https://platformpcgateway.polyt.cn/api/1.0/login/getLoginUser";
private const string showInfoDetailUrl = "https://platformpcgateway.polyt.cn/api/1.0/show/getShowInfoDetail";
private const string sellSeatListUrl = "https://platformpcgateway.polyt.cn/api/1.0/seat/getSellSeatList";
private const string commitOrder = "https://platformpcgateway.polyt.cn/api/1.0/platformOrder/commitOrderOnSeat";
private const string createOrder = "https://platformpcgateway.polyt.cn/api/1.0/platformOrder/createOrder";
#region 跳转至选座页面必填参数
private readonly string projectId;
private readonly string productId;
private readonly string theaterId;
#endregion
public Polyt()
{
var targetUrl = Appsetting.GetTargetUrl();
var infoArray = targetUrl.Replace(targetUrl.Remove(targetUrl.IndexOf("show")), "").Split("/");
theaterId = infoArray[2];
productId = infoArray[3];
projectId = infoArray[1];
}
public override void Start()
{
base.Start();
if (!VerifyCookie())
{
Console.WriteLine("Cookie失效或已过期,请在Appsetting.json填写正确Cookie并重新启动");
return;
}
Task.Run(() => UltraTicket(null));
var taskCount = int.Parse(Appsetting.Get("TaskCount"));
var proxyIPs = ProxyHelper.GetProxy(taskCount);
for (var i = 0; i < taskCount; i++)
{
var index = i;
Task.Run(() => UltraTicket(proxyIPs[index]));
}
}
/// <summary>
/// 超级抢票
/// </summary>
private async void UltraTicket(ProxyIP proxyIP)
{
IWebProxy proxy = null;
DateTime expireTime = new DateTime(9999,12, 30);
if (proxyIP is not null)
{
proxy = new WebProxy(proxyIP.iP, proxyIP.port);
expireTime = proxyIP.expire_time;
}
TicketResp targetTicket = null;
List<int> sellSeats;//可售座位
SeatsInfo allSeats;//座位信息
int targetSeatId = 0;//目标座位Id
List<int> priceChoose;
List<int> dayChoose;
while (_status == 1)
{
if(DateTime.Now < showStartTime)
{
Thread.Sleep(1);
continue;
}
try
{
dayChoose = Appsetting.GetPositionIndex().ToList();//抢的日期下标标
priceChoose = Appsetting.GetPriceIndex().ToList();//抢的票档
targetTicket = await ChoosePriceAsync(proxy, dayChoose, priceChoose);
if (targetTicket is not null)
{
sellSeats = await GetSellSeats(targetTicket.SectionId, targetTicket.ShowId, proxy);
if (sellSeats?.Count > 0)
{
allSeats = await GetSeatsInfoAsync(proxy, targetTicket.ShowId, targetTicket.SectionId);
if (allSeats is not null)
{
targetSeatId = GetTargetSeatId(allSeats, targetTicket.PriceId, sellSeats);
if (targetSeatId != 0)
{
var newOrder = await CreateOrder(proxy, targetTicket, targetSeatId);
if (newOrder.code == 200 && !string.IsNullOrWhiteSpace(newOrder.data))
{
var commitOrder = await Pay(proxy, newOrder.data);
if (commitOrder.code == 200)
{
Console.WriteLine("抢票成功,请前往App我的订单查看并支付");
Stop();
break;
}
else if (commitOrder.msg.Contains("待支付"))
{
Console.WriteLine(commitOrder.msg);
Stop();
break;
}
}
}
}
}
}
if((expireTime - DateTime.Now).TotalSeconds <= 30)
{
var newProxy = ProxyHelper.GetProxy();
proxy = new WebProxy(newProxy.iP, newProxy.port);
expireTime = newProxy.expire_time;
}
Console.WriteLine($"第{TryCount}次抢票");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
if (e.Message.Contains("405"))
{
var newProxy = ProxyHelper.GetProxy();
proxy = new WebProxy(newProxy.iP, newProxy.port);
expireTime = newProxy.expire_time;
}
}
finally
{
Thread.Sleep(1500);
TryCount++;
}
}
}
/// <summary>
/// 创建订单
/// </summary>
/// <returns></returns>
public async Task<RespModel<string>> CreateOrder(IWebProxy proxy, TicketResp targetTicket, int targetSeatId)
{
var reqMode = new
{
channelId = "",
projectId = this.projectId,
seriesId = "",
showId = targetTicket.ShowId,
showTime = targetTicket.DateTime,
priceList = new TicketOrder[]{ new TicketOrder()
{
count = 1,
freeTicketCount = 1,
priceId = targetTicket.PriceId,
seat = targetSeatId
}},
requestModel = new PolytReqModel()
};
var resp = await PostAsync(commitOrder, JsonHelper.ObjToJson(reqMode), proxy);
var obj = JsonHelper.JsonToObj<RespModel<string>>(resp);
return obj;
}
private async Task<RespModel<dynamic>> Pay(IWebProxy proxy, string uuid)
{
var reqMode = new {
consignee = Appsetting.Get("PeopleName"),
consigneePhonr = Appsetting.Get("Phone"),
deliveryWay = "01",
movieIds = "",
orderFreightAmt = 0,
payWayCode = "06",
requestModel = new PolytReqModel(),
seriesId = "",
uuid = uuid
};
var resp = await PostAsync(createOrder, JsonHelper.ObjToJson(reqMode), proxy);
var obj = JsonHelper.JsonToObj<RespModel<dynamic>>(resp);
return obj;
}
private int GetTargetSeatId(SeatsInfo allSeats, int priceId, List<int> sellSeats)
{
var ComplySeats = allSeats.seatList.Where(s => s.p == priceId && sellSeats.Contains(s.sd)).ToList();//符合条件的位置
return Tools.ListRandom(ComplySeats).FirstOrDefault()?.sd ?? 0;
}
/// <summary>
/// 获取座位信息
/// </summary>
public async Task<SeatsInfo> GetSeatsInfoAsync(IWebProxy proxy, string showId, string sectionId)
{
var resp = await GetAsync("https://cdn.polyt.cn/seat/h5/" + showId + "_"+ sectionId + ".json?callback=jsonpCallback", proxy);
resp = resp.Replace("jsonpCallback(", "").TrimEnd(')').TrimEnd('"');
var data = JsonHelper.JsonToObj<RespModel<string>>(resp).data;
var allSeats = JsonHelper.JsonToObj<SeatsInfo>(data);
if(allSeats is null)
{
Console.WriteLine("获取位置描述信息失败");
return null;
}
return allSeats;
}
/// <summary>
/// 获取可售座位
/// </summary>
/// <returns></returns>
public async Task<List<int>> GetSellSeats(string sectionId, string showId, IWebProxy proxy)
{
var reqModel = new
{
sectionId = sectionId,
showId = showId,
requestModel = new PolytReqModel()
};
var resp = await PostAsync(sellSeatListUrl, JsonHelper.ObjToJson(reqModel), proxy);
var model = JsonHelper.JsonToObj<RespModel<SellSeatsId>>(resp);
if (model.code != 200)
{
Console.WriteLine("座位已全部售出");
return null;
}
var sellSeats = model.data?.sellSeatIds ?? new List<int>();
return sellSeats;
}
/// <summary>
/// 选择票
/// </summary>
public async Task<TicketResp> ChoosePriceAsync(IWebProxy proxy, List<int> dayChoose, List<int> priceChoose)
{
var reqModel = new
{
productId = this.productId,
projectId = this.projectId,
theaterId = this.theaterId,
requestModel = new PolytReqModel()
};
var resp = await PostAsync(showInfoDetailUrl, JsonHelper.ObjToJson(reqModel), proxy);
if (resp.Contains("请求失败"))
{
Console.WriteLine("请求失败");
return null;
}
var groups = JsonHelper.JsonToObj<dynamic>(resp).data.platShowInfoDetailVOList;
var targetTicket = new TicketResp();
int date = 0;
foreach (var group in groups)
{
int priceIndex = 0;
foreach (var ticketPrice in group.ticketPriceList)
{
if (ticketPrice.reservedCount > targetTicket.ReservedCount && dayChoose.Contains(date) && priceChoose.Contains(priceIndex))
{
targetTicket = new TicketResp()
{
Date = date,
PriceIndex = priceIndex,
ReservedCount = ticketPrice.reservedCount,
ShowId = ticketPrice.showId,
SectionId = group.sectionId,
DateTime = group.showTime,
Price = ticketPrice.actuallyPrice,
PriceId = ticketPrice.priceId
};
}
priceIndex++;
}
date++;
}
if (!string.IsNullOrWhiteSpace(targetTicket.ShowId))
{
return targetTicket;
}
Console.WriteLine("无票或未开售");
return null;
}
/// <summary>
/// 验证cookie是否生效
/// </summary>
public bool VerifyCookie()
{
var reqBody = new
{
requestModel = new PolytReqModel()
};
return JsonHelper.JsonToObj<RespModel<dynamic>>(PostAsync(checkLoginUrl, JsonHelper.ObjToJson(reqBody), null).Result).data != null;
}
public Dictionary<string, string> GetReqHeaders()
{
var headers = new Dictionary<string, string>();
headers.Add("Origin", "https://m.polyt.cn");
headers.Add("Referer", "https,//m.polyt.cn/");
return headers;
}
private async Task<string> GetAsync(string serviceAddress, IWebProxy proxy)
{
return await HttpRequest.GetAsync(serviceAddress, GetReqHeaders(), proxy);
}
private async Task<string> PostAsync(string serviceAddress, string strContent, IWebProxy proxy)
{
return await HttpRequest.PostAsync(serviceAddress, strContent, GetReqHeaders(), proxy);
}
}
}