小陆同学

python 中文名:蟒蛇,设计者:Guido van Rossum

导航

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))

 

posted on 2020-08-28 20:16  小陆同学  阅读(2683)  评论(0编辑  收藏  举报