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)
相关推荐
大数据追光猿3 分钟前
【深度学习】Pytorch项目实战-基于协同过滤实现物品推荐系统
人工智能·pytorch·python·深度学习·ai编程·推荐算法
m0_738355695 分钟前
java泛型
java·开发语言
师范大学生11 分钟前
基于CNN的FashionMNIST数据集识别2——模型训练
python·深度学习·cnn
web1376560764319 分钟前
纯 Python、Django、FastAPI、Flask、Pyramid、Jupyter、dbt 解析和差异分析
python·django·fastapi
大模型铲屎官22 分钟前
哈希表入门到精通:从原理到 Python 实现全解析
开发语言·数据结构·python·算法·哈希算法·哈希表
L_090738 分钟前
【C】队列与栈的相互转换
c语言·开发语言·数据结构
qq4054251971 小时前
基于python的旅客游记和轨迹分析可视化系统设计(新)
开发语言·python
C#Thread1 小时前
C#上位机--进程和线程的区别
java·开发语言
DKPT1 小时前
计算机网络之路由协议(自治系统)
开发语言·笔记·学习·计算机网络·算法
水月梦镜花1 小时前
数据结构:基数排序(c++实现)
开发语言·数据结构·c++