Fix: send custom webhook JSON in UTF-8

CUSTOM webhooks were receiving JSON-escaped Unicode (e.g. \\u5229...) because requests' json= payload uses ensure_ascii=True by default.

Change send_to_custom() to serialize payload with json.dumps(..., ensure_ascii=False), send bytes as UTF-8, and set Content-Type to application/json; charset=utf-8.

Impact: receivers see proper Chinese characters in the payload fields.
This commit is contained in:
Loveyless
2026-01-14 08:23:19 +08:00
parent 7159fc6ccc
commit 16223a0be4

View File

@@ -15,6 +15,7 @@ A股自选股智能分析系统 - 通知层
"""
import logging
import json
import smtplib
import re
from datetime import datetime
@@ -1678,10 +1679,13 @@ class NotificationService:
'User-Agent': 'StockAnalysis/1.0'
}
body = json.dumps(payload, ensure_ascii=False).encode('utf-8')
headers_with_charset = dict(headers)
headers_with_charset['Content-Type'] = 'application/json; charset=utf-8'
response = requests.post(
url,
json=payload,
headers=headers,
data=body,
headers=headers_with_charset,
timeout=30
)