import json
import os
import platform
from flask import Flask, request
app = Flask(__name__)
SHUTDOWN_COMMAND = "shutdown /s /t 0" # Windows关机命令
@app.route('/aligenie/你的鉴权文件.txt', methods=['GET'])
def get_file():
response = '鉴权文件内容
return response, 200, {'Content-type': 'text/plain'}
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'GET':
data = {'message': 'Hello, world!'}
json_data = json.dumps(data)
return json_data, 200, {'Content-type': 'application/json'}
elif request.method == 'POST':
data = request.get_json()
intent_name = data.get('intentName', '未知意图')
if intent_name == '关机':
print('开始关机')
# Windows关机命令
if platform.system() == "Windows":
os.system(SHUTDOWN_COMMAND)
else:
print("Unsupported OS")
# 发送回复消息
response_data = {
"returnCode": "0",
"returnErrorSolution": "",
"returnMessage": "",
"returnValue": {
"reply": "正在尝试关机",
"resultType": "RESULT",
"executeCode": "SUCCESS"
}
}
response_body = json.dumps(response_data).encode('utf-8')
return response_body, 200, {'Content-type': 'application/json'}
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9096)
https://iap.aligenie.com/添加一个技能,绑定你的主机IP地址。

小爱同学有吗。。