发布时间:2024-08-10 09:01
def dd(dd_token, dd_secret, dd_txt):
timestamp = str(round(time.time() * 1000))
secret = dd_secret # 钉钉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=\' + dd_token + \'×tamp=\' + timestamp + \'&sign=\' + sign
print(url)
data = {
\"msgtype\": \"text\",
\"text\": {\"content\": dd_txt}
}
headers = {\'Content-Type\': \'application/json\'}
res = requests.post(url=url, data=json.dumps(data), headers=headers)
print(res.text)
dd_secret = \'SECxxxxxxxxxxxxxxx\' #需要开启机器人加签 此处为加签的secret
dd_token = \'06a6xxxxxxxxxxxxxxx\' #自定义机器人的 token
dd_txt = \'要发送的内容\'
dd(dd_token, dd_secret, dd_txt)