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

2018-11-30  本文已影响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)

上一篇下一篇

猜你喜欢

热点阅读