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)
相关推荐
浅时光_c4 分钟前
9 循环语句
c语言·开发语言
stevenzqzq5 分钟前
Kotlin 协程:withContext 与 async 核心区别与使用场景
android·开发语言·kotlin
CDN36012 分钟前
弱网下游戏盾掉线重连失败?链路保活与超时参数优化
开发语言·游戏·php
im_AMBER12 分钟前
Leetcode 153 课程表 | 腐烂的橘子
开发语言·算法·leetcode·深度优先·图搜索
嫂子的姐夫14 分钟前
34-自动化补环境和jsdom补环境
爬虫·python·逆向
烈风17 分钟前
01_Tauri环境搭建
开发语言·前端·后端
cch891817 分钟前
PHP爬虫框架大比拼
开发语言·爬虫·php
l1t24 分钟前
DeepSeek辅助编写的dmp转schema和csv文件c语言程序
c语言·开发语言·windows
羊小猪~~27 分钟前
LLM--大模型快速展示(Gradio)
人工智能·python·大模型·llm·部署·gradio·ai算法
DREW_Smile30 分钟前
自定义类型:联合体和枚举
c语言·开发语言