美文网首页
使用python脚本编写企业微信报警

使用python脚本编写企业微信报警

作者: 猫里灬 | 来源:发表于2018-11-30 16:42 被阅读0次

    使用软件:pytharm   

    使用python版本:python3.6

    脚本代码如下:

    import requests

    get_token_url= 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={ID}&corpsecret={SECRET}'

    get_token_url= get_token_url.format(

            ID='ww5aae58a8f443bfb4',# 登录网页后,点我的企业

            SECRET='-8F1lA_FqYr25UbvaylXdlggvpLNbZG9OEpREUBEgNw'  # 打开应用可查看

    )

    r_token= requests.get(url=get_token_url)

    token_dic= r_token.json()

    token= token_dic.get('access_token')

    text_content= "你可以登录<a href='https://www.baidu.com'>百度"

    data_body= {

    "touser" : "MaoLi",# userid 也就是网页上显示的账户对应的值

      "msgtype" : "text",# 消息类型为 纯文本

      "agentid" : 1000002,

      "text" : {

    "content" : text_content

      },

    "safe":0  # 是否加密传输: 0 不加密  1 加密

    }

    send_msg_url= 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}'

    r= requests.post(

    url=send_msg_url.format(token),

        json=data_body)

    print(r.status_code)

    print(r.text)

    相关文章

      网友评论

          本文标题:使用python脚本编写企业微信报警

          本文链接:https://www.haomeiwen.com/subject/xmkiqqtx.html