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.
63 lines
2.2 KiB
63 lines
2.2 KiB
|
1 week ago
|
import requests
|
||
|
|
import time
|
||
|
|
import json
|
||
|
|
from urllib.parse import urljoin
|
||
|
|
from lib.sign_key import SignKey
|
||
|
|
from lib.gzip_base64 import gzip_base64_cmc2dh
|
||
|
|
from cmc2dh.config import cinema_info, base_url
|
||
|
|
|
||
|
|
|
||
|
|
class MovieShow:
|
||
|
|
def __init__(self):
|
||
|
|
# 初始化签名生成类的对象
|
||
|
|
self.sign_key = SignKey()
|
||
|
|
# 生成请求参数
|
||
|
|
self.api_func = 'movieType'
|
||
|
|
self.current_timestamp = round(time.time() * 1000) # 生成时间戳
|
||
|
|
self.current_time = time.strftime('%Y%m%d%H%M%S', time.localtime(int(self.current_timestamp / 1000))) # 生成时间字符串
|
||
|
|
|
||
|
|
def prepare(self):
|
||
|
|
pass
|
||
|
|
|
||
|
|
def request(self, gzip=True):
|
||
|
|
# 初始化原始的请求参数
|
||
|
|
origin_data = {
|
||
|
|
'cinemaCode': cinema_info['code'],
|
||
|
|
'data': [{
|
||
|
|
'id': '99',
|
||
|
|
'movieTypeCode': '99',
|
||
|
|
'movieTypeName': '凸显',
|
||
|
|
'operateFlag': 2,
|
||
|
|
'version': self.current_timestamp
|
||
|
|
}],
|
||
|
|
'extend': {
|
||
|
|
'timeStamp': self.current_time,
|
||
|
|
'sign': self.sign_key.sign_dh(cinema_info['code'], self.api_func, self.current_time),
|
||
|
|
'apiFunc': self.api_func,
|
||
|
|
'info': json.dumps({'startDatetime': 0,
|
||
|
|
'cinemaCode': cinema_info['code'],
|
||
|
|
'flag': 0,
|
||
|
|
'dataCount': 1,
|
||
|
|
'endDatetime': self.current_timestamp,
|
||
|
|
'packageCode': 'f8af7345-a2f0-4ae0-8fc3-7e154a8fa379'})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
# 对原始请求进行加密压缩
|
||
|
|
req_data = {'data': gzip_base64_cmc2dh(origin_data)} # 请求不压缩数据
|
||
|
|
if gzip:
|
||
|
|
req_data = {'data': gzip_base64_cmc2dh(origin_data)} # 请求压缩数据
|
||
|
|
print(origin_data)
|
||
|
|
print(req_data)
|
||
|
|
|
||
|
|
# 发送请求
|
||
|
|
r = requests.post(urljoin('http://' + cinema_info['ip'], base_url), data=req_data)
|
||
|
|
print(r.json())
|
||
|
|
|
||
|
|
def handle(self):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
movie_show = MovieShow()
|
||
|
|
movie_show.request()
|