|
|
@@ -10,6 +10,7 @@ import com.alibaba.fastjson.TypeReference;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -28,12 +29,26 @@ public class MessageServiceImpl implements MessageService {
|
|
|
new TypeReference<ApiResponseCommon<List<SendMessageResult>>>() {}
|
|
|
);
|
|
|
|
|
|
- //统一异常判断:只要 code 不是 200,就抛异常
|
|
|
+ // 第一层:检查 HTTP/协议级错误
|
|
|
if (response.getCode() != 200 || response.getData() == null) {
|
|
|
String errorMsg = response.getText() != null ? response.getText() : "发送消息失败,未知错误";
|
|
|
throw new CustomException("发送文本消息失败: " + errorMsg);
|
|
|
}
|
|
|
|
|
|
+ // 第二层:检查每条消息是否真正发送成功
|
|
|
+ List<SendMessageResult> results = response.getData();
|
|
|
+ List<String> failedRecipients = new ArrayList<>();
|
|
|
+ for (SendMessageResult result : results) {
|
|
|
+ if (!result.isSendSuccess()) {
|
|
|
+ failedRecipients.add(result.getToUserName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!failedRecipients.isEmpty()) {
|
|
|
+ String errorMsg = "部分消息发送失败,失败接收人: " + String.join(", ", failedRecipients);
|
|
|
+ throw new CustomException("发送文本消息部分失败: " + errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
return response;
|
|
|
}
|
|
|
|