diff --git a/server/src/XiangYi.Application/Services/NotificationService.cs b/server/src/XiangYi.Application/Services/NotificationService.cs index 78119db..deaf336 100644 --- a/server/src/XiangYi.Application/Services/NotificationService.cs +++ b/server/src/XiangYi.Application/Services/NotificationService.cs @@ -251,7 +251,7 @@ public class NotificationService : INotificationService targetUser.ServiceAccountOpenId, NotificationTemplateType.Unlock, "来访通知", - unlockerUser?.Nickname ?? "有人", + (unlockerUser?.Nickname ?? "有人") + " 解锁了您", $"编号{unlockerUser?.XiangQinNo ?? "未知"}刚刚访问了您", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "pages/interact/unlockedMe", @@ -311,7 +311,7 @@ public class NotificationService : INotificationService targetUser.ServiceAccountOpenId, NotificationTemplateType.Favorite, "收藏通知", - favoriterUser?.Nickname ?? "有人", + (favoriterUser?.Nickname ?? "有人") + " 收藏了您", $"编号{favoriterUser?.XiangQinNo ?? "未知"}收藏了您", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "pages/interact/favoritedMe", @@ -371,7 +371,7 @@ public class NotificationService : INotificationService targetUser.ServiceAccountOpenId, NotificationTemplateType.FirstMessage, "消息通知", - senderUser?.Nickname ?? "有人", + (senderUser?.Nickname ?? "有人") + " 联系了您", $"编号{senderUser?.XiangQinNo ?? "未知"}给您发送了一条消息", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "pages/chat/index", @@ -431,7 +431,7 @@ public class NotificationService : INotificationService targetUser.ServiceAccountOpenId, NotificationTemplateType.MessageReminder, "消息提醒", - senderUser?.Nickname ?? "有人", + (senderUser?.Nickname ?? "有人") + " 等待您回复", $"编号{senderUser?.XiangQinNo ?? "未知"}正在等待您的回复", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "pages/chat/index", diff --git a/server/src/XiangYi.Infrastructure/WeChat/WeChatService.cs b/server/src/XiangYi.Infrastructure/WeChat/WeChatService.cs index f8c5325..62c438b 100644 --- a/server/src/XiangYi.Infrastructure/WeChat/WeChatService.cs +++ b/server/src/XiangYi.Infrastructure/WeChat/WeChatService.cs @@ -346,12 +346,26 @@ public class WeChatService : IWeChatService miniprogram_state = request.MiniprogramState }; - var response = await _httpClient.PostAsJsonAsync(url, requestBody); - var result = await response.Content.ReadFromJsonAsync(); + var jsonContent = System.Text.Json.JsonSerializer.Serialize(requestBody); + var httpRequest = new HttpRequestMessage(HttpMethod.Post, url) + { + Content = new StringContent(jsonContent, Encoding.UTF8, "application/json") + }; + + var response = await _httpClient.SendAsync(httpRequest); + var responseContent = await response.Content.ReadAsStringAsync(); + + if (string.IsNullOrWhiteSpace(responseContent)) + { + _logger.LogWarning("发送订阅消息失败: 微信返回空响应, StatusCode={StatusCode}, ToUser={ToUser}", (int)response.StatusCode, request.ToUser); + return false; + } + + var result = System.Text.Json.JsonSerializer.Deserialize(responseContent); if (result?.ErrCode != 0) { - _logger.LogWarning("发送订阅消息失败: {ErrCode} - {ErrMsg}", result?.ErrCode, result?.ErrMsg); + _logger.LogWarning("发送订阅消息失败: {ErrCode} - {ErrMsg}, ToUser={ToUser}", result?.ErrCode, result?.ErrMsg, request.ToUser); return false; } @@ -360,7 +374,7 @@ public class WeChatService : IWeChatService } catch (Exception ex) { - _logger.LogError(ex, "发送订阅消息异常"); + _logger.LogError(ex, "发送订阅消息异常: ToUser={ToUser}", request.ToUser); return false; } }