只需要提供参数就能够正确返回加密参数, 如下所示:
import time
from builtins import *
import httpx
from rich import print, json
# 请求远程数据
def get_remote_data(api_name, uid=None, sid=None, headers=None):
base_url = 'http://localhost:9999/api/'
# base_url = 'http://198.xxx.xxx.xxx:9999/api/' # 私信联系我获取远程服务器的ip地址
default_headers = {'uid': uid, 'sid': sid}
if headers:
updated_headers = {}
for k, v in headers.items():
if isinstance(v, dict):
updated_headers[k] = json.dumps(v)
else:
updated_headers[k] = str(v)
default_headers.update(updated_headers)
try:
with httpx.Client(http2=False) as client:
data = client.post(base_url + api_name, headers=default_headers)
if data.status_code != 200:
return None, data.status_code
data = data.json()
headers_dict = json.loads(data.get('headers', '{}'))
url = data.get('url')
post_data = {'data': data.get('data')}
if 'wua' in data:
post_data['wua'] = data.get('wua')
response = client.post(url, data=post_data, headers=headers_dict)
if response.status_code != 200:
return response.json(), response.status_code
return response.json(), response.json().get('ret')[0]
except httpx.RequestError as e:
return None, f"请求出错: {e}"
if __name__ == '__main__':
map = {
'apiName': 'mtop.relationrecommend.mtoprecommend.recommend',
'apiVersion': '1.0',
'isEnableWua': '1',
'app': 'taoTe',
'json': {
"style": "list",
"areaCode": "CN",
"p4pIds": "",
"topSimplifyBucketId": "3171",
"pvFeature": "",
"client_os": "iOS",
"devicePerformanceLevel": "high",
"schemaType": "auction",
"bxFeature": "",
"nsNative": "true",
"search_wap_mall": "false",
"dyS": "0",
"rainbow": "",
"LBS": "{}",
"network": "wifi",
"end_price": "",
"isBigSizeMode": "false",
"onFilter": "",
"loc": "",
"editionCode": "CN",
"keyboardRealTime": "false",
"tab": "all",
"enableXSearchScroll": "true",
"p4pS": "0",
"page": "1",
"brand": "iPhone",
"ttid": "201200@ltao_iphone_10.32.33",
"preSeTime": "0",
"lastQ": "",
"canP4pVideoPlay": "true",
"_xsearchInputQ": "",
"hasTab": "false",
"itemExpTypes": "",
"sort": "",
"sid": "",
"newSortBar": "true",
"appId": "1111",
"monitorCountry": "CN",
"dyIds": "",
"layeredSrp": "true",
"device": "iPhone12,1",
"contentIds": "",
"globalLbs": "",
"spm": "a2738.7628294",
"info": "WIFI",
"utd_id": "",
"sessionId": "",
"countryNum": "156",
"n": "10",
"ppath": "",
"newSubscribe": "true",
"catmap": "",
"isEnterSrpSearch": "true",
"search_button": "true",
"jarvisDisable": "true",
"enableNavBarHalfSticky": "true",
"xsearchFromSearchDoor": "true",
"hasPreposeFilter": "false",
"apptimestamp": "1716275716",
"start_price": "",
"imsi": "46000",
"client_for_bts": "client_ios14_idfa_alert:8533886",
"itemS": "0",
"isBeta": "false",
"itemIds": "",
"newSimilarAndSame": "true",
"client_os_version": "14.5",
"devicePerformanceType": "",
"vm": "nw",
"service": "",
"from": "input",
"deviceType": "Phone",
"sversion": "19.7",
"needTabs": "false",
"behavior": "",
"q": "macmini" # 这里修改搜索关键词
}
}
data, msg = get_remote_data('customJson', 'uid', 'sid', map)
print(data, msg)
支持远程测试, 有需要的可以私信我, 简单调用, 有易语言的测试版本
说明: 此代码仅供用于学习交流, 切勿用于非法用途