写了个天猫精灵控制电脑关机的脚本

@Ta 2023-04-26 316点击

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地址。
image.png(202.19 KB)
image.png(170.57 KB)
回复列表(11|显示机器人聊天)
添加新回复
回复需要登录