钉钉机器人发送消息脚本
· 技术积累 · Python

钉钉群机器人发送消息python脚本,可用作监控告警使用

如何使用:

1、注册个钉钉账号
2、创建一个群
3、添加群机器人
4、复制webhook到脚本api_url中

钉钉机器人发送消息脚本

钉钉机器人发送消息脚本


python脚本

#!/usr/bin/python
# -*- coding: utf-8 -*-
 
import requests
import json
import sys
import os
 
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 
def msg(text):
    json_text= {
     "msgtype": "text",
        #@群成员参数,填写手机号
        "at": {
            "atMobiles": [
                "xxxxxxxxxxx"
        ],
            "isAtAll": False
        },

    "text": {
            "content": text
    }    
    }
    print requests.post(api_url,json.dumps(json_text),headers=headers).content
     
if __name__ == '__main__':
    text = sys.argv[3]
    msg(text)

本文最后更新时间 2019-04-30
文章链接地址:
https://me.jinchuang.org/archives/451.html
本站文章除注明[转载|引用],均为本站原创内容,转载前请注明出处

留言列表

  1. cloudcone
    cloudcone Windows 8.1 Google Chrome · 中国上海市松江区电信 · 回复

    钉钉办公利器

  2. 张小仙
    张小仙 Windows 10 Google Chrome · 中国天津市电信IDC机房 · 回复

    :mrgreen:博客 的footer.php页面的站点地图代码,可否提供一下呢?

    1. J.C
      J.C Windows 10 Google Chrome · 中国上海市松江区电信 · 回复

      你用这个网站https://www.xml-sitemaps.com生成下就行了,我就用的它

留言