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)
相关推荐
阿里嘎多学长2 小时前
2026-02-16 GitHub 热点项目精选
开发语言·程序员·github·代码托管
啊吧怪不啊吧3 小时前
C++之基于正倒排索引的Boost搜索引擎项目usuallytool部分代码及详解
开发语言·c++·搜索引擎·项目
CeshirenTester4 小时前
9B 上端侧:多模态实时对话,难点其实在“流”
开发语言·人工智能·python·prompt·测试用例
Starry_hello world4 小时前
Python (2)
python
发现你走远了4 小时前
Windows 下手动安装java JDK 21 并配置环境变量(详细记录)
java·开发语言·windows
ID_180079054734 小时前
Python爬取京东商品库存数据与价格监控
jvm·python·oracle
游乐码4 小时前
c#类和对象
开发语言·c#
黎雁·泠崖4 小时前
Java常用类核心详解(一):Math 类超细讲解
java·开发语言
懒惰成性的5 小时前
12.Java的异常
java·开发语言
-To be number.wan5 小时前
Python数据分析:时间序列数据分析
开发语言·python·数据分析