python 钉钉机器人自定义发送文件_python调用钉钉 自定义机器人API发送消息

发布时间:2024-11-19 09:01

#!/bin/python

# -*- coding: utf-8 -*-

\"\"\"

# 发送消息到钉钉

\"\"\"

import json

import time

import sys

import requests

# dingidng notification

class Dingding(object):

def __init__(self, access_token, content=\'\', at_people=\'\'):

self.access_token = access_token

self.content = content

self.at_people = at_people

def get_token(self):

\'\'\'

钉钉管理后台 : http://open-dev.dingtalk.com

\'\'\'

access_token = \'https://oapi.dingtalk.com/robot/send?access_token=%s\' % self.access_token

return access_token

def send_dingding(self):

\'\'\'

access_token: 网站

content: 发送的内容

msgtype : 类型

\'\'\'

msgtype = \'text\'

if self.at_people == \'\':

values = {

\'msgtype\': \'text\',

msgtype: {

\'content\': self.content

},

\'at\': {

\'atMobiles\': self.at_people,

},

}

else:

values = {

\'msgtype\': \'text\',

msgtype: {

\'content\': self.content

},

\'at\': {

\'atMobiles\': [self.at_people]

},

}

headers = {\'Content-Type\': \'application/json; charset=UTF-8\'}

values = json.dumps(values)

print(self.get_token(), values)

res = requests.post(self.get_token(), values, headers=headers)

errmsg = json.loads(res.text)[\'errmsg\']

if errmsg == \'ok\':

return \'ok\'

return \'fail: %s\' % res.text

content = \'\'.join(sys.argv[1:])

obj = Dingding(\'你的机器人Webhook API\', content)

obj.send_dingding()

现在新版的机器人都需要自定义词 发送的内容要包括自定义词

python dingding10.py 啊test

\"python

\"python

点外卖的小伙伴可以能进群

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号