python调用飞书机器人

python调用飞书机器人

最简单的代码

import hashlib
import base64
import hmac
import time
import requests

# 飞书webhook地址:https://open.feishu.cn/open-apis/bot/v2/xxxxxxxxxxxxx     通过设置飞书机器人可得
# 签名:yyyyyyyyyyyyyyyy    通过设置飞书机器人可得

url = 'https://open.feishu.cn/open-apis/bot/v2/xxxxxxxxxxxxx'


def gen_sign():
    secret = 'yyyyyyyyyyyyyyyy'
    timestamp = int(time.time())
    # 拼接timestamp和secret
    string_to_sign = '{}\n{}'.format(timestamp, secret)
    hmac_code = hmac.new(string_to_sign.encode("utf-8"), digestmod=hashlib.sha256).digest()

    # 对结果进行base64处理
    sign = base64.b64encode(hmac_code).decode('utf-8')

    return timestamp, sign


def request_feishu():
    timestamp, sign = gen_sign()
    print(timestamp, sign)
    data = {
        "timestamp": timestamp,
        "sign": sign,
        "msg_type": "text",
        "content": {"text": "嘻嘻"}
    }
    headers = {
        "Content-Type": "application/json",
    }
    result = requests.post(url, json=data, headers=headers)
    print(result.json())
    return


if __name__ == '__main__':
    request_feishu()

image

posted @   zong涵  阅读(541)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示