First
This commit is contained in:
parent
14be2c9973
commit
595c204918
47
app.py
47
app.py
@ -9,8 +9,8 @@ import requests
|
|||||||
import json
|
import json
|
||||||
from timeset import timeset
|
from timeset import timeset
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@app.route('/send=0', methods=['GET','POST'])
|
@app.route('/send/<int:ida>', methods=['GET','POST'])
|
||||||
def send_custom_json_0():
|
def send_custom_json(ida):
|
||||||
time_stamp,nonce,sign=timeset()
|
time_stamp,nonce,sign=timeset()
|
||||||
custom_json = {
|
custom_json = {
|
||||||
"system": {
|
"system": {
|
||||||
@ -24,48 +24,7 @@ def send_custom_json_0():
|
|||||||
"token": "At_0000hz7d3dcf1dbd884b4ba94a26c621",
|
"token": "At_0000hz7d3dcf1dbd884b4ba94a26c621",
|
||||||
"deviceId": "9F01FD3PAZ9B6B4",
|
"deviceId": "9F01FD3PAZ9B6B4",
|
||||||
"channelId": "0",
|
"channelId": "0",
|
||||||
"operation": "0",
|
"operation": ida,
|
||||||
"duration": "1000"
|
|
||||||
},
|
|
||||||
"id": "1"
|
|
||||||
}
|
|
||||||
target_url = 'https://openapi.lechange.cn:443/openapi/controlMovePTZ'
|
|
||||||
headers = {'Content-Type': 'application/json'}
|
|
||||||
try:
|
|
||||||
# 将自定义JSON数据转换为字符串
|
|
||||||
json_payload = json.dumps(custom_json)
|
|
||||||
|
|
||||||
# 发送POST请求到外部API
|
|
||||||
response = requests.post(target_url, data=json_payload, headers=headers)
|
|
||||||
|
|
||||||
# 检查请求是否成功
|
|
||||||
if response.status_code == 200:
|
|
||||||
print('Request sent successfully')
|
|
||||||
# 返回目标API的响应给客户端
|
|
||||||
return jsonify(response.json())
|
|
||||||
else:
|
|
||||||
print(f'Failed to send request, status code: {response.status_code}')
|
|
||||||
return jsonify({'error': 'Failed to send request'}), 500
|
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
print(f'Error occurred during request: {e}')
|
|
||||||
return jsonify({'error': str(e)}), 500
|
|
||||||
@app.route('/send=1', methods=['GET','POST'])
|
|
||||||
def send_custom_json_1():
|
|
||||||
time_stamp,nonce,sign=timeset()
|
|
||||||
custom_json = {
|
|
||||||
"system": {
|
|
||||||
"ver": "1.0",
|
|
||||||
"sign": sign,
|
|
||||||
"appId": "lc0be9b1a760e44634",
|
|
||||||
"time": time_stamp,
|
|
||||||
"nonce": nonce
|
|
||||||
},
|
|
||||||
"params": {
|
|
||||||
"token": "At_0000hz7d3dcf1dbd884b4ba94a26c621",
|
|
||||||
"deviceId": "9F01FD3PAZ9B6B4",
|
|
||||||
"channelId": "0",
|
|
||||||
"operation": "1",
|
|
||||||
"duration": "1000"
|
"duration": "1000"
|
||||||
},
|
},
|
||||||
"id": "1"
|
"id": "1"
|
||||||
|
Loading…
Reference in New Issue
Block a user