Closed swyxjk closed 2 months ago
receive_msg回调 的 payload 整体是一个form
from fastapi import FastAPI, Form,File,UploadFile
from pydantic import BaseModel # 引入BaseModel
from typing import Union, List, Optional
# 创建payload 模型
class payload (BaseModel):
type: str
content: Union[str,UploadFile] = None
#content: Optional[UploadFile] = None
source: Optional[str] = None
isMentioned: Optional[str] = None
isMsgFromSelf: Optional[str] = None
@app.post("/receive_msg")
async def receive_message(payload:payload=Form()):
print(payload)
type_str = payload.type
if type_str == 'file':
# 文件名
filename_1 = payload.content.filename
# 发送者昵称
name = json.loads(payload.source)['from']['payload']['name']
# 读取文件内容
file_content = await payload.content.read()
# 保存文件到磁盘
with open(filename_1, 'wb') as f:
f.write(file_content)
return
解决了话可以关掉issue
接收图片的格式怎么设置?
app = FastAPI()
@app.post("/receive_msg") async def receive_msg(type: str = Form(), content: str = Form(),source:str = Form()):
https://github.com/danni-cool/wechatbot-webhook?tab=readme-ov-file#2-%E6%94%B6%E6%B6%88%E6%81%AF-api 看不明白