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)
相关推荐
踏着七彩祥云的小丑4 小时前
pytest——Mark标记
开发语言·python·pytest
Dream of maid4 小时前
Python12(网络编程)
开发语言·网络·php
W23035765734 小时前
经典算法:最长上升子序列(LIS)深度解析 C++ 实现
开发语言·c++·算法
Y4090014 小时前
【多线程】线程安全(1)
java·开发语言·jvm
不爱吃炸鸡柳5 小时前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
minji...5 小时前
Linux 线程同步与互斥(三) 生产者消费者模型,基于阻塞队列的生产者消费者模型的代码实现
linux·运维·服务器·开发语言·网络·c++·算法
Dxy12393102165 小时前
Python基于BERT的上下文纠错详解
开发语言·python·bert
SiYuanFeng6 小时前
Colab复现 NanoChat:从 Tokenizer(CPU)、Base Train(CPU) 到 SFT(GPU) 的完整踩坑实录
python·colab
wjs20247 小时前
JavaScript 语句
开发语言