You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.9 KiB
77 lines
2.9 KiB
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 UnlockSeats: |
|
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')['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('UnlockSeats: 获取参数失败请检查', self.show_info, self.seats, self.seats_section, self.booking_id) |
|
return False |
|
|
|
print('-' * 100 + '\n' + '请求unlockSeats接口') |
|
|
|
data = {'UserName': self.user_name, |
|
'Password': self.password, |
|
'CinemaId': self.cinema_id, |
|
'ShowDate': self.show_info['date'], |
|
'FilmId': self.show_info['film_id'], |
|
'ShowTime': self.show_info['time'], |
|
'HallId': self.show_info['hId'], |
|
'SectionId': self.seats_section, |
|
'LockUserId': '', # LockUserId 锁定座位用户名(暂时无用) |
|
'Seats': self.seats, |
|
'TempBookingId': self.booking_id, |
|
} |
|
print(data) |
|
result_xml = self.ws_client.service.unlockSeats(**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', json.dumps(result_dict)) |
|
|
|
# 处理返回数据 |
|
self.handle() |
|
|
|
# 返回数据用于记录测试结果 |
|
return data, result_xml, result_dict |
|
|
|
def handle(self): |
|
pass |
|
|
|
|
|
if __name__ == "__main__": |
|
api = UnlockSeats(global_data) |
|
api.request()
|
|
|