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)
相关推荐
starzy199015 分钟前
Scala循环与判断:一切皆表达式的控制流
开发语言·人工智能·scala
starzy199029 分钟前
Scala类和对象:从构造器到样例类的完整指南
开发语言·后端·scala
niucloud-admin40 分钟前
NIUCLOUD PHP SAAS上门家政使用文档--服务订单:订单列表
开发语言·php
黑十43 分钟前
PyTorch 报 “no CUDA GPUs are available“ 怎么办?3 步排查
服务器·网络·人工智能·pytorch·python
怪我冷i1 小时前
Rust 的impl语法详解
开发语言·后端·rust
threelab1 小时前
开源图片去水印代码
python
qq_406981032 小时前
c++的decltype是什么
开发语言·c++
坤坤子吖2 小时前
算法学习——单调队列
开发语言·c++·笔记·学习·算法
我就是全世界2 小时前
OpenCode Go 套餐划算吗:先看你用哪个模型
开发语言·后端·golang
螺丝钉tina2 小时前
[Playwright] [02]常用命令与调试:Debug UI、Mode和 Trace Viewer
开发语言·javascript·测试工具·ui·自动化