python 飞书 机器人

![在这里插入图片描述](https://img-blog.csdnimg.cn/e4758957286342999266a4ed01e19d59.png

废话 不多说 直接上 代码!!!

python 复制代码
"""
    coding:utf-8
    @Software:PyCharm
    @Time:2022/9/24 10:15
    @Author:Startao
    @Description:
"""
import base64
import hashlib
import hmac
import time

import requests


def gen_sign(timestamp, secret):
    # 拼接timestamp和secret
    string_to_sign = '{}\n{}'.format(timestamp, secret)
    hmac_code = hmac.new(string_to_sign.encode("utf-8"), digestmod=hashlib.sha256).digest()
    print(hmac_code)
    # 对结果进行base64处理
    sign = base64.b64encode(hmac_code).decode('utf-8')
    return sign


def send_message(message):
    webhook = "your_webhook"
    secret = "your_secret"
    timestamp = int(time.time())
    headers = {
        "Content-Type": "application/json"
    }
    a_sign = gen_sign(timestamp, secret)

    message_txt = {
        "sign": a_sign,
        "timestamp": timestamp,
        "msg_type": "text",
        "content": {
            "text": message
        }
    }
    response = requests.post(url=webhook, headers=headers, json=message_txt)
相关推荐
lingran__16 分钟前
C语言自定义类型详解 (1.1w字版)
c语言·开发语言
tang7778931 分钟前
Python爬虫代理,选短效IP还是长效IP?
爬虫·python·tcp/ip
村口曹大爷42 分钟前
JDK 24 正式发布:性能压轴,为下一代 LTS 铺平道路
java·开发语言
写文章的大米1 小时前
这份数据验证方案,可以让你的 FastAPI 崩溃率直降90%
python
xingzhemengyou11 小时前
Python 有哪些定时器
前端·python
站大爷IP1 小时前
Python自动整理音乐文件:按艺术家和专辑分类歌曲
python
BBB努力学习程序设计1 小时前
Python 高效处理大数据:生成器(Generator)的工作机制与实战技巧
python
ysdysyn2 小时前
C# Modbus RTU 多从站控制全攻略:一端口,双轴控制
开发语言·c#·mvvm·通讯·modbus rtu
hashiqimiya2 小时前
java程序的并发
java·开发语言·python
2301_811958382 小时前
浏览器下载huggingface网络连接超时,使用镜像源教程
python·tokenizer