import time
import hmac
import hashlib
import base64
import urllib.parse
import requests
def to_dingding():
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))
Webhook = "Webhook"
url = 'https://oapi.dingtalk.com/robot/send?access_token=Webhook×tamp={}&sign={}'.format(
timestamp, sign) # Webhook需要修改
headers = {
'Content-Type': 'application/json'
}
json = {
"at": {
"atMobiles": [
"" # 需要@的人的手机号
],
"isAtAll": 'false'
},
"text": {
"content": f"{'测试数据文本'}" # 需要是字符串
},
"msgtype": "text"
}
resp = requests.post(url=url, headers=headers, json=json)
to_dingding()
钉钉接入机器人发送群消息(python版)
最新推荐文章于 2024-05-18 16:16:00 发布