度过了好忙好忙好忙的一段时间,最近闲下来,随便写点东西吧
python使用钉钉机器人输出文本,图片,定时推送
python 控制钉钉机器人
- 在钉钉创建一个三人以上的群,在群里添加一个自定义机器人,随意起名字,加个签(钉钉自动给的,要复制出来)
- 查看机器人复制你的Webhook url
- 钉钉输出文本方法
# 向钉钉输出文本
def to_dingding(text1):
# print(text1)
timestamp = str(round(time.time() * 1000))
secret = '放入你的签'
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
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 = '放入你的Webhookurl×tamp={}&sign={}'.format(
timestamp, sign)
headers = {
'Content-Type': 'application/json'
}
json = {
"at": {
"atMobiles": [