update
This commit is contained in:
64
app/main.py
64
app/main.py
@@ -15,6 +15,8 @@ from fastapi.staticfiles import StaticFiles
|
||||
# from app import tgMessage # type: ignore #发送tg消息
|
||||
from datetime import datetime
|
||||
import requests
|
||||
from tentcentSMS import sendSms
|
||||
import random
|
||||
|
||||
# 初始化数据库
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
@@ -50,9 +52,10 @@ def get_db():
|
||||
# def root():
|
||||
# return {"message": "Hello World"}
|
||||
|
||||
|
||||
def sengTgmesage(message):
|
||||
url = "http://192.168.31.38:8521/send_message"
|
||||
data = {"message":message}
|
||||
data = {"message": message}
|
||||
headers = {"Content-Type": "application/json"}
|
||||
response = requests.post(url, json=data, headers=headers)
|
||||
try:
|
||||
@@ -61,13 +64,13 @@ def sengTgmesage(message):
|
||||
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[该消息是接受好友自动回复]"
|
||||
response = f"你好,\n..........................\n一名开发者\n副业:跨境电商\n#公众号:异度世界\n..........................\n回复关键词,了解更多:\n1. 数字游民\n..........................\n[该消息是接受好友自动回复]"
|
||||
|
||||
|
||||
return PlainTextResponse(content=response)
|
||||
|
||||
|
||||
@@ -98,7 +101,7 @@ def tgMessagefun(openid: Optional[str] = None, db: Session = Depends(get_db)):
|
||||
message = f'openid: {openid}-未关联,在{current_time}访问网页'
|
||||
print(message)
|
||||
sengTgmesage(message)
|
||||
|
||||
|
||||
# tgMessage.sendTg(message)
|
||||
|
||||
|
||||
@@ -137,7 +140,6 @@ def generateqr(url="http://nomad.hackrobot.cn",
|
||||
# url="http://192.168.31.219:10086"
|
||||
if wxid:
|
||||
url += f"?wxid={wxid}"
|
||||
|
||||
|
||||
# 创建二维码
|
||||
qr = qrcode.QRCode(version=1, box_size=5, border=2) # 调整二维码大小
|
||||
@@ -204,7 +206,7 @@ def add_user(nickname: Optional[Any] = None,
|
||||
response = f"{nickname}你好,\n..........................\n一名开发者\n副业:跨境电商\n#公众号:异度世界\n..........................\n回复关键词,了解更多:\n1. 数字游民\n..........................\n[该消息是接受好友自动回复]"
|
||||
|
||||
# 关键词回复
|
||||
if keyword == '加群' or keyword =="数字游民" or keyword =="3" or keyword =="1":
|
||||
if keyword == '加群' or keyword == "数字游民" or keyword == "3" or keyword == "1":
|
||||
print("keyword==加群")
|
||||
combined_image_path = generateqr(url="http://nomad.hackrobot.cn",
|
||||
wxid=wxid,
|
||||
@@ -220,15 +222,17 @@ def add_user(nickname: Optional[Any] = None,
|
||||
elif keyword == '活动':
|
||||
print("keyword==活动")
|
||||
response = f"活动正在筹备中"
|
||||
combined_image_path = generateqr(url="http://nomad.hackrobot.cn",
|
||||
wxid=wxid,
|
||||
group_image_path="images/meetupqr.jpg")
|
||||
combined_image_path = generateqr(
|
||||
url="http://nomad.hackrobot.cn",
|
||||
wxid=wxid,
|
||||
group_image_path="images/meetupqr.jpg")
|
||||
return FileResponse(combined_image_path)
|
||||
elif keyword == 'qrcode':
|
||||
print("keyword==qrcode")
|
||||
combined_image_path = generateqr(url="http://nomad.hackrobot.cn",
|
||||
# wxid='qrcode',
|
||||
group_image_path="images/nomadqr.jpg")
|
||||
combined_image_path = generateqr(
|
||||
url="http://nomad.hackrobot.cn",
|
||||
# wxid='qrcode',
|
||||
group_image_path="images/nomadqr.jpg")
|
||||
return FileResponse(combined_image_path)
|
||||
else:
|
||||
print('其他keyword')
|
||||
@@ -276,3 +280,37 @@ def update_user(identifier: str,
|
||||
}
|
||||
|
||||
|
||||
# 获取手机号=>生成验证码
|
||||
@app.post("/get_verification_code/")
|
||||
def get_verification_code(wxid: str,
|
||||
phone_number: str,
|
||||
db: Session = Depends(get_db)):
|
||||
verification_code = '{:04d}'.format(random.randint(0, 9999))
|
||||
user = db.query(models.User).filter(models.User.wxid == wxid).first()
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
user.phone_number = phone_number
|
||||
user.verification_code = verification_code
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
"message": "Verification code sent",
|
||||
"verification_code": verification_code
|
||||
}
|
||||
|
||||
|
||||
# 验证码校验
|
||||
@app.post("/verify_code/")
|
||||
def verify_code(phone_number: str, code: str, db: Session = Depends(get_db)):
|
||||
user = db.query(
|
||||
models.User).filter(models.User.phone_number == phone_number).first()
|
||||
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
if user.verification_code == code:
|
||||
return {"message": "Verification successful"}
|
||||
else:
|
||||
raise HTTPException(status_code=400,
|
||||
detail="Invalid verification code")
|
||||
|
||||
Reference in New Issue
Block a user