官网文档
自定义机器人
需要在钉钉pc端进行操作,获得webhook地址及secret
import requests
import json
import time
import hmac
import hashlib
import base64
import urllib.parse
class DingTalkBot:
#text link markdown ActionCard FeedCard
#https://developers.dingtalk.com/document/robots/custom-robot-access
msgtype="text"
headers={
"Content-Type":"application/json;charset=UTF-8"}
atMobiles=[]
atUserIds=[]
isAtAll=False
verify=False
def __init__(self, webhook, encryptionkey):
self.webhook = webhook
self.encryptionkey = encryptionkey
def webhook_sign(self):
'''
加签
'''
timestamp = str(round(time.time() * 1000))
secret_enc = self.encryptionkey.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, self.encryptionkey)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
url = self.webhook+