加载中...
python 钉钉机器人推送消息
发表于:2022-04-18 | 分类: python
字数统计: 181 | 阅读时长: 1分钟 | 阅读量:

文章模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
import time
import hmac
import hashlib
import base64
import urllib.parse



timestamp = str(round(time.time() * 1000))
secret = 'this is 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))

access_token = ''
url = 'https://oapi.dingtalk.com/robot/send?access_token={}&timestamp={}&sign={}'.format(access_token,timestamp, sign)
# 获取当前时间
str_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
# 发送的消息格式
data = {"msgtype": "markdown",
"markdown": {
"title": "测试已完成",
"text":"啦啦啦",
},
"at": {"atMobiles": ["15386174586"]}
}
headers = {'Content-Type': 'application/json'}
message = requests.post(url, json.dumps(data), headers=headers).json()

在这里插入图片描述

上一篇:
python Django增删改查 快速体验
下一篇:
Django 邮件发送
本文目录
本文目录