ts
This commit is contained in:
+50
-27
@@ -444,38 +444,61 @@ async def get_login_status():
|
||||
|
||||
@app.post("/api/login/qrcode")
|
||||
async def generate_qrcode():
|
||||
"""模拟登录成功"""
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
"""重定向到小红书官方登录页面"""
|
||||
# 返回小红书登录页面 URL
|
||||
login_url = "https://www.xiaohongshu.com/login"
|
||||
|
||||
# 生成登录状态(模拟登录成功)
|
||||
login_id = str(uuid.uuid4())
|
||||
current_time = datetime.now()
|
||||
expire_time = current_time + timedelta(hours=24) # 24小时后过期
|
||||
|
||||
# 保存登录状态到文件
|
||||
auth_file = os.path.join(config.DATA_DIR, "auth_state.json")
|
||||
auth_data = {
|
||||
"logged_in": True,
|
||||
"login_time": current_time.isoformat(),
|
||||
"expire_time": expire_time.isoformat(),
|
||||
"login_id": login_id,
|
||||
"platform": "xiaohongshu"
|
||||
}
|
||||
|
||||
with open(auth_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(auth_data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
# 返回登录信息
|
||||
return {
|
||||
"login_id": login_id,
|
||||
"login_time": current_time.isoformat(),
|
||||
"expire_time": expire_time.isoformat(),
|
||||
"message": "登录成功(模拟)",
|
||||
"expire_in_hours": 24
|
||||
"login_url": login_url,
|
||||
"message": "请在打开的小红书页面完成扫码登录",
|
||||
"instruction": "登录成功后,返回此页面点击'验证登录'按钮"
|
||||
}
|
||||
|
||||
|
||||
@app.post("/api/login/verify")
|
||||
async def verify_login():
|
||||
"""验证登录状态"""
|
||||
try:
|
||||
auth_file = os.path.join(config.DATA_DIR, "auth_state.json")
|
||||
|
||||
if not os.path.exists(auth_file):
|
||||
return {
|
||||
"success": False,
|
||||
"message": "未找到登录状态,请先登录"
|
||||
}
|
||||
|
||||
with open(auth_file, 'r', encoding='utf-8') as f:
|
||||
auth_data = json.load(f)
|
||||
|
||||
# 检查登录是否过期
|
||||
login_time = auth_data.get("login_time")
|
||||
expire_time = auth_data.get("expire_time")
|
||||
current_time = datetime.now().isoformat()
|
||||
|
||||
if expire_time and current_time > expire_time:
|
||||
# 登录已过期,清除状态
|
||||
os.remove(auth_file)
|
||||
return {
|
||||
"success": False,
|
||||
"message": "登录已过期,请重新登录"
|
||||
}
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": "登录成功",
|
||||
"logged_in": True,
|
||||
"login_time": login_time,
|
||||
"expire_time": expire_time,
|
||||
"expire_in_hours": 24
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"success": False,
|
||||
"message": f"验证失败: {str(e)}"
|
||||
}
|
||||
|
||||
|
||||
@app.post("/api/logout")
|
||||
async def logout():
|
||||
"""退出登录"""
|
||||
|
||||
Reference in New Issue
Block a user