mirror of
https://github.com/WhaleFell/SMSBoom.git
synced 2026-07-16 11:22:18 +08:00
✨ feat: 接口在线web基本完工.
This commit is contained in:
28
api.json
28
api.json
@@ -9,33 +9,7 @@
|
|||||||
"Cy-Token": "token 9876032166"
|
"Cy-Token": "token 9876032166"
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"phone_num": "{phone}",
|
"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"
|
"area_code": "86"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"}}]
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# encoding=utf8
|
# encoding=utf8
|
||||||
import json
|
import json
|
||||||
import time
|
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 flask_cors import CORS
|
||||||
from urllib3 import disable_warnings
|
from urllib3 import disable_warnings
|
||||||
|
|
||||||
@@ -12,6 +12,9 @@ disable_warnings()
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app, supports_credentials=True, resources="/*") # 跨域
|
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:
|
def request_parse(req_data: request) -> dict:
|
||||||
'''解析请求数据并以字典的形式返回'''
|
'''解析请求数据并以字典的形式返回'''
|
||||||
@@ -48,6 +51,10 @@ class BaseResponse(BaseModel):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/", methods=['GET'])
|
||||||
|
def index():
|
||||||
|
return render_template('admin.html')
|
||||||
|
|
||||||
@app.route("/testapi/", methods=['POST'])
|
@app.route("/testapi/", methods=['POST'])
|
||||||
def testapi():
|
def testapi():
|
||||||
brs = BaseResponse()
|
brs = BaseResponse()
|
||||||
@@ -77,7 +84,7 @@ def submitapi():
|
|||||||
"""提交API到json文件"""
|
"""提交API到json文件"""
|
||||||
# 需要传入 json 数据
|
# 需要传入 json 数据
|
||||||
jsonData = request.get_json()
|
jsonData = request.get_json()
|
||||||
api = API(**jsonData)
|
api = API(**jsonData).handle_API()
|
||||||
data = json.loads(json_path.read_text(encoding='utf8'))
|
data = json.loads(json_path.read_text(encoding='utf8'))
|
||||||
with open(json_path, mode="w", encoding="utf8") as j:
|
with open(json_path, mode="w", encoding="utf8") as j:
|
||||||
try:
|
try:
|
||||||
@@ -88,13 +95,13 @@ def submitapi():
|
|||||||
return BaseResponse(status=1, msg=f"写入失败!{why}").resp
|
return BaseResponse(status=1, msg=f"写入失败!{why}").resp
|
||||||
|
|
||||||
|
|
||||||
@app.route("/backapi/", methods=['GET'])
|
@app.route("/backapi/", methods=['GET', 'POST'])
|
||||||
def backjson():
|
def backjson():
|
||||||
"""备份json文件"""
|
"""备份json文件"""
|
||||||
try:
|
try:
|
||||||
timeStruct = time.localtime(int(time.time()))
|
timeStruct = time.localtime(int(time.time()))
|
||||||
strTime = time.strftime("%Y_%m_%d_%H_%M_%S", timeStruct)
|
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',
|
json_back_path = Path(json_path.parent, 'apiback',
|
||||||
f"api_back_{strTime}.json")
|
f"api_back_{strTime}.json")
|
||||||
with open(json_back_path, mode="w") as j:
|
with open(json_back_path, mode="w") as j:
|
||||||
@@ -104,10 +111,11 @@ def backjson():
|
|||||||
except Exception as why:
|
except Exception as why:
|
||||||
return BaseResponse(status=1, msg=f"备份失败{why}").resp
|
return BaseResponse(status=1, msg=f"备份失败{why}").resp
|
||||||
|
|
||||||
|
|
||||||
@app.route("/downloadapi/", methods=['GET'])
|
@app.route("/downloadapi/", methods=['GET'])
|
||||||
def downloadapi():
|
def downloadapi():
|
||||||
"""下载接口文件"""
|
"""下载接口文件"""
|
||||||
return json_path.read_text(encoding='utf8')
|
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)
|
||||||
|
|||||||
@@ -2,204 +2,172 @@
|
|||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<!-- 屏蔽referrer -->
|
<!-- 屏蔽referrer -->
|
||||||
<meta name="referrer" content="never">
|
<meta name="referrer" content="never">
|
||||||
<title>短信轰炸接口调试工具.</title>
|
<title>短信轰炸接口调试工具.</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
|
||||||
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
|
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
||||||
<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
|
crossorigin="anonymous"></script>
|
||||||
<!-- 引入 layui.css -->
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
|
||||||
<link rel="stylesheet" href="https://unpkg.com/layui@2.6.8/dist/css/layui.css">
|
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
|
||||||
<!-- 引入 layui.js -->
|
crossorigin="anonymous"></script>
|
||||||
<script src="https://unpkg.com/layui@2.6.8/dist/layui.js"></script>
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
|
||||||
|
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
||||||
|
<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
|
||||||
|
<!-- 引入 layui.css -->
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/layui@2.6.8/dist/css/layui.css">
|
||||||
|
<!-- 引入 layui.js -->
|
||||||
|
<script src="https://unpkg.com/layui@2.6.8/dist/layui.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container" id="app">
|
<div class="container" id="app">
|
||||||
<div class="page-header">
|
|
||||||
<h1>抖音去水印解析<small>最新支持图文/视频! author:落落 <b><a href="https://lskyl.xyz/">Blog</a></b></small></h1>
|
|
||||||
</div>
|
|
||||||
<label for="basic-url">请输入复制的视频链接(自动提取URL)</label>
|
|
||||||
|
|
||||||
<!-- 输入框组 -->
|
<h3>
|
||||||
<div class="input-group">
|
短信接口添加工具
|
||||||
<span class="input-group-addon" id="basic-addon3">URL:</span>
|
<small class="text-muted">By 落落</small>
|
||||||
<input v-model="raw_url" type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3">
|
</h3>
|
||||||
<span class="input-group-btn">
|
|
||||||
<button v-on:click="req_api" class="btn btn-info" type="button">Go!</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<br />
|
|
||||||
<div v-if="url" class="alert alert-info" role="alert">
|
|
||||||
<b>提取到的链接:</b> <a v-bind:href="url" class="alert-link" target="_blank">{{ url }}</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="resp">
|
<div>
|
||||||
<div v-if="resp.status" class="alert alert-danger" role="alert">
|
<div class="input-group mb-3">
|
||||||
<b>接口报错!Msg:</b> {{ resp.msg }}
|
<div class="input-group-prepend">
|
||||||
</div>
|
<span class="input-group-text" id="basic-addon1">phone</span>
|
||||||
|
</div>
|
||||||
|
<input v-model="phone" type="text" class="form-control" placeholder="测试手机号">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-else>
|
<div class="input-group mb-3">
|
||||||
<div class="alert alert-success" role="alert">
|
<div class="input-group-prepend">
|
||||||
<b>解析成功!Msg:</b> {{ resp.msg }}
|
<span class="input-group-text" id="basic-addon1">decs</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- Telegram share -->
|
<input v-model="desc" type="text" class="form-control" placeholder="接口描述">
|
||||||
<script async src="https://telegram.org/js/telegram-widget.js?18" v-bind:data-telegram-share-url="resp.data.p_url" v-bind:data-comment="resp.data.title" data-size="large"></script>
|
</div>
|
||||||
<!-- 解析结果可折叠面板 -->
|
|
||||||
|
|
||||||
<div class="panel-group" id="accordion">
|
<div class="input-group mb-3">
|
||||||
<div class="panel panel-default">
|
<div class="input-group-prepend">
|
||||||
<div class="panel-body">
|
<span class="input-group-text" id="basic-addon1">URL</span>
|
||||||
<b v-if="resp.type_ === 'v'">Type:视频</b>
|
</div>
|
||||||
<b v-else>Type:图文</b>
|
<input v-model="url" type="text" class="form-control" placeholder="链接">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body">
|
|
||||||
<b>文案:</b> {{ resp.data.title }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body">
|
|
||||||
<b>作者:</b> {{ resp.data.author }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body">
|
|
||||||
<b>音乐:</b><a v-bind:href="resp.data.m_url" target="_blank"><b>(点击下载)</b></a>
|
|
||||||
<audio v-bind:src="resp.data.m_url" controls>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h4 class="panel-title">
|
|
||||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapse_1">
|
|
||||||
预览图 (点击展开)
|
|
||||||
</a>
|
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
<div id="collapse_1" class="panel-collapse collapse">
|
|
||||||
<div class="panel-body">
|
|
||||||
<a href="#" class="thumbnail">
|
|
||||||
<img v-bind:src="resp.data.p_url" alt="无法加载....">
|
|
||||||
<a v-bind:href="resp.data.p_url">
|
|
||||||
<button type="button" class="btn btn-info">Download</button>
|
|
||||||
</a>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="resp.type_ === 'p'" class="panel panel-default">
|
<div class="input-group">
|
||||||
<div class="panel-heading">
|
<div class="input-group-prepend">
|
||||||
<h4 class="panel-title">
|
<span class="input-group-text">Data</span>
|
||||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapse_2">
|
</div>
|
||||||
图文下载 (点击展开)
|
<textarea v-model="data" class="form-control" aria-label="With textarea" placeholder="发送的数据"></textarea>
|
||||||
</a>
|
</div>
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
<div id="collapse_2" class="panel-collapse collapse">
|
|
||||||
<div class="panel-body">
|
|
||||||
点击图片即可下载!
|
|
||||||
<div class="row">
|
|
||||||
<div v-for="img_url in resp.data.img_list" class="col-xs-6 col-md-3">
|
|
||||||
<a v-bind:href="img_url" target="_blank" class="thumbnail">
|
|
||||||
<img v-bind:src="img_url" alt="加载失败">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
<br />
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body">
|
|
||||||
<b>视频链接:</b>
|
|
||||||
<a v-bind:href="resp.data.v_url" target="_blank">(点击下载)</a>
|
|
||||||
<br />
|
|
||||||
<div class="embed-responsive embed-responsive-16by9">
|
|
||||||
<video ref="video" controls controlslist="nodownload" preload="none" width="100%"
|
|
||||||
height="100%" :poster="resp.data.p_url" :src="resp.data.v_url">
|
|
||||||
</video>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
<div class="input-group">
|
||||||
</div>
|
<div class="input-group-prepend">
|
||||||
</div>
|
<span class="input-group-text">header</span>
|
||||||
</div>
|
</div>
|
||||||
|
<textarea v-model="header" class="form-control" aria-label="With textarea"
|
||||||
|
placeholder="自定义header(可选)"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
<div class="input-group mb-3">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text" id="basic-addon1">请求方法</span>
|
||||||
|
</div>
|
||||||
|
<input v-model="method" type="text" class="form-control" placeholder="GET or POST">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
<div v-if="resp">
|
||||||
|
<div v-if="resp.status === '1'" class="alert alert-danger" role="alert">
|
||||||
|
<b>接口报错!Msg:</b> {{ resp.msg }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="error">
|
<div v-else>
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-success" role="alert">
|
||||||
<b>请求失败,请检查接口 Why:</b> {{ resp }}
|
<b>测试成功!Msg:</b> {{ resp.msg }}
|
||||||
接口地址: <code>{{ api }}</code>
|
</div>
|
||||||
</div>
|
<div class="alert alert-success" role="alert">
|
||||||
</div>
|
<b>接口响应:</b> {{ resp.data }}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="error === 1">
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
<b>请求失败,请检查接口 Why:</b> {{ resp }}
|
||||||
|
接口地址: <code>{{ api }}</code>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button v-on:click="call_api('/testapi/');" type="button" class="btn btn-primary">测试接口</button>
|
||||||
|
<button v-on:click="call_api('/submitapi/');" type="button" class="btn btn-primary">提交接口</button>
|
||||||
|
<button v-on:click="call_api('/backapi/');" type="button" class="btn btn-primary">备份接口</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
|
// server 地址 结尾不要加 /
|
||||||
// api 地址基于 Flask 搭建,可能会失效。请知悉
|
var api = "";
|
||||||
// 重度使用者请自行通过腾讯云函数搭建!!!
|
var app = new Vue({
|
||||||
var api = "https://service-dyjwokh6-1300913563.gz.apigw.tencentcs.com/dy/"
|
el: '#app',
|
||||||
|
data: {
|
||||||
var app = new Vue({
|
api: api,
|
||||||
el: '#app',
|
data: '',
|
||||||
data: {
|
url: '',
|
||||||
api: api,
|
header: '',
|
||||||
raw_url: '',
|
phone: '',
|
||||||
url: '',
|
method: '',
|
||||||
resp: '',
|
resp: '',
|
||||||
error: ''
|
error: '',
|
||||||
},
|
desc:''
|
||||||
methods: {
|
},
|
||||||
// 正则匹配字符串中的URL
|
methods: {
|
||||||
httpString: function (s) {
|
gen_json: function () {
|
||||||
if (!s) return ''
|
let datas = {
|
||||||
var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
|
"url": this.url,
|
||||||
var reg = /(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g;
|
"data": this.data,
|
||||||
s = s.match(reg);
|
"header": this.header,
|
||||||
this.url = s[0];
|
"phone": this.phone,
|
||||||
console.log(this.url);
|
"method": this.method,
|
||||||
return s[0];
|
"desc": this.desc,
|
||||||
},
|
};
|
||||||
req_api: function () {
|
console.log(datas);
|
||||||
layer.msg('请求接口中', {
|
return datas;
|
||||||
icon: 16
|
},
|
||||||
, shade: 0.01
|
call_api: function (url) {
|
||||||
});
|
let data = this.gen_json()
|
||||||
axios.get(api, {
|
if (data) { data = JSON.stringify(data) };
|
||||||
params: {
|
layer.msg('请求接口中', {
|
||||||
url: this.url,
|
icon: 16
|
||||||
}
|
, shade: 0.01
|
||||||
})
|
});
|
||||||
.then((response) => {
|
axios({
|
||||||
this.resp = response.data;
|
method: 'post',
|
||||||
layer.closeAll('loading');
|
url: url,
|
||||||
})
|
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
|
||||||
.catch((error) => {
|
data: data
|
||||||
this.error = true;
|
})
|
||||||
this.resp = error;
|
.then((response) => {
|
||||||
layer.closeAll('loading');
|
this.resp = response.data;
|
||||||
})
|
layer.closeAll('loading');
|
||||||
},
|
console.log("请求发送成功!");
|
||||||
},
|
console.log(this.resp.msg);
|
||||||
// 监听 raw_url 变化
|
})
|
||||||
watch: {
|
.catch((why) => {
|
||||||
'raw_url': function (newVal) {
|
this.error = true;
|
||||||
this.url = this.httpString(newVal);
|
this.resp = why;
|
||||||
},
|
console.log(why);
|
||||||
},
|
layer.msg("请求失败!");
|
||||||
});
|
layer.closeAll('loading');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -42,31 +42,35 @@ class API(BaseModel):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
def replace_data(self, content: Union[str, dict], phone) -> str:
|
def replace_data(self, content: Union[str, dict], phone) -> str:
|
||||||
|
if not phone:
|
||||||
|
return content
|
||||||
if isinstance(content, dict):
|
if isinstance(content, dict):
|
||||||
for key, value in content.items():
|
for key, value in content.items():
|
||||||
content[key] = value.replace("{phone}", phone).replace(
|
content[key] = value.replace("[phone]", phone).replace(
|
||||||
"{timestamp}", self.timestamp_new())
|
"[timestamp]", self.timestamp_new())
|
||||||
else:
|
else:
|
||||||
if isinstance(content, str):
|
if isinstance(content, str):
|
||||||
content.replace("{phone}", phone).replace(
|
content.replace('[phone]', phone).replace(
|
||||||
"{timestamp}", self.timestamp_new())
|
'[timestamp]', self.timestamp_new())
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def timestamp_new(self) -> str:
|
def timestamp_new(self) -> str:
|
||||||
"""返回整数字符串时间戳"""
|
"""返回整数字符串时间戳"""
|
||||||
return str(int(datetime.now().timestamp()))
|
return str(int(datetime.now().timestamp()))
|
||||||
|
|
||||||
def handle_API(self, phone):
|
def handle_API(self, phone=None):
|
||||||
"""
|
"""
|
||||||
:param API: one API basemodel
|
:param API: one API basemodel
|
||||||
:return: API basemodel
|
:return: API basemodel
|
||||||
"""
|
"""
|
||||||
if self.method != "POST":
|
if self.method != "POST":
|
||||||
self.method = "GET"
|
self.method = "GET"
|
||||||
self.data = self.replace_data(self.data, phone)
|
if isinstance(self.data, str):
|
||||||
self.url = self.replace_data(self.url, phone)
|
self.data = json.loads(self.data)
|
||||||
if isinstance(self.header, str):
|
if isinstance(self.header, str):
|
||||||
self.header = json.loads(self.header)
|
self.header = json.loads(self.header)
|
||||||
|
self.data = self.replace_data(self.data, phone)
|
||||||
|
self.url = self.replace_data(self.url, phone)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +81,7 @@ 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,
|
||||||
|
|||||||
@@ -76,13 +76,13 @@ def timestamp_new() -> str:
|
|||||||
def replace_data(content: Union[str, dict]) -> str:
|
def replace_data(content: Union[str, dict]) -> str:
|
||||||
if isinstance(content, dict):
|
if isinstance(content, dict):
|
||||||
for key, value in content.items():
|
for key, value in content.items():
|
||||||
content[key] = value.replace("{phone}", phone).replace(
|
content[key] = value.replace("[phone]", phone).replace(
|
||||||
"{timestamp}", timestamp_new())
|
"[timestamp]", timestamp_new())
|
||||||
else:
|
else:
|
||||||
# fix: add str判断
|
# fix: add str判断
|
||||||
if isinstance(content, str):
|
if isinstance(content, str):
|
||||||
content.replace("{phone}", phone).replace(
|
content.replace("[phone]", phone).replace(
|
||||||
"{timestamp}", timestamp_new())
|
"[timestamp]", timestamp_new())
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user