From 3eddb219203712895390748fd061378713f9b056 Mon Sep 17 00:00:00 2001 From: AdminWhaleFall Date: Tue, 5 Apr 2022 21:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E7=94=B1=E5=8D=95?= =?UTF-8?q?=E5=BC=95=E5=8F=B7=E5=BC=95=E8=B5=B7=E7=9A=84=20json=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.json | 15 +++++++++++++++ flask_app/utils.py | 11 +++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/api.json b/api.json index 57d6ea3..032a6c6 100644 --- a/api.json +++ b/api.json @@ -23,5 +23,20 @@ "validate": "" } } + }, + { + "desc": "果壳app", + "url": "https://guokrapp-apis.guokr.com/hawking/v1/verifications", + "method": "POST", + "header": { + "User-Agent": "android 2.0.15", + "Client-Source": "android;23;Android;MuMu", + "Client-Channel": "gkchannel_QD009", + "Content-Type": "application/json; charset=UTF-8" + }, + "data": { + "dial_code": "0086", + "phone": "[phone]" + } } ] \ No newline at end of file diff --git a/flask_app/utils.py b/flask_app/utils.py index f7c5cc8..7b178f4 100644 --- a/flask_app/utils.py +++ b/flask_app/utils.py @@ -46,7 +46,7 @@ class API(BaseModel): return content # 统一转换成 str 再替换. content = str(content).replace("[phone]", phone).replace( - "[timestamp]", self.timestamp_new()) + "[timestamp]", self.timestamp_new()).replace("'",'"') # 尝试 json 化 try: return json.loads(content) @@ -82,10 +82,13 @@ def test_resq(api: API, phone) -> httpx.Response: api = api.handle_API(phone) with httpx.Client(headers=default_header, timeout=8) as client: if not isinstance(api.data, dict): - client.request(method=api.method, headers=api.header, + # print("data") + resp = client.request(method=api.method, headers=api.header, url=api.url, data=api.data) - resp = client.request( - method=api.method, headers=api.header, url=api.url, json=api.data) + else: + # print('json') + resp = client.request( + method=api.method, headers=api.header, url=api.url, json=api.data) return resp