mirror of
https://github.com/WhaleFell/SMSBoom.git
synced 2026-04-25 19:20:49 +08:00
🐞 fix: 网页的bug
This commit is contained in:
@@ -56,6 +56,7 @@ def index():
|
|||||||
return render_template('admin.html')
|
return render_template('admin.html')
|
||||||
|
|
||||||
@app.route("/testapi/", methods=['POST'])
|
@app.route("/testapi/", methods=['POST'])
|
||||||
|
@logger.catch
|
||||||
def testapi():
|
def testapi():
|
||||||
brs = BaseResponse()
|
brs = BaseResponse()
|
||||||
# 需要传入 json 数据
|
# 需要传入 json 数据
|
||||||
|
|||||||
@@ -44,15 +44,14 @@ class API(BaseModel):
|
|||||||
def replace_data(self, content: Union[str, dict], phone) -> str:
|
def replace_data(self, content: Union[str, dict], phone) -> str:
|
||||||
if not phone:
|
if not phone:
|
||||||
return content
|
return content
|
||||||
if isinstance(content, dict):
|
# 统一转换成 str 再替换.
|
||||||
for key, value in content.items():
|
content = str(content).replace("[phone]", phone).replace(
|
||||||
content[key] = value.replace("[phone]", phone).replace(
|
"[timestamp]", self.timestamp_new())
|
||||||
"[timestamp]", self.timestamp_new())
|
# 尝试 json 化
|
||||||
else:
|
try:
|
||||||
if isinstance(content, str):
|
return json.loads(content)
|
||||||
content.replace('[phone]', phone).replace(
|
except:
|
||||||
'[timestamp]', self.timestamp_new())
|
return content
|
||||||
return content
|
|
||||||
|
|
||||||
def timestamp_new(self) -> str:
|
def timestamp_new(self) -> str:
|
||||||
"""返回整数字符串时间戳"""
|
"""返回整数字符串时间戳"""
|
||||||
@@ -63,12 +62,11 @@ class API(BaseModel):
|
|||||||
:param API: one API basemodel
|
:param API: one API basemodel
|
||||||
:return: API basemodel
|
:return: API basemodel
|
||||||
"""
|
"""
|
||||||
if self.method != "POST":
|
|
||||||
self.method = "GET"
|
|
||||||
if isinstance(self.data, str):
|
if isinstance(self.data, str):
|
||||||
self.data = json.loads(self.data)
|
self.data = json.loads(self.data)
|
||||||
if isinstance(self.header, str):
|
if isinstance(self.header, str):
|
||||||
self.header = json.loads(self.header)
|
if self.header:
|
||||||
|
self.header = json.loads(self.header)
|
||||||
self.data = self.replace_data(self.data, phone)
|
self.data = self.replace_data(self.data, phone)
|
||||||
self.url = self.replace_data(self.url, phone)
|
self.url = self.replace_data(self.url, phone)
|
||||||
return self
|
return self
|
||||||
@@ -81,7 +79,6 @@ def test_resq(api: API, phone) -> httpx.Response:
|
|||||||
:return: httpx 请求对象.
|
:return: httpx 请求对象.
|
||||||
"""
|
"""
|
||||||
api = api.handle_API(phone)
|
api = api.handle_API(phone)
|
||||||
print(api.dict())
|
|
||||||
with httpx.Client(headers=default_header, timeout=8) as client:
|
with httpx.Client(headers=default_header, timeout=8) as client:
|
||||||
if not isinstance(api.data, dict):
|
if not isinstance(api.data, dict):
|
||||||
client.request(method=api.method, headers=api.header,
|
client.request(method=api.method, headers=api.header,
|
||||||
@@ -89,3 +86,7 @@ def test_resq(api: API, phone) -> httpx.Response:
|
|||||||
resp = client.request(
|
resp = client.request(
|
||||||
method=api.method, headers=api.header, url=api.url, json=api.data)
|
method=api.method, headers=api.header, url=api.url, json=api.data)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pass
|
||||||
|
|||||||
@@ -91,8 +91,6 @@ def handle_API(API: API) -> API:
|
|||||||
:param API: one API basemodel
|
:param API: one API basemodel
|
||||||
:return: API basemodel
|
:return: API basemodel
|
||||||
"""
|
"""
|
||||||
if API.method != "POST":
|
|
||||||
API.method = "GET"
|
|
||||||
API.data = replace_data(API.data)
|
API.data = replace_data(API.data)
|
||||||
API.url = replace_data(API.url)
|
API.url = replace_data(API.url)
|
||||||
return API
|
return API
|
||||||
|
|||||||
Reference in New Issue
Block a user