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)
相关推荐
潜创微科技--高清音视频芯片方案开发34 分钟前
2026年C转DP芯片方案深度分析:从适配场景到成本性能的优选指南
c语言·开发语言
Dontla43 分钟前
用pip install -e .开发Python包时,Python项目目录结构(项目结构)(可编辑安装editable install)
python·pip
Thomas.Sir44 分钟前
第三章:Python3 之 字符串
开发语言·python·字符串·string
刘景贤1 小时前
C/C++开发环境
开发语言·c++
威联通网络存储2 小时前
告别掉帧与素材损毁:威联通 QuTS hero 如何重塑影视后期协同工作流
前端·网络·人工智能·python
Dxy12393102162 小时前
Python 根据列表中某字段排序:从基础到进阶
开发语言·windows·python
competes2 小时前
学生需求 交易累计积分,积分兑换奖品
java·大数据·开发语言·人工智能·java-ee
splage2 小时前
Java进阶——IO 流
java·开发语言·python
青桔柠薯片2 小时前
从C语言到裸机运行:i.MX6ULL 的 GPIO 控制与编译链接过程分析
c语言·开发语言·imx6ull