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.
65 lines
2.1 KiB
65 lines
2.1 KiB
|
1 week ago
|
import zlib
|
||
|
|
import json
|
||
|
|
import base64
|
||
|
|
import urllib.parse
|
||
|
|
|
||
|
|
d = {
|
||
|
|
"status": "1",
|
||
|
|
"downloadInfo": {
|
||
|
|
"startDatetime": 0,
|
||
|
|
"cinemaCode": "304",
|
||
|
|
"flag": 0,
|
||
|
|
"dataCount": 1,
|
||
|
|
"endDatetime": 1610437484617,
|
||
|
|
"packageCode": "3eccd150-b8c9-4a43-a821-32d26f9cfb6b"
|
||
|
|
},
|
||
|
|
"success": 1,
|
||
|
|
"cinemaCode": "304",
|
||
|
|
"extend": {
|
||
|
|
"timeStamp": "20210112154459",
|
||
|
|
"sign": "BC018C679686F671C0BFE3ABB8A79A70",
|
||
|
|
"apiFunc": "cinemaInfo",
|
||
|
|
"info": {"startDatetime": 0, "cinemaCode": "304", "flag": 0, "dataCount": 1, "endDatetime": 1610437484617,
|
||
|
|
"packageCode": "3eccd150-b8c9-4a43-a821-32d26f9cfb6b"},
|
||
|
|
"retCode": "POS2000",
|
||
|
|
"retMsg": "处理完成"
|
||
|
|
},
|
||
|
|
"data": [
|
||
|
|
{
|
||
|
|
"cinemaCode": "304",
|
||
|
|
"cinemaName": "北京CBD万达广场店",
|
||
|
|
"id": "304",
|
||
|
|
"operateFlag": "2",
|
||
|
|
"platformCode": "11051401",
|
||
|
|
"version": "1610437484618",
|
||
|
|
"dealCode": "100000",
|
||
|
|
"dealMsg": "处理成功"
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def gzip_base64(req_obj):
|
||
|
|
# PHP 源码 urlencode(base64_encode(gzencode(json_encode($this->_ququData),9)));
|
||
|
|
json_str = json.dumps(req_obj) # 转换数据对象到json字符串
|
||
|
|
print(json_str)
|
||
|
|
gzip_compress = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16) # 创建gzip的压缩方式
|
||
|
|
gzip_bytes = gzip_compress.compress(json_str.encode()) + gzip_compress.flush() # 生成gzip压缩的字节码
|
||
|
|
b64encode_bytes = base64.b64encode(gzip_bytes) # 进行 base64 加密
|
||
|
|
result = urllib.parse.quote_plus(b64encode_bytes.decode()) # 对结果进行urlencode
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
def ungzip_base64(code):
|
||
|
|
# PHP源码 gzinflate(substr(base64_decode(urldecode($text)), 10, -8));
|
||
|
|
real_url = urllib.parse.unquote_plus(code) # 进行 urldecode操作
|
||
|
|
b64decode_bytes = base64.b64decode(real_url) # 进行base64解密
|
||
|
|
result = zlib.decompress(b64decode_bytes, zlib.MAX_WBITS | 16) # 使用zlib按照gzip的格式解压
|
||
|
|
return result.decode()
|
||
|
|
|
||
|
|
|
||
|
|
encode_str = gzip_base64(d)
|
||
|
|
print(encode_str)
|
||
|
|
decode_str = ungzip_base64(encode_str)
|
||
|
|
print(decode_str)
|