飞书实现发送文本消息

1、发送普通消息,代码如下

import requests
import json

def get_data():
data = {
"msg_type": "text",
"content": {
"text": "你好"
}
}
return json.dumps(data,ensure_ascii=True).encode("utf-8")

def req(data):
#webhook
url = "https://open.feishu.cn/open-apis/bot/v2/hook/111-22-33-44"
header = {
"Content-type": "application/json",
"charset":"utf-8"
}
requests.post(url,data=data,headers=header)

if __name__ == '__main__':
req(get_data())



效果图

2、发送富文本

import requests
import json

def get_data():
data = {
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": "项目更新通知",
"content": [
[{
"tag": "text",
"text": "项目有更新: "
},
{
"tag": "a",
"text": "请查看",
"href": "https://www.baidu.com/"
},
{
"tag": "at",
"user_id": "123456"
}
]
]
}
}
}
}
return json.dumps(data,ensure_ascii=True).encode("utf-8")


def req(data):
url = "https://open.feishu.cn/open-apis/bot/v2/hook/11-11-22-33"
header = {
"Content-type": "application/json",
"charset":"utf-8"
}
requests.post(url,data=data,headers=header)

if __name__ == '__main__':
req(get_data())

posted @ 2022-07-19 08:38  菩提浪子  阅读(1365)  评论(0)    收藏  举报