diff --git a/FlaskWebProject1.pyproj b/FlaskWebProject1.pyproj new file mode 100644 index 0000000..672d7bd --- /dev/null +++ b/FlaskWebProject1.pyproj @@ -0,0 +1,76 @@ + + + 10.0 + Debug + 2.0 + 7a041c64-9b7a-497d-9eb7-05f9485f072c + . + {789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52} + app.py + + + . + Web launcher + http://localhost + . + true + FlaskWebProject1 + FlaskWebProject1 + True + + + true + false + + + true + false + + + + + + + + + + + + + + + + + + + True + True + http://localhost + False + + + + + + + CurrentPage + True + False + False + False + + + + + + + + + False + False + + + + + \ No newline at end of file diff --git a/FlaskWebProject1.sln b/FlaskWebProject1.sln new file mode 100644 index 0000000..8937d3b --- /dev/null +++ b/FlaskWebProject1.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "FlaskWebProject1", "FlaskWebProject1.pyproj", "{7A041C64-9B7A-497D-9EB7-05F9485F072C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A041C64-9B7A-497D-9EB7-05F9485F072C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A041C64-9B7A-497D-9EB7-05F9485F072C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A041C64-9B7A-497D-9EB7-05F9485F072C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A041C64-9B7A-497D-9EB7-05F9485F072C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6A9CE5FB-EF11-44FA-8527-4F24C7C85362} + EndGlobalSection +EndGlobal diff --git a/app.py b/app.py new file mode 100644 index 0000000..f232e60 --- /dev/null +++ b/app.py @@ -0,0 +1,102 @@ +""" +This script runs the application using a development server. +It contains the definition of routes and views for the application. +""" + +import time +from flask import Flask, request, jsonify +import requests +import json +from timeset import timeset +app = Flask(__name__) +@app.route('/send=0', methods=['GET','POST']) +def send_custom_json_0(): + 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": "0", + "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" + }, + "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 + +if __name__ == '__main__': + import os + HOST = os.environ.get('SERVER_HOST', 'localhost') + try: + PORT = int(os.environ.get('SERVER_PORT', '5555')) + except ValueError: + PORT = 5555 + app.run(HOST, PORT) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f93353a --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask>=2.2.3 diff --git a/timeset.py b/timeset.py new file mode 100644 index 0000000..300a4f4 --- /dev/null +++ b/timeset.py @@ -0,0 +1,16 @@ +import time +import uuid +import hashlib +def timeset(): + # »ñÈ¡µ±Ç°Ê±¼ä´Á + time_stamp = int(time.time()) + # »ñÈ¡Ëæ»úÊý + nonce = str(uuid.uuid4()) + # Ó¦ÓÃÃÜÔ¿ + app_secret = "8ff611f60e6e4413804379108b617f" + # Éú³Éԭʼ´® + SIGN_TEMPLATE = "time:{},nonce:{},appSecret:{}".format(time_stamp, nonce, app_secret) + # ¼ÆËãÇ©Ãû + sign = hashlib.md5(SIGN_TEMPLATE.encode()).hexdigest() + print("sign:", sign) + return time_stamp,nonce,sign