python--發送文本消息、鏈接消息帶圖片到釘釘告警群


發送文本消息

def sendDingDing(self,text):
    headers = {'Content-Type': 'application/json'}
    webhook = "https://oapi.dingtalk.com/robot/send?access_token="+self.apps.access_token
    data = {
        "msgtype": "text",
        "text": {
            "content": text+'\n'
        },
        "at": {
            "atMobiles": [

            ],
            "isAtAll": False
        }
    }

    x = requests.post(url=webhook, data=json.dumps(data), headers=headers)

發送鏈接消息

import json
import requests

def send_msg(url):
    headers = {'Content-Type': 'application/json;charset=utf-8'}
    data = {
        "msgtype": "link",
        "link": {
            "text": '這是標題',
            "title": "這是內容",
            "picUrl": "http://192.168.1.165:8000/static/images/fail.jpg",      
            "messageUrl": "https://fanyi.baidu.com/translate?aldtype=16047&query=&keyfrom=baidu&smartresult=dict&lang=auto2zh#auto/zh/"

        },
    }
    r = requests.post(url,data = json.dumps(data),headers=headers)
    return r.text
if __name__ == '__main__':
    url = 'https://oapi.dingtalk.com/robot/send?access_token={}'.formate(token)
    print(send_msg(url))

更多跳轉官方:https://ding-doc.dingtalk.com/doc#/serverapi2/al5qyp


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM