首页 > 微信 > 详细

企业微信应用推送消息 python代码 zabbix设置

时间:2019-10-18 12:27:11      阅读:125      评论:0      收藏:0      [点我收藏+]

企业微信应用推送消息 python代码

 

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip -V
pip install requests

cat >weixin_send.py <<EOF
#!/usr/bin/env python
# coding=utf-8
import requests
import sys

def get_token_in_time(corp_id,secret):
    res = requests.get(https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s % (corp_id, secret))
    res = res.json()
    token = res.get(access_token, False)
    return token

def get_auth_code(code):
    rest = requests.get(https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=%s&code=%s % (get_token_in_time(),code))
    return rest.content

#https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE


if __name__ == __main__:
    if len(sys.argv) != 5:
        print("Usage:%s corpId SecretString AgentId MsgTxt ToUser" % sys.argv[0])
    else:

        corp_str = sys.argv[1]
        secret_str = sys.argv[2]
        agentid_str = str(sys.argv[3])
        msgtxt = sys.argv[4:][0]
        touser_str = sys.argv[-1]


        datastr=""" {"touser":"%s","msgtype":"text","agentid":%d,"text":{"content":"%s"}}""" % (touser_str,int(agentid_str),msgtxt)
        ACCESS_TOKEN = get_token_in_time(corp_str,secret_str)
        print("ACCESS_TOKEN::%s"%ACCESS_TOKEN)
        r = requests.post(url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s" % ACCESS_TOKEN,data=datastr)
        print r.text
EOF


##微信消息推送测试
python
weixin_send.py corpId SecretString AgentId "微信消息推送测试" @all


###zabbix 报警媒介类型 设置

chmod a+x weixin_send.py
\cp weixin_send.py $(find / -name alertscripts)/

 

技术分享图片

 

企业微信应用推送消息 python代码 zabbix设置

原文:https://www.cnblogs.com/blog-lhong/p/11697434.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!