#: To register a company in the micro-enterprise micro-channel signal
#: Well, after registration, enter the micro letter
#:have a test
#: Get access_token
#: Start getting
#:Obtain
#; Installed on the server side pip root @ Ubuntu: ~ # APT install Python - pip #: use pip install Python's request module root @ Ubuntu: ~ # pip install Requests #: end servers in preparation script (must be placed in this directory) Ubuntu @ root: ~ # cd / Apps / zabbix_server / report this content share / zabbix / alertscripts / root @ Ubuntu: / Apps / zabbix_server / report this content share / zabbix / alertscripts # vim linux37_weixin.py # ! / usr / bin / env Python #coding: UTF - 8 #Author: Zhang shijie Import Requests Import SYS Import os Import json Import logging logging.basicConfig (LevelLogging.DEBUG =, the format = ' % (the asctime) S,% (filename) S,% (levelname) S,% (Message) S ' , datefmt = ' % A,% B% D% the Y% H:% M :% S ' , filename = the os.path. the Join ( ' / tmp ' , ' weixin.log ' ), the fileMode = ' a ' ) corpid = ' ww0873ad6fe9cf2ff1 ' #: here modified to correspond to the company ID appsecret = " bvnET5_5Zt9Y9xEQpNnZnA2RlH8YgqH1KU6Sxz5z_1U " #: Here also modify agentid ="1000002" #:此处也要修改 token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret req=requests.get(token_url) accesstoken=req.json()['access_token'] msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken touser=sys.argv[1] subject=sys.argv[2] message=sys.argv[2] + "\n\n" +sys.argv[3] params={ "touser": touser, "msgtype": "text", "agentid": agentid, "text": { "content": message }, "safe":0 } req=requests.post(msgsend_url, data=json.dumps(params)) logging.info(' The sendto: ' + + TOUSER ' ;; Subject: ' + + Subject ' ;; Message: ' + Message) #; test could not be sent
#: This account must be a figure below this vegetable market account
#: After a good test, create a web client that media type
#: Add a warning to the user media
#: Configuration actions
#: Then test (test to be wrong, the general refused permission)
#; Give permission to execute the root @ Ubuntu: / Apps / zabbix_server / Share / ZABBIX / # alertscripts the chmod + X linux37_weixin.py #: is a group owner in modifying the root @ Ubuntu: / Apps / zabbix_server / Share / ZABBIX / alertscripts # chown zabbix.zabbix linux37_weixin.py #: in the deleted files in tmp, because the value of the previous test, the system will automatically generate a file here, so we get the value of this file is root with root root @ Ubuntu: / Apps / zabbix_server / report this content share / zabbix / alertscripts # RM -rf /tmp/weixin.log
#: Test is successful