From 0d27140deebd0002794a9d609392735a9c403d70 Mon Sep 17 00:00:00 2001 From: 7a1dd609-d238-4580-9d5f-ee8412b0f5bc <7a1dd609-d238-4580-9d5f-ee8412b0f5bc@bankofchina.com> Date: Sat, 25 Jan 2025 10:57:28 +0800 Subject: [PATCH] feat: move requests to httpx --- requirements.txt | 2 +- sdgb.py | 36 +++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/requirements.txt b/requirements.txt index 527563b..ee347e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -requests +httpx pycryptodome pytz flask diff --git a/sdgb.py b/sdgb.py index 8ec939b..1070c26 100644 --- a/sdgb.py +++ b/sdgb.py @@ -3,7 +3,7 @@ import zlib import pytz import base64 import hashlib -import requests +import httpx from datetime import datetime from Crypto.Cipher import AES @@ -29,7 +29,6 @@ class aes_pkcs7(object): def decrypt(self, content): cipher = AES.new(self.key, AES.MODE_CBC, self.iv) - #content = base64.b64decode(content) return cipher.decrypt(content) text = cipher.decrypt(content).decode('utf-8') return self.pkcs7unpadding(text) @@ -56,26 +55,26 @@ def sdgb_api(data, useApi, userId): data = data data_enc = aes.encrypt(data) data_def = zlib.compress(data_enc) - requests.packages.urllib3.disable_warnings() endpoint = "https://maimai-gm.wahlap.com:42081/Maimai2Servlet/" - r = requests.post(endpoint + get_hash_api(useApi), headers={ - "User-Agent": "%s#%d"%(get_hash_api(useApi), userId), - "Content-Type": "application/json", - "Mai-Encoding": "1.40", - "Accept-Encoding": "", - "Charset": "UTF-8", - "Content-Encoding": "deflate", - "Expect": "100-continue" - }, data = data_def,verify=False) + r = httpx.post( + endpoint + get_hash_api(useApi), + headers = { + "User-Agent": "%s#%d"%(get_hash_api(useApi), userId), + "Content-Type": "application/json", + "Mai-Encoding": "1.40", + "Accept-Encoding": "", + "Charset": "UTF-8", + "Content-Encoding": "deflate", + "Expect": "100-continue" + }, + data = data_def + ) resp_def = r.content try: resp_enc = zlib.decompress(resp_def) - #print(resp_enc) except: resp_enc = resp_def - #print("skipped") - #print(resp_enc) return unpad(aes.decrypt(resp_enc), 16).decode() def qr_api(qr_code): @@ -96,7 +95,10 @@ def qr_api(qr_code): "Host": "ai.sys-all.cn", "User-Agent": "WC_AIME_LIB" } - res = requests.post("http://ai.sys-allnet.cn/wc_aime/api/get_data", data=json.dumps(param, separators=(',', ':')), headers=headers) - # print(param) # debug打印param数据 + res = httpx.post( + "http://ai.sys-allnet.cn/wc_aime/api/get_data", + data = json.dumps(param, separators=(',', ':')), + headers = headers + ) assert res.status_code == 200, "网络错误" return json.loads(res.content) \ No newline at end of file