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)
相关推荐
m0_71643007几秒前
mysql表锁监控命令_诊断MyISAM表锁定问题的方法
jvm·数据库·python
广州山泉婚姻几秒前
Python爬虫 + AI 极简实战
人工智能·python
qq_334563552 分钟前
开发者工具怎么看HTML_Elements面板使用指南【操作】
jvm·数据库·python
m0_716430072 分钟前
c++怎么读取安卓系统Assets目录下的资源文件流数据【实战】
jvm·数据库·python
大江东去浪淘尽千古风流人物2 分钟前
【DROID-W】WildGS-SLAM
数据库·人工智能·python·oracle·augmented reality
ShineWinsu3 分钟前
百度搜索算法逆向思考的技术文章
开发语言
zhangchaoxies4 分钟前
C#怎么实现MVVM模式 C#如何在WPF中使用MVVM设计模式分离视图和逻辑【架构】
jvm·数据库·python
lhbian4 分钟前
C# vs 汇编:编程世界的两极对比
开发语言·汇编·c#
吕源林4 分钟前
防止SQL注入的应用层过滤_采用成熟的安全过滤中间件
jvm·数据库·python
handler017 分钟前
Linux基础知识(1)
linux·服务器·c语言·开发语言·数据结构·c++