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)
相关推荐
·心猿意码·3 分钟前
C++智能指针解析
开发语言·c++
广龙宇8 分钟前
【一起学Rust · 项目实战】使用getargs库来获取命令行参数
开发语言·python
沐知全栈开发32 分钟前
HTML 颜色名
开发语言
property-1 小时前
C++中#define和const的区别
开发语言·c++
mit6.8241 小时前
[Agent开发平台] 后端的后端 | MySQL | Redis | RQ | idgen | ObjectStorage
人工智能·python
学编程的小虎1 小时前
用 Python + Vue3 打造超炫酷音乐播放器:网易云歌单爬取 + Three.js 波形可视化
开发语言·javascript·python
€8111 小时前
Java入门级教程23——配置Nginx服务器、轻量级HTTP服务开发、前后端分离实现完整应用系统
java·开发语言·仓颉·生成验证码
yunson_Liu1 小时前
编写Python脚本在域名过期10天内将域名信息发送到钉钉
开发语言·python·钉钉
星秀日2 小时前
框架--SpringMVC
java·开发语言·servlet
布林模型2 小时前
缠论工具czsc快速使用入门(二)
python·缠论·快速入门·czsc