parent
55a4bdaed3
commit
3bb8b923aa
4 changed files with 354 additions and 0 deletions
@ -0,0 +1,107 @@ |
|||||||
|
import json |
||||||
|
import time |
||||||
|
import random |
||||||
|
from urllib.parse import urljoin |
||||||
|
from lib.http_req import req |
||||||
|
from config import global_data |
||||||
|
from lib.redis_util import redis_set_key, redis_get_key |
||||||
|
|
||||||
|
SUB_URL = '?m=web&a=lockSeatsv2' |
||||||
|
|
||||||
|
|
||||||
|
class LockSeatsV2: |
||||||
|
def __init__(self, data): |
||||||
|
self.url = urljoin(data['basic_data']['url_http'], SUB_URL) |
||||||
|
self.user_name = data['basic_data']['user_name'] # 固定写死的参数 |
||||||
|
self.password = data['basic_data']['password'] # 固定写死的参数 |
||||||
|
self.cinema_id = data['basic_data']['cinema_id'] |
||||||
|
self.req_method = data['http_req_method'] # http接口请求方法POST或GET |
||||||
|
self.show_info = None |
||||||
|
self.booking_id = None |
||||||
|
self.seats = None |
||||||
|
self.seats_section = None |
||||||
|
|
||||||
|
def prepare(self, buy_seats_num): |
||||||
|
buy_seats_num = int(buy_seats_num) |
||||||
|
|
||||||
|
# 获取场次信息 |
||||||
|
self.show_info = redis_get_key('json_buy_show_info') |
||||||
|
|
||||||
|
# 生成临时订单号 |
||||||
|
temp_booking_id_int = round(time.time() * 1000000) + random.randint(10, 99) |
||||||
|
temp_booking_id = 'mx' + str(temp_booking_id_int) |
||||||
|
self.booking_id = temp_booking_id |
||||||
|
|
||||||
|
# 生成座位数据 |
||||||
|
all_seats_list = redis_get_key('json_get_seats')['data']['seat'] # 获取get_seats返回的结果 |
||||||
|
available_seats_list = [s for s in all_seats_list if s['status'] == 'F' and s['available'] == 'Y'] # 计算可用作为 |
||||||
|
|
||||||
|
if len(available_seats_list) < buy_seats_num: |
||||||
|
print('无可用座位') |
||||||
|
return False |
||||||
|
# 选择作为 |
||||||
|
select_seat_list = [] |
||||||
|
while buy_seats_num > 0: |
||||||
|
select_seat = random.choice(available_seats_list) |
||||||
|
if select_seat['seatType'] not in ['L', 'R'] and select_seat not in select_seat_list: |
||||||
|
select_seat_list.append(select_seat) |
||||||
|
buy_seats_num -= 1 |
||||||
|
elif select_seat not in select_seat_list: |
||||||
|
if buy_seats_num > 1: |
||||||
|
row = select_seat['rowId'] |
||||||
|
col = int(select_seat['colId']) |
||||||
|
seat_type = select_seat['seatType'] |
||||||
|
for seat in available_seats_list: |
||||||
|
if seat['rowId'] == row and \ |
||||||
|
(seat['colId'] == str(col - 1) or seat['colId'] == str(col + 1)) and \ |
||||||
|
(seat['seatType'] in ['L', 'R'] and seat['seatType'] != seat_type): |
||||||
|
select_seat_list.append(select_seat) |
||||||
|
select_seat_list.append(seat) |
||||||
|
buy_seats_num -= 2 |
||||||
|
break |
||||||
|
|
||||||
|
# print(select_seat_list) |
||||||
|
self.seats = '|'.join(f"{seat['rowId']}:{seat['colId']}" for seat in select_seat_list) |
||||||
|
self.seats_section = '|'.join(f"{seat['sectionId']}" for seat in select_seat_list) |
||||||
|
select_seat_info = { |
||||||
|
"seat_str": self.seats, |
||||||
|
"section_str": self.seats_section, |
||||||
|
"select_seat_list": select_seat_list, |
||||||
|
} |
||||||
|
redis_set_key('json_selected_seats', json.dumps(select_seat_info)) |
||||||
|
|
||||||
|
return True |
||||||
|
|
||||||
|
def request(self, buy_seats_num): |
||||||
|
# 准备请求数据 |
||||||
|
self.prepare(buy_seats_num) |
||||||
|
|
||||||
|
if any(x is None for x in (self.booking_id, self.show_info, self.seats, self.seats_section)): |
||||||
|
print('LockSeatsV2: 获取参数失败请检查', self.booking_id, self.show_info, self.seats, self.seats_section) |
||||||
|
return False |
||||||
|
|
||||||
|
params = { |
||||||
|
'user': self.user_name, # 授权用户名 |
||||||
|
'pass': self.password, # 授权密码 |
||||||
|
'cinema': self.cinema_id, # 影院三位编码 |
||||||
|
} |
||||||
|
data = { |
||||||
|
'showCode': self.show_info['performId'], |
||||||
|
'seats': self.seats, |
||||||
|
'tempBookingId': self.booking_id, |
||||||
|
} |
||||||
|
|
||||||
|
resp_params, resp_data, response = req('lock_seats_v2', self.url, self.req_method, params, data) |
||||||
|
|
||||||
|
# 处理返回的数据 |
||||||
|
self.handle() |
||||||
|
|
||||||
|
return resp_params, resp_data, response |
||||||
|
|
||||||
|
def handle(self): |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
api = LockSeatsV2(global_data) |
||||||
|
api.request(2) |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
from urllib.parse import urljoin |
||||||
|
from config import global_data |
||||||
|
from lib.redis_util import redis_get_key |
||||||
|
from lib.http_req import req |
||||||
|
|
||||||
|
SUB_URL = '?m=web&a=unlockSeatsV2' |
||||||
|
|
||||||
|
|
||||||
|
class UnlockSeatsV2: |
||||||
|
def __init__(self, data): |
||||||
|
self.url = urljoin(data['basic_data']['url_http'], SUB_URL) |
||||||
|
self.user_name = data['basic_data']['user_name'] # 固定写死的参数 |
||||||
|
self.password = data['basic_data']['password'] # 固定写死的参数 |
||||||
|
self.cinema_id = data['basic_data']['cinema_id'] |
||||||
|
self.req_method = data['http_req_method'] # http接口请求方法POST或GET |
||||||
|
self.show_info = None |
||||||
|
self.seats = None |
||||||
|
self.lock_code = None |
||||||
|
|
||||||
|
def prepare(self): |
||||||
|
self.show_info = redis_get_key('json_buy_show_info') # 获取购票场次信息返回值 |
||||||
|
self.seats = redis_get_key('json_selected_seats')['seat_str'] # 获取座位信息 |
||||||
|
self.lock_code = redis_get_key('json_lock_seats_v2')['data']['lockCode'] # 获取锁座码 |
||||||
|
|
||||||
|
def request(self): |
||||||
|
# 准备请求数据 |
||||||
|
self.prepare() |
||||||
|
|
||||||
|
# 检查准备的测试数据 |
||||||
|
if any(x is None for x in (self.show_info, self.seats, self.lock_code)): |
||||||
|
print('LockSeatsV2: 获取参数失败请检查', self.show_info, self.seats, self.lock_code) |
||||||
|
return False |
||||||
|
|
||||||
|
params = { |
||||||
|
'user': self.user_name, # 授权用户名 |
||||||
|
'pass': self.password, # 授权密码 |
||||||
|
'cinema': self.cinema_id, # 影院三位编码 |
||||||
|
} |
||||||
|
data = { |
||||||
|
'showCode': self.show_info['performId'], # 放映日期 |
||||||
|
'seats': self.seats, # 座位信息 |
||||||
|
'lockCode': self.lock_code, # 锁座码 |
||||||
|
} |
||||||
|
resp_params, resp_data, response = req('unlock_seats_v2', self.url, self.req_method, params, data) |
||||||
|
|
||||||
|
# 处理返回的数据 |
||||||
|
self.handle() |
||||||
|
|
||||||
|
return resp_params, resp_data, response |
||||||
|
|
||||||
|
def handle(self): |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
api = UnlockSeatsV2(global_data) |
||||||
|
api.request() |
||||||
@ -0,0 +1,118 @@ |
|||||||
|
import json |
||||||
|
import time |
||||||
|
import random |
||||||
|
from suds.client import Client |
||||||
|
from lib.xml_to_dict import xml_to_dict |
||||||
|
from lib.gzip_base64 import ungzip_base64_dh2cmc |
||||||
|
from config import global_data |
||||||
|
from lib.redis_util import redis_set_key, redis_get_key |
||||||
|
|
||||||
|
|
||||||
|
class LockSeatsV2: |
||||||
|
def __init__(self, data): |
||||||
|
self.ws_client = Client(data['basic_data']['url_ws'], cache=None) |
||||||
|
self.ws_client.set_options(location=data['basic_data']['url_ws']) |
||||||
|
self.user_name = data['basic_data']['user_name'] # 固定写死的参数 |
||||||
|
self.password = data['basic_data']['password'] # 固定写死的参数 |
||||||
|
self.cinema_id = data['basic_data']['cinema_id'] |
||||||
|
self.show_info = None |
||||||
|
self.booking_id = None |
||||||
|
self.seats = None |
||||||
|
self.seats_section = None |
||||||
|
|
||||||
|
def prepare(self, buy_seats_num): |
||||||
|
buy_seats_num = int(buy_seats_num) |
||||||
|
|
||||||
|
# 获取场次信息 |
||||||
|
self.show_info = redis_get_key('xml_buy_show_info') |
||||||
|
|
||||||
|
# 生成临时订单号 |
||||||
|
temp_booking_id_int = round(time.time() * 1000000) + random.randint(10, 99) |
||||||
|
temp_booking_id = 'mx' + str(temp_booking_id_int) |
||||||
|
self.booking_id = temp_booking_id |
||||||
|
|
||||||
|
# 生成座位数据 |
||||||
|
all_seats_list = redis_get_key('xml_get_seats')['data']['seat'] # 获取get_seats返回的结果 |
||||||
|
available_seats_list = [s for s in all_seats_list if s['status'] == 'F' and s['available'] == 'Y'] # 计算可用作为 |
||||||
|
|
||||||
|
if len(available_seats_list) < buy_seats_num: |
||||||
|
print('无可用座位') |
||||||
|
return False |
||||||
|
# 选择作为 |
||||||
|
select_seat_list = [] |
||||||
|
while buy_seats_num > 0: |
||||||
|
select_seat = random.choice(available_seats_list) |
||||||
|
if select_seat['seatType'] not in ['L', 'R'] and select_seat not in select_seat_list: |
||||||
|
select_seat_list.append(select_seat) |
||||||
|
buy_seats_num -= 1 |
||||||
|
elif select_seat not in select_seat_list: |
||||||
|
if buy_seats_num > 1: |
||||||
|
row = select_seat['rowId'] |
||||||
|
col = int(select_seat['colId']) |
||||||
|
seat_type = select_seat['seatType'] |
||||||
|
for seat in available_seats_list: |
||||||
|
if seat['rowId'] == row and \ |
||||||
|
(seat['colId'] == str(col - 1) or seat['colId'] == str(col + 1)) and \ |
||||||
|
(seat['seatType'] in ['L', 'R'] and seat['seatType'] != seat_type): |
||||||
|
select_seat_list.append(select_seat) |
||||||
|
select_seat_list.append(seat) |
||||||
|
buy_seats_num -= 2 |
||||||
|
break |
||||||
|
|
||||||
|
# print(select_seat_list) |
||||||
|
self.seats = '|'.join(f"{seat['rowId']}:{seat['colId']}" for seat in select_seat_list) |
||||||
|
self.seats_section = '|'.join(f"{seat['sectionId']}" for seat in select_seat_list) |
||||||
|
select_seat_info = { |
||||||
|
"seat_str": self.seats, |
||||||
|
"section_str": self.seats_section, |
||||||
|
"select_seat_list": select_seat_list, |
||||||
|
} |
||||||
|
redis_set_key('xml_selected_seats', json.dumps(select_seat_info)) |
||||||
|
|
||||||
|
return True |
||||||
|
|
||||||
|
def request(self, buy_seats_num): |
||||||
|
# 准备请求数据 |
||||||
|
self.prepare(buy_seats_num) |
||||||
|
|
||||||
|
if any(x is None for x in (self.booking_id, self.show_info, self.seats, self.seats_section)): |
||||||
|
print('LockSeatsV2: 获取参数失败请检查',self.booking_id, self.show_info, self.seats, self.seats_section) |
||||||
|
return False |
||||||
|
|
||||||
|
print('-' * 100 + '\n' + '请求lockSeatsV2接口') |
||||||
|
|
||||||
|
data = {'UserName': self.user_name, |
||||||
|
'Password': self.password, |
||||||
|
'CinemaId': self.cinema_id, |
||||||
|
'ShowCode': self.show_info['performId'], |
||||||
|
'Seats': self.seats, |
||||||
|
'TempBookingId': self.booking_id, |
||||||
|
} |
||||||
|
print(data) |
||||||
|
result_xml = self.ws_client.service.lockSeatsv2(**data) |
||||||
|
|
||||||
|
# 处理返回数据格式 |
||||||
|
if 'xml' not in result_xml: |
||||||
|
print(f"-- gzip加密结果 --\n{result_xml}") |
||||||
|
result_xml = ungzip_base64_dh2cmc(result_xml) |
||||||
|
|
||||||
|
result_dict = xml_to_dict(result_xml) |
||||||
|
result_json = json.dumps(result_dict, ensure_ascii=False) |
||||||
|
print("-- Json结果 --\n", result_json) |
||||||
|
|
||||||
|
# 返回结果写缓存 |
||||||
|
redis_set_key('xml_lock_seats_v2', json.dumps(result_dict)) |
||||||
|
|
||||||
|
# 处理返回数据 |
||||||
|
self.handle() |
||||||
|
|
||||||
|
# 返回数据用于记录测试结果 |
||||||
|
return data, result_xml, result_dict |
||||||
|
|
||||||
|
def handle(self): |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
api = LockSeatsV2(global_data) |
||||||
|
api.request(2) |
||||||
@ -0,0 +1,72 @@ |
|||||||
|
import json |
||||||
|
from suds.client import Client |
||||||
|
from lib.xml_to_dict import xml_to_dict |
||||||
|
from lib.gzip_base64 import ungzip_base64_dh2cmc |
||||||
|
from config import global_data |
||||||
|
from lib.redis_util import redis_set_key, redis_get_key |
||||||
|
|
||||||
|
|
||||||
|
class UnlockSeatsV2: |
||||||
|
def __init__(self, data): |
||||||
|
self.ws_client = Client(data['basic_data']['url_ws'], cache=None) |
||||||
|
self.ws_client.set_options(location=data['basic_data']['url_ws']) |
||||||
|
self.user_name = data['basic_data']['user_name'] # 固定写死的参数 |
||||||
|
self.password = data['basic_data']['password'] # 固定写死的参数 |
||||||
|
self.cinema_id = data['basic_data']['cinema_id'] |
||||||
|
self.show_info = None |
||||||
|
self.seats = None |
||||||
|
self.seats_section = None |
||||||
|
self.booking_id = None |
||||||
|
|
||||||
|
def prepare(self): |
||||||
|
self.show_info = redis_get_key('xml_buy_show_info') # 获取购票场次信息返回值 |
||||||
|
self.seats = redis_get_key('xml_selected_seats')['seat_str'] # 获取座位信息 |
||||||
|
self.seats_section = redis_get_key('xml_selected_seats')['section_str'] # 获取座位section |
||||||
|
self.booking_id = redis_get_key('xml_lock_seats_v2')['data']['tempBookingId'] # 获取锁座码 |
||||||
|
|
||||||
|
def request(self): |
||||||
|
# 准备请求数据 |
||||||
|
self.prepare() |
||||||
|
|
||||||
|
# 检查准备的测试数据 |
||||||
|
if any(x is None for x in (self.show_info, self.seats, self.seats_section, self.booking_id)): |
||||||
|
print('UnlockSeatsV2: 获取参数失败请检查', self.show_info, self.seats, self.seats_section, self.booking_id) |
||||||
|
return False |
||||||
|
|
||||||
|
print('-' * 100 + '\n' + '请求unlockSeatsV2接口') |
||||||
|
|
||||||
|
data = {'UserName': self.user_name, |
||||||
|
'Password': self.password, |
||||||
|
'CinemaId': self.cinema_id, |
||||||
|
'ShowCode': self.show_info['performId'], |
||||||
|
'Seats': self.seats, |
||||||
|
'TempBookingId': self.booking_id, |
||||||
|
} |
||||||
|
print(data) |
||||||
|
result_xml = self.ws_client.service.unlockSeatsv2(**data) |
||||||
|
|
||||||
|
# 处理返回数据格式 |
||||||
|
if 'xml' not in result_xml: |
||||||
|
print(f"-- gzip加密结果 --\n{result_xml}") |
||||||
|
result_xml = ungzip_base64_dh2cmc(result_xml) |
||||||
|
|
||||||
|
result_dict = xml_to_dict(result_xml) |
||||||
|
result_json = json.dumps(result_dict, ensure_ascii=False) |
||||||
|
print("-- Json结果 --\n", result_json) |
||||||
|
|
||||||
|
# 返回结果写缓存 |
||||||
|
redis_set_key('xml_unlock_seats_v2', json.dumps(result_dict)) |
||||||
|
|
||||||
|
# 处理返回数据 |
||||||
|
self.handle() |
||||||
|
|
||||||
|
# 返回数据用于记录测试结果 |
||||||
|
return data, result_xml, result_dict |
||||||
|
|
||||||
|
def handle(self): |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
api = UnlockSeatsV2(global_data) |
||||||
|
api.request() |
||||||
Loading…
Reference in new issue