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)
相关推荐
xxie1237941 天前
return与print
开发语言·python
秋91 天前
从 Python 后端工程师转型 AI Engineer(AI 工程化)的完整补课清单(2026实战版)
开发语言·人工智能·python
程序员二叉1 天前
【Java】 异常高频面试题精讲 | 易错点+对比总结
java·开发语言·面试
慕木沐1 天前
Google ADK Java 1.0版本 核心机制与实战 Demo
java·开发语言·python
Tbisnic1 天前
AI大模型学习第十一天:技术选型、安全防护与金融实战
python·学习·ai·大模型·提示词工程
Roann_seo%1 天前
C++文件操作完全指南:从文本读写到二进制文件处理
开发语言·c++
hboot1 天前
AI工程师第一课 - Python
前端·后端·python
huangdong_1 天前
淘宝商品SKU图自动分类技术深度解析:从DOM解析到智能归档
开发语言·javascript·ecmascript
阿正的梦工坊1 天前
【Rust】12-借用检查器与非词法生命周期
开发语言·后端·rust
许彰午1 天前
30_Java Stream流操作全解
java·windows·python