diff --git a/app/__pycache__/main.cpython-310.pyc b/app/__pycache__/main.cpython-310.pyc index d173cee..c108c2a 100644 Binary files a/app/__pycache__/main.cpython-310.pyc and b/app/__pycache__/main.cpython-310.pyc differ diff --git a/app/main.py b/app/main.py index 4993c63..a60989b 100644 --- a/app/main.py +++ b/app/main.py @@ -14,6 +14,7 @@ from fastapi.responses import FileResponse from fastapi.staticfiles import StaticFiles # from app import tgMessage # type: ignore #发送tg消息 from datetime import datetime +import requests # 初始化数据库 models.Base.metadata.create_all(bind=engine) @@ -49,7 +50,19 @@ def get_db(): # def root(): # return {"message": "Hello World"} - +def sengTgmesage(message): + url = "http://192.168.31.38:8521/send_message" + data = {"message":message} + headers = {"Content-Type": "application/json"} + response = requests.post(url, json=data, headers=headers) + try: + response_data = response.json() + print(response_data) + except requests.exceptions.JSONDecodeError: + print("Response content is not in JSON format") + print("Response content:", response.text) + + @app.get("/hello") def hello(): # response = f"你好,\n..........................\n一名开发者\n副业:跨境电商\n#公众号:异度世界\n..........................\n回复关键词,了解更多:\n1. 微信机器人\n2. 数字游民\n3. 加群\n..........................\n[该消息是接受好友自动回复]" @@ -77,12 +90,15 @@ def tgMessagefun(openid: Optional[str] = None, db: Session = Depends(get_db)): # message = f"{userInfo['nickname']}/{userInfo['gender']}在{current_time}进行了访问" message = f"{userInfo.nickname}/{userInfo.gender}在{current_time}进行了访问" print(message) + sengTgmesage(message) # tgMessage.sendTg(message) else: print('openid未关联') message = f'openid: {openid}-未关联,在{current_time}访问网页' print(message) + sengTgmesage(message) + # tgMessage.sendTg(message)