-
Notifications
You must be signed in to change notification settings - Fork 3
/
cwToWechat.py
56 lines (46 loc) · 1.65 KB
/
cwToWechat.py
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
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
import json
import requests
corpid = '*********'
agentid = '***************'
appsecret = '*****************'
toparty = 1
token_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + \
corpid + '&corpsecret=' + appsecret
def getObject(m, f):
return m.get(f)
def lambda_handler(event, context):
message = event['Records'][0]['Sns']['Message']
null = 'null'
m = eval(message)
AlarmName = getObject(m, 'AlarmName')
AlarmDescription = getObject(m, 'AlarmDescription')
NewStateValue = getObject(m, 'NewStateValue')
OldStateValue = getObject(m, 'OldStateValue')
NewStateReason = getObject(m, 'NewStateReason')
NewStateReason = getObject(m, 'NewStateReason')
Trigger = getObject(m, 'Trigger')
newMessage = 'AlarmName: ' + AlarmName + '\n' + '\n' \
+ 'AlarmDescription: ' + AlarmDescription + '\n' + '\n' \
+ 'NewStateValue: ' + NewStateValue + '\n' + '\n' \
+ 'OldStateValue: ' + OldStateValue + '\n' + '\n' \
+ 'NewStateReason: ' + NewStateReason + '\n' + '\n' \
+ 'Trigger: ' + str(Trigger)
print(newMessage)
req = requests.get(token_url)
accesstoken = req.json()['access_token']
msgsend_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
params = {
# "touser": touser,
"toparty": toparty,
"msgtype": "text",
"agentid": agentid,
"text": {
"content": newMessage
},
"safe": 0
}
req = requests.post(msgsend_url, data=json.dumps(params))