-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmp.py
More file actions
48 lines (43 loc) · 1.68 KB
/
mp.py
File metadata and controls
48 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import itchatmp
import test
# 配置微信公众号信息
itchatmp.update_config(itchatmp.WechatConfig(
token='pjhubs',
appId = 'wx02fb9d00f976e7f0',
appSecret = 'wx02fb9d00f976e7f0'))
# 接收用户消息
@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
toUserName = msg['FromUserName']
content = msg['Content']
isContain = 0;
# pjhubs.txt为有权限的用户列表
f = open("pjhubs.txt","r")
lines = f.readlines()
for line in lines:
if line[:-1] == toUserName:
isContain = 1;
if isContain == 0:
return '该系统并未对您开放,请联系PJ进行配置'
else:
if content == '添加':
# test.addNewUnit('tempUnit', 1, 2)
return '操作成功!'
elif content == '开灯':
return test.updateStatusWithHardware('hardware', 1, 'redLED', 1)
elif content == '关灯':
return test.updateStatusWithHardware('hardware', 1, 'redLED', 0)
elif content == '温度':
unit = test.updateStatusWithHardware('hardware', 0, 'tempUnit', 1)
returnString = '当前温度为:' + str(unit.num) + '°'
return returnString
elif content == '开风扇':
return test.updateStatusWithHardware('hardware', 1, 'tempUnit', 1)
elif content == '关风扇':
return test.updateStatusWithHardware('hardware', 1, 'tempUnit', 0)
# 新用户关注公众号时
@itchatmp.msg_register(itchatmp.content.EVENT)
def user_management(event):
if(event['Event']=='subscribe'):
return u'欢迎来到PJHubs,如果你想试用室内环境智能监测系统,请联系PJ'
itchatmp.run()