自定义钉钉消息

import time

import hmac

import hashlib

import base64

import urllib.parse

import requests

timestamp= str(round(time.time()* 1000))

secret= 'xxx'  #钉钉机器人的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))

print(timestamp)

print(sign)

url= "https://oapi.dingtalk.com/robot/send?access_token=xxx×tamp=%s&sign=%s" % (timestamp, sign)  "  #钉钉机器人的webhook

data= {"msgtype": "text", "text": {"content": "今天周五啦,大家填写一下测试周任务统计"}}

header= '{Content-Type: application/json}'

print(url)

response= requests.post(url, json=data)

print(response)


钉钉开放平台链接:https://developers.dingtalk.com/document/app/custom-robot-access?spm=ding_open_doc.document.0.0.6d9d28e1bOGseA#topic-2026027

你可能感兴趣的:(自定义钉钉消息)