添加项目文件。

This commit is contained in:
IrisVega 2024-05-14 20:43:52 +08:00
parent 3c6ddd7448
commit 14be2c9973
5 changed files with 220 additions and 0 deletions

76
FlaskWebProject1.pyproj Normal file
View File

@ -0,0 +1,76 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>7a041c64-9b7a-497d-9eb7-05f9485f072c</ProjectGuid>
<ProjectHome>.</ProjectHome>
<ProjectTypeGuids>{789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<StartupFile>app.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<LaunchProvider>Web launcher</LaunchProvider>
<WebBrowserUrl>http://localhost</WebBrowserUrl>
<OutputPath>.</OutputPath>
<SuppressCollectPythonCloudServiceFiles>true</SuppressCollectPythonCloudServiceFiles>
<Name>FlaskWebProject1</Name>
<RootNamespace>FlaskWebProject1</RootNamespace>
<SuppressEnvironmentCreationPrompt>True</SuppressEnvironmentCreationPrompt>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="app.py" />
<Compile Include="timeset.py" />
</ItemGroup>
<ItemGroup>
<Content Include="requirements.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets" />
<!-- Specify pre- and post-build commands in the BeforeBuild and
AfterBuild targets below. -->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<AutoAssignPort>True</AutoAssignPort>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://localhost</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}" User="">
<WebProjectProperties>
<StartPageUrl>
</StartPageUrl>
<StartAction>CurrentPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram>
</ExternalProgram>
<StartExternalURL>
</StartExternalURL>
<StartCmdLineArguments>
</StartCmdLineArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
<EnableENC>False</EnableENC>
<AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>

25
FlaskWebProject1.sln Normal file
View File

@ -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

102
app.py Normal file
View File

@ -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)

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
Flask>=2.2.3

16
timeset.py Normal file
View File

@ -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