已掉线,重新登录

首页 > 绿虎论坛 > 电脑 > 软件 (发帖)

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

作者: @Ta

时间: 2023-04-26

点击: 665


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|显示机器人聊天)』

1.

小爱同学有吗。。

(/@Ta/2023-04-26 16:36//)

2. @穴儿,😂,我没有小爱
(/@Ta/2023-04-26 16:39//)

3. @穴儿,我看了下文档,流程都差不多,改改就能用。
https://developers.xiaoai.mi.com/documents/Home?type=/api/doc/render_markdown/SkillAccess/skill/CustomSkillsMain
(/@Ta/2023-04-26 16:43//)

8.

@残缘,晚上回去试试。。

(/@Ta/2023-04-26 16:49//)

9. @穴儿,chatgpt给的参数不太对,还是得对照的文档改改
(/@Ta/2023-04-26 16:50//)

10.

@残缘,你要把文档给到chatgpt进行纠正。

一加8Pro

(/@Ta/2023-04-26 17:57//)

11. @罐子,我觉得即便给他文档他一次两次也整不好😂,而这功夫早就改好了,就几行代码
(/@Ta/2023-04-26 17:58//)

12.

@残缘,嗯。
一加8Pro

(/@Ta/2023-04-26 18:02//)

13. r@残缘@罐子@穴儿,如何在天猫精灵上传自己的音乐并播放
(/@Ta/2023-05-06 14:12//)

14. @先飞,😂最简单的就是链接蓝牙,麻烦点的开发就是创建一个语音技能
(/@Ta/2023-05-06 14:36//)

15.

@先飞,链接蓝牙啊。。

(/@Ta/2023-05-06 14:30//)

回复需要登录

9月11日 14:44 星期四

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1