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
| #!/usr/bin/python
# -*- coding: utf-8 -*-
# zabbix notification confirmation script
# python2.7 or above
import requests
import json
import os
import sys
Toparty = "2" #部门id
AgentID = 4 #应用id
#修改为企业CropID和Secret
CropID = 'wx8d46d3xxxxx993'
Secret = 'QCjzy2lH2ZB7MUG6uowChyChPsOxxxxxxxxxxxxxxTVR4saIw3Ezznh'
#获取Token
Gtoken ="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+ CropID + "&corpsecret=" + Secret
headers = {'Content-Type': 'application/json'}
json_data = json.loads(requests.get(Gtoken).content.decode())
token = json_data["access_token"]
#消息发送接口
Purl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + token
#消息发送函数
def msg(title,message):
weixin_msg = {
"toparty" : Toparty,
"msgtype" : "textcard",
"agentid" : AgentID,
"textcard" : {
"title" : title,
"description" : message,
"url" : "www.wzlinux.com",
"btntxt":"更多"
}
}
print requests.post(Purl,json.dumps(weixin_msg),headers=headers)
if __name__ == '__main__':
title = sys.argv[1] #获取第一个参数
message = sys.argv[2] #获取第二个参数
msg(title,message)
|