新增 消息定时推送功能
This commit is contained in:
@@ -260,13 +260,19 @@ 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'):
|
if task.get('content_text'):
|
||||||
send_message_in_thread(server.client.send_text_message, recipient, task['content_text'])
|
send_message_in_thread(server.client.send_text_message, recipient, task['content_text'])
|
||||||
@@ -290,6 +296,9 @@ def api_preview_task(task_id):
|
|||||||
# 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user