新增 消息定时推送功能

This commit is contained in:
liuwei
2025-06-10 12:35:08 +08:00
parent 924fe9dfd5
commit e43a2dc32c

View File

@@ -260,36 +260,45 @@ def api_preview_task(task_id):
if not preview_user: if not preview_user:
return jsonify({"success": False, "error": "未登录或会话已过期"}), 401 return jsonify({"success": False, "error": "未登录或会话已过期"}), 401
# 获取预览接收者列表 # 获取预览接收者并解析JSON
preview_recipients = task.get("preview_recipients", []) preview_recipients_str = task.get("preview_recipients", "[]")
try:
preview_recipients = json.loads(preview_recipients_str)
except json.JSONDecodeError:
return jsonify({"success": False, "error": "预览接收者格式错误"}), 400
if not preview_recipients: if not preview_recipients:
return jsonify({"success": False, "error": "未设置预览接收者"}), 400 return jsonify({"success": False, "error": "未设置预览接收者"}), 400
# 为每个接收者发送预览消息 # 为每个接收者发送预览消息
for recipient in preview_recipients: for recipient in preview_recipients:
# 发送文本消息 try:
if task.get('content_text'): # 发送文本消息
send_message_in_thread(server.client.send_text_message, recipient, task['content_text']) if task.get('content_text'):
send_message_in_thread(server.client.send_text_message, recipient, task['content_text'])
# 发送图片消息 # 发送图片消息
if task.get('content_image'): if task.get('content_image'):
send_message_in_thread(server.client.send_image_message, recipient, task['content_image']) send_message_in_thread(server.client.send_image_message, recipient, task['content_image'])
# 发送链接消息 # 发送链接消息
if task.get('content_link'): if task.get('content_link'):
send_message_in_thread(server.client.send_link_message, recipient, task['content_link']) send_message_in_thread(server.client.send_link_message, recipient, task['content_link'])
# # 发送小程序消息 # # 发送小程序消息
# if task.get('content_miniprogram'): # if task.get('content_miniprogram'):
# miniprogram = task['content_miniprogram'] # miniprogram = task['content_miniprogram']
# send_message_in_thread( # send_message_in_thread(
# server.client.send_miniprogram_message, # server.client.send_miniprogram_message,
# recipient, # recipient,
# miniprogram.get('title'), # miniprogram.get('title'),
# miniprogram.get('appid'), # miniprogram.get('appid'),
# miniprogram.get('pagepath'), # miniprogram.get('pagepath'),
# miniprogram.get('thumb_url') # miniprogram.get('thumb_url')
# ) # )
except Exception as e:
logger.error(f"发送预览消息到 {recipient} 失败: {e}")
continue
return jsonify({ return jsonify({
"success": True, "success": True,