---
title: "天猫精灵的高阶玩法-控制我的电脑"
id: "1815"
type: "post"
slug: "%e5%a4%a9%e7%8c%ab%e7%b2%be%e7%81%b5%e7%9a%84%e9%ab%98%e9%98%b6%e7%8e%a9%e6%b3%95"
published_at: "2019-03-17T00:55:50+00:00"
modified_at: "2019-03-17T01:15:06+00:00"
url: "https://seq.ink/all/1815.html"
markdown_url: "https://seq.ink/all/1815.html.md"
excerpt: "用天猫精灵关闭我的电脑： 1.https://open.aligenie.com 创建一个开发者账户，然后创建一个应用 2.https://github.com/ychongsaytc/inhost 下载这个py项目用来做webhook 3 ..."
taxonomy_category:
  - "ALL"
  - "Coding代码堆"
  - "Live日常"
---

用天猫精灵关闭我的电脑：  
 1.https://open.aligenie.com  
 创建一个开发者账户，然后创建一个应用  
 2.https://github.com/ychongsaytc/inhost  
 下载这个py项目用来做webhook  
 3.在https://open.aligenie.com里创建一个技能-意图-回复设置的下面-下载认证文件  
 4.在inhost目录下创建一个文件夹./inhost/aligenie/里面把下载的认证文件放进去  
 5.修改**inhost.py里的**代码在urls段添加一条路由指向认证文件

[cc lang=”python”]  
 urls = (  
 ‘/’, ‘index’,  
 ‘/aligenie/认证文件.txt’,’aligenie’,  
 ‘/(\S+?)/(\S+?)/?’, ‘deploy’,  
 )

#再添加一个类

class aligenie:  
 def GET(self):  
 return’认证文件里的字符串’  
 [/cc]  
 6.把config-sample.json改名为config.json并修改配置  
 如下  
 [cc lang=”python”]  
 {  
 “http_host”: “0.0.0.0”,  
 “http_port”: 10000,  
 “url_secret”: “一个随机的字符串”,  
 “pid_file”: “/var/run/inhost.pid”,  
 “log_file”: “/var/log/inhost.log”,  
 “commands”: {  
 “shutdown”: {  
 “command”: “shutdown -h now”,  
 “timeout”: 300,  
 “netboot”:{  
 “command”:”/usr/bin/etherwake -D ’70:E9:4C:68:19:44′”,  
 “timeout”:300  
 }  
 }  
 }  
 }  
 [/cc]  
 然后运行python service.py start  
 如果有报错 把缺少的包安装好就可以了  
 7.因为我家的ip是公网的，所以可以直接使用。没有请进行端口映射  
 8.在天猫开放平台你创建的技能那里：在回复配置中调好url如：  
 http://ip:port/配置中的随机字符串/shutdown  
 调用你设置好的命令，配置文件中的“shutdown”。之后你每次对天猫说关闭我的电脑（技能中设置的调用词）电脑就好执行你填好的关机命令  
 如果你的路由器可以用python的话可以再写一条开机命令（通过网络唤醒）

你可以利用这个webhook增加更多功能
