1. 程式人生 > 實用技巧 >使用釘釘機器人做一個監控

使用釘釘機器人做一個監控

生成access token

傳送訊息

def send_message(text):
    send_url = 'https://oapi.dingtalk.com/robot/send?access_token=xxx'

    headers = {
        'Content-Type': 'application/json',
        "Charset": "UTF-8"
    }
    data = {
        "msgtype": "markdown",
        "markdown": {
            "title": "python",
            "text": text
        },
        "at": {
            # "atMobiles": [
            #     "18788888888"
            # ],
            "isAtAll": True
        }
    }
    resp = requests.post(url=send_url, headers=headers, json=data)
    print(resp.json())


if __name__ == '__main__':
    text = """
    #### 深圳天氣 
    > 20度,西北風1級,空氣良89,相對溫度73%
    > ![screenshot](https://img95.699pic.com/photo/50055/5642.jpg_wh860.jpg)
    > ###### 10點21分發布 [天氣](https://www.baidu.com)
    """
    send_message(text)

結果