From 8403d24be36f3bfaad5edf992989cf915078cd8c Mon Sep 17 00:00:00 2001 From: root Date: Sun, 1 Mar 2026 09:27:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A3=9E=E4=B9=A6?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=8C=E9=87=8D=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: 1. FeishuNotificationService 中先 json_encode 然后 HttpClient 又 json_encode 2. 导致 emoji 被双重编码,飞书 API 报错 200621 修复: 1. 直接传递数组给 HttpClient,让 HttpClient 统一进行编码 2. HttpClient 中使用 JSON_UNESCAPED_UNICODE 避免 emoji 转义 3. 移除了 FeishuNotificationService 中的中间编码步骤 --- backend/app/service/FeishuNotificationService.php | 9 +++------ backend/app/util/HttpClient.php | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/backend/app/service/FeishuNotificationService.php b/backend/app/service/FeishuNotificationService.php index ad6817c..c261bf2 100644 --- a/backend/app/service/FeishuNotificationService.php +++ b/backend/app/service/FeishuNotificationService.php @@ -563,9 +563,6 @@ class FeishuNotificationService $app = $this->getAppConfig(); $token = $this->getAccessToken(); - // 使用 JSON_UNESCAPED_UNICODE 避免 emoji 被转义 - $content = json_encode(['card' => $card], JSON_UNESCAPED_UNICODE); - error_log('📤 发送飞书消息: app_id=' . $app['app_id'] . ', feishu_user_id=' . $feishuUserId); error_log('📦 消息卡片: ' . json_encode($card, JSON_UNESCAPED_UNICODE)); @@ -574,7 +571,7 @@ class FeishuNotificationService [ 'receive_id' => $feishuUserId, 'msg_type' => 'interactive', - 'content' => $content, + 'content' => ['card' => $card], // 直接传递数组,让 HttpClient 进行编码 ], [ 'Authorization: Bearer ' . $token, @@ -714,8 +711,8 @@ class FeishuNotificationService "https://open.feishu.cn/open-apis/im/v1/messages/{$message->message_id}/update", [ 'msg_type' => 'interactive', - // 使用 JSON_UNESCAPED_UNICODE 避免 emoji 被转义 - 'content' => json_encode(['card' => $updatedCard], JSON_UNESCAPED_UNICODE), + // 直接传递数组,让 HttpClient 进行编码 + 'content' => ['card' => $updatedCard], ], [ 'Authorization: Bearer ' . $token, diff --git a/backend/app/util/HttpClient.php b/backend/app/util/HttpClient.php index 1454408..d513404 100644 --- a/backend/app/util/HttpClient.php +++ b/backend/app/util/HttpClient.php @@ -88,7 +88,8 @@ class HttpClient curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + // 使用 JSON_UNESCAPED_UNICODE 避免 emoji 被转义 + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ?: self::$defaultTimeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);