1PC版钉钉登录
2 钉钉群-群设置-智能群助手-添加机器人-自定义
3 填写机器人名字
4 安全设置选择:加签
5 完成
6 机器人设置查看Webhook,secret
7 选择加签安全设置,需要计算sign, timestamp
import json
import datetime
import requests
import time
import hashlib
import hmac
import base64
import re
# timestamp:当前时间戳,单位是毫秒,与请求调用时间误差不能超过1小时
timestamp=int(round(time.time() * 1000))
# 加密,获取sign和timestamp
data = (str(timestamp) + '\n' + secret).encode('utf-8')
secret = secret.encode('utf-8')
sign= base64.b64encode(hmac.new(secret, data, digestmod=hashlib.sha256).digest())
reg = re.compile(r"'(.*)'")
signature = str(re.findall(reg, str(sign))[0])
url = ‘https://oapi.dingtalk.com/robot/send?access_token=%s&sign=%s×tamp=%s’ % (access_token, sign, timestamp)