正文
python推送钉钉群消息
import time import hmac import hashlib import base64 import urllib.parse import requests,json #钉钉加签 webhook='https://oapi.dingtalk.com/robot/send?access_token=********' #钉钉机器人webhook timestamp = str(round(time.time() * 1000)) secret = 'SEC********' #钉钉机器人秘钥 secret_enc = secret.encode('utf-8') string_to_sign = '{}\n{}'.format(timestamp, secret) # print(string_to_sign) 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+'×tamp='+timestamp+'&sign='+sign print(webhook) #定义数据类型 headers={'Content-Type':'application/json'} msgtitle="new msg" data={"msgtype":"text","text":{"content":f'通知:{msgtitle}!!!'},"isAtAll":True} #发送post请求 res=requests.post(webhook,data=json.dumps(data),headers=headers) print(res.text)
- 上一篇: shadowsocks一键安装脚本
- 下一篇: vbs脚本检测出现指定标题窗口并点击鼠标
猜你喜欢
- 2024-01-08python脚本检测出现指定标题窗口并点击鼠标
- 2024-01-04linux后台执行python脚本
- 2024-01-03Ubuntu安装Python3.9
- 搜索