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.
34 lines
1.1 KiB
34 lines
1.1 KiB
|
6 days ago
|
import json
|
||
|
|
import requests
|
||
|
|
from lib.gzip_base64 import ungzip_base64_dh2cmc
|
||
|
|
from lib.redis_util import redis_set_key
|
||
|
|
|
||
|
|
|
||
|
|
def req(name: str, url: str, method: str, params: dict, data: dict):
|
||
|
|
print('-' * 100 + '\n' + f'请求{name}接口')
|
||
|
|
print('请求参数', data)
|
||
|
|
if method == 'GET':
|
||
|
|
params = {**params, **data}
|
||
|
|
data = {}
|
||
|
|
response = requests.post(url, params=params)
|
||
|
|
else:
|
||
|
|
response = requests.post(url, params=params, data=data)
|
||
|
|
response_json = response.text
|
||
|
|
|
||
|
|
if 'status' not in response_json:
|
||
|
|
print(f"-- gzip加密结果 --\n{response_json}")
|
||
|
|
response_json = ungzip_base64_dh2cmc(response_json)
|
||
|
|
response_obj = json.loads(response_json)
|
||
|
|
|
||
|
|
# 打印信息
|
||
|
|
print("-- 打印请求URL --\n", response.request.url)
|
||
|
|
print("-- 打印请求头 --\n", response.request.headers)
|
||
|
|
print("-- 打印请求体 --\n", response.request.body)
|
||
|
|
print("-- Json结果 --\n", response_json)
|
||
|
|
print("-- Obj结果 --\n", response_obj)
|
||
|
|
|
||
|
|
# 返回结果写缓存
|
||
|
|
redis_set_key(f'json_{name}', response_json)
|
||
|
|
|
||
|
|
return params, data, response_obj
|