From 38389ab41e6bd1b85b8b0dd4d65cbb2c2da5cf09 Mon Sep 17 00:00:00 2001 From: AdminWhaleFall Date: Tue, 5 Apr 2022 02:16:09 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=8E=A5=E5=8F=A3=E5=9C=A8?= =?UTF-8?q?=E7=BA=BFweb=E5=9F=BA=E6=9C=AC=E5=AE=8C=E5=B7=A5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.json | 28 +- apiback/api_back_2022_04_03_21_02_12.json | 1 - flask_app/app.py | 18 +- flask_app/templates/admin.html | 334 ++++++++++------------ flask_app/utils.py | 19 +- smsboom.py | 8 +- 6 files changed, 181 insertions(+), 227 deletions(-) delete mode 100644 apiback/api_back_2022_04_03_21_02_12.json diff --git a/api.json b/api.json index 5937965..a688acc 100644 --- a/api.json +++ b/api.json @@ -9,33 +9,7 @@ "Cy-Token": "token 9876032166" }, "data": { - "phone_num": "{phone}", - "area_code": "86" - } - }, - { - "desc": "彩云小译", - "url": "https://biz.caiyunapp.com/v1/send_sms_code", - "method": "POST", - "header": { - "Referer": "https://fanyi.caiyunapp.com/", - "Cy-Token": "token 9876032166" - }, - "data": { - "phone_num": "{phone}", - "area_code": "86" - } - }, - { - "desc": "彩云小译", - "url": "https://biz.caiyunapp.com/v1/send_sms_code", - "method": "POST", - "header": { - "Referer": "https://fanyi.caiyunapp.com/", - "Cy-Token": "token 9876032166" - }, - "data": { - "phone_num": "{phone}", + "phone_num": "[phone]", "area_code": "86" } } diff --git a/apiback/api_back_2022_04_03_21_02_12.json b/apiback/api_back_2022_04_03_21_02_12.json deleted file mode 100644 index 2fae989..0000000 --- a/apiback/api_back_2022_04_03_21_02_12.json +++ /dev/null @@ -1 +0,0 @@ -[{"desc": "С", "url": "https://biz.caiyunapp.com/v1/send_sms_code", "method": "POST", "header": {"Referer": "https://fanyi.caiyunapp.com/", "Cookie": "UM_distinctid=17fd5c7a9ba69a-0200a7005bf45a-56171958-146d15-17fd5c7a9bb749; _gid=GA1.2.2046680529.1648971157; _gat_gtag_UA_185151443_2=1; _ga=GA1.2.44459633.1648559084; _ga_65TZCJSDBD=GS1.1.1648971156.4.1.1648971164.0; _ga_R9YPR75N68=GS1.1.1648971156.4.1.1648971164.52", "Cy-Token": "token 9876032166"}, "data": {"phone_num": "{phone}", "area_code": "86"}}, {"desc": "С", "url": "https://biz.caiyunapp.com/v1/send_sms_code", "method": "POST", "header": {"Referer": "https://fanyi.caiyunapp.com/", "Cy-Token": "token 9876032166"}, "data": {"phone_num": "{phone}", "area_code": "86"}}, {"desc": "С", "url": "https://biz.caiyunapp.com/v1/send_sms_code", "method": "POST", "header": {"Referer": "https://fanyi.caiyunapp.com/", "Cy-Token": "token 9876032166"}, "data": {"phone_num": "{phone}", "area_code": "86"}}] \ No newline at end of file diff --git a/flask_app/app.py b/flask_app/app.py index c0785bb..086a994 100644 --- a/flask_app/app.py +++ b/flask_app/app.py @@ -1,7 +1,7 @@ # encoding=utf8 import json import time -from flask import Flask, make_response, request, jsonify +from flask import Flask, make_response, request, jsonify, render_template from flask_cors import CORS from urllib3 import disable_warnings @@ -12,6 +12,9 @@ disable_warnings() app = Flask(__name__) CORS(app, supports_credentials=True, resources="/*") # 跨域 +# 解决与 vue 冲突 +app.jinja_env.variable_start_string = '[[' +app.jinja_env.variable_end_string = ']]' def request_parse(req_data: request) -> dict: '''解析请求数据并以字典的形式返回''' @@ -48,6 +51,10 @@ class BaseResponse(BaseModel): return response +@app.route("/", methods=['GET']) +def index(): + return render_template('admin.html') + @app.route("/testapi/", methods=['POST']) def testapi(): brs = BaseResponse() @@ -77,7 +84,7 @@ def submitapi(): """提交API到json文件""" # 需要传入 json 数据 jsonData = request.get_json() - api = API(**jsonData) + api = API(**jsonData).handle_API() data = json.loads(json_path.read_text(encoding='utf8')) with open(json_path, mode="w", encoding="utf8") as j: try: @@ -88,13 +95,13 @@ def submitapi(): return BaseResponse(status=1, msg=f"写入失败!{why}").resp -@app.route("/backapi/", methods=['GET']) +@app.route("/backapi/", methods=['GET', 'POST']) def backjson(): """备份json文件""" try: timeStruct = time.localtime(int(time.time())) strTime = time.strftime("%Y_%m_%d_%H_%M_%S", timeStruct) - Path.mkdir(Path(json_path.parent, 'apiback', exist_ok=True)) + Path(json_path.parent, 'apiback').mkdir(exist_ok=True) json_back_path = Path(json_path.parent, 'apiback', f"api_back_{strTime}.json") with open(json_back_path, mode="w") as j: @@ -104,10 +111,11 @@ def backjson(): except Exception as why: return BaseResponse(status=1, msg=f"备份失败{why}").resp + @app.route("/downloadapi/", methods=['GET']) def downloadapi(): """下载接口文件""" return json_path.read_text(encoding='utf8') -app.run(host="0.0.0.0", port=1098, debug=True) +app.run(host="0.0.0.0", port=10981, debug=True) diff --git a/flask_app/templates/admin.html b/flask_app/templates/admin.html index 5dea57a..0b28cce 100644 --- a/flask_app/templates/admin.html +++ b/flask_app/templates/admin.html @@ -2,204 +2,172 @@ - - - - 短信轰炸接口调试工具. - - - - - - - - - - + + + + 短信轰炸接口调试工具. + + + + + + + + + + + -
- - +
- -
- URL: - - - - -
-
- +

+ 短信接口添加工具 + By 落落 +

-
- +
+
+
+ phone +
+ +
-
- - - - +
+
+ decs +
+ +
-
-
-
- Type:视频 - Type:图文 -
-
-
-
- 文案: {{ resp.data.title }} -
-
-
-
- 作者: {{ resp.data.author }} -
-
-
-
- 音乐:(点击下载) -
-
- +
+
+ URL +
+ +
-
- -
-
- 点击图片即可下载! -
-
- - 加载失败 - -
+
+
+ Data +
+ +
-
-
-
-
-
-
-
- 视频链接: - (点击下载) -
-
- -
+
-
-
-
-
+
+
+ header +
+ +
-
+
+
+ 请求方法 +
+ +
+
-
+
+ -
- -
-
+
+ + +
+ +
+ +
+ +
+ + + + +
+ \ No newline at end of file diff --git a/flask_app/utils.py b/flask_app/utils.py index 845b83e..4575f4a 100644 --- a/flask_app/utils.py +++ b/flask_app/utils.py @@ -42,31 +42,35 @@ class API(BaseModel): return v def replace_data(self, content: Union[str, dict], phone) -> str: + if not phone: + return content if isinstance(content, dict): for key, value in content.items(): - content[key] = value.replace("{phone}", phone).replace( - "{timestamp}", self.timestamp_new()) + content[key] = value.replace("[phone]", phone).replace( + "[timestamp]", self.timestamp_new()) else: if isinstance(content, str): - content.replace("{phone}", phone).replace( - "{timestamp}", self.timestamp_new()) + content.replace('[phone]', phone).replace( + '[timestamp]', self.timestamp_new()) return content def timestamp_new(self) -> str: """返回整数字符串时间戳""" return str(int(datetime.now().timestamp())) - def handle_API(self, phone): + def handle_API(self, phone=None): """ :param API: one API basemodel :return: API basemodel """ if self.method != "POST": self.method = "GET" - self.data = self.replace_data(self.data, phone) - self.url = self.replace_data(self.url, phone) + if isinstance(self.data, str): + self.data = json.loads(self.data) if isinstance(self.header, str): self.header = json.loads(self.header) + self.data = self.replace_data(self.data, phone) + self.url = self.replace_data(self.url, phone) return self @@ -77,6 +81,7 @@ def test_resq(api: API, phone) -> httpx.Response: :return: httpx 请求对象. """ api = api.handle_API(phone) + print(api.dict()) with httpx.Client(headers=default_header, timeout=8) as client: if not isinstance(api.data, dict): client.request(method=api.method, headers=api.header, diff --git a/smsboom.py b/smsboom.py index 5a3856b..316004f 100644 --- a/smsboom.py +++ b/smsboom.py @@ -76,13 +76,13 @@ def timestamp_new() -> str: def replace_data(content: Union[str, dict]) -> str: if isinstance(content, dict): for key, value in content.items(): - content[key] = value.replace("{phone}", phone).replace( - "{timestamp}", timestamp_new()) + content[key] = value.replace("[phone]", phone).replace( + "[timestamp]", timestamp_new()) else: # fix: add str判断 if isinstance(content, str): - content.replace("{phone}", phone).replace( - "{timestamp}", timestamp_new()) + content.replace("[phone]", phone).replace( + "[timestamp]", timestamp_new()) return content