python--向钉钉群发送消息(亲测可用)


向钉钉群发送文本消息

def sendDingDing(self,text):
    print(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)

向钉钉群发送链接消息

mport json
import requests

def send_msg(url):
    headers = {'Content-Type': 'application/json;charset=utf-8'}
    data = {
        "msgtype": "link",
        "link": {
            "text": '点我跳转百度',
            "title": "点我",
            "picUrl": "图片链接",      # 可以加,可以不加
            "messageUrl": "https://www.baidu.com"

        },
    }
    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={}'.format()
    print(send_msg(url))

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM