后端添加tg通知
This commit is contained in:
Binary file not shown.
28
app/main.py
28
app/main.py
@@ -12,6 +12,9 @@ import qrcode
|
|||||||
import os
|
import os
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from app.tgMesaage import sendTg #发送tg消息
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
# 初始化数据库
|
# 初始化数据库
|
||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
@@ -53,6 +56,25 @@ def hello():
|
|||||||
response = f"你好,\n..........................\n一名开发者\n副业:跨境电商\n#公众号:异度世界\n..........................\n回复关键词,了解更多:\n1. 微信机器人\n2. 数字游民\n3. 加群\n..........................\n[该消息是接受好友自动回复]"
|
response = f"你好,\n..........................\n一名开发者\n副业:跨境电商\n#公众号:异度世界\n..........................\n回复关键词,了解更多:\n1. 微信机器人\n2. 数字游民\n3. 加群\n..........................\n[该消息是接受好友自动回复]"
|
||||||
return PlainTextResponse(content=response)
|
return PlainTextResponse(content=response)
|
||||||
|
|
||||||
|
@app.get("/tgMessage")
|
||||||
|
def tgMessage(openid: Optional[str] = None,db: Session = Depends(get_db)):
|
||||||
|
current_time = datetime.now()
|
||||||
|
print("Current Date and Time:", current_time)
|
||||||
|
# 发送tg消息通知 wxid_4413224132412 || o7LFAwR32hWGq9XOpd7ZxK1wZxq8
|
||||||
|
|
||||||
|
openid="o7LFAwR32hWGq9XOpd7ZxK1wZxq82"
|
||||||
|
print('openid',openid)
|
||||||
|
if openid:
|
||||||
|
# 查询用户信息:昵称
|
||||||
|
userInfo=read_user(openid,db=db)
|
||||||
|
if userInfo:
|
||||||
|
print('userInfo==>',userInfo)
|
||||||
|
message=f'{userInfo.nickname}/{userInfo.gender}在{current_time}进行了访问'
|
||||||
|
sendTg(message)
|
||||||
|
else:
|
||||||
|
print('openid未关联,在')
|
||||||
|
message=f'openid: {openid}-未关联,在{current_time}访问网页'
|
||||||
|
sendTg(message)
|
||||||
|
|
||||||
def create_user_task(db: Session, user: schemas.UserCreate):
|
def create_user_task(db: Session, user: schemas.UserCreate):
|
||||||
try:
|
try:
|
||||||
@@ -104,7 +126,8 @@ def read_users(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
|
|||||||
def read_user(identifier: str, db: Session = Depends(get_db)):
|
def read_user(identifier: str, db: Session = Depends(get_db)):
|
||||||
user = crud.get_user_by_openid_or_wxid(db, identifier=identifier)
|
user = crud.get_user_by_openid_or_wxid(db, identifier=identifier)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise HTTPException(status_code=404, detail="User not found")
|
# raise HTTPException(status_code=404, detail="User not found")
|
||||||
|
print('查询用户不存在')
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@@ -134,7 +157,8 @@ def generate_qr(wxid: Optional[str] = Query(None), db: Session = Depends(get_db)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
url = "https://web.hackrobot.cn"
|
# url = "https://web.hackrobot.cn"
|
||||||
|
url="http://192.168.31.219:10086"
|
||||||
if wxid:
|
if wxid:
|
||||||
url += f"?wxid={wxid}"
|
url += f"?wxid={wxid}"
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
Reference in New Issue
Block a user