|
|
@@ -7,6 +7,9 @@ import com.fs.wxcid.ServiceUtils;
|
|
|
import com.fs.wxcid.dto.common.ApiResponseCommon;
|
|
|
import com.fs.wxcid.dto.login.RequestBaseVo;
|
|
|
import com.fs.wxcid.dto.message.MsgItem;
|
|
|
+import com.fs.wxcid.dto.message.RevokeMsgRequest;
|
|
|
+import com.fs.wxcid.dto.message.RevokeMsgResult;
|
|
|
+import com.fs.wxcid.dto.message.SendImageMessageResult;
|
|
|
import com.fs.wxcid.dto.message.SendMessageResult;
|
|
|
import com.fs.wxcid.dto.message.SendTextMessageRequest;
|
|
|
import com.fs.wxcid.service.MessageService;
|
|
|
@@ -24,7 +27,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
private ServiceUtils serviceUtils;
|
|
|
|
|
|
@Override
|
|
|
- public ApiResponseCommon<List<SendMessageResult>> sendTextMessage(Long accountId, String txt) {
|
|
|
+ public List<SendMessageResult> sendTextMessage(Long accountId, String txt) {
|
|
|
SendTextMessageRequest request = new SendTextMessageRequest();
|
|
|
List<MsgItem> list = new ArrayList<>();
|
|
|
MsgItem msgItem = new MsgItem();
|
|
|
@@ -43,34 +46,51 @@ public class MessageServiceImpl implements MessageService {
|
|
|
String errorMsg = "部分消息发送失败,失败接收人: " + String.join(", ", failedRecipients);
|
|
|
throw new CustomException("发送文本消息部分失败: " + errorMsg);
|
|
|
}
|
|
|
- return response;
|
|
|
+ return response.getData();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ApiResponseCommon<List<SendMessageResult>> sendImageMessage(Long accountId, String imgUrl) {
|
|
|
+ public List<SendImageMessageResult> sendImageMessage(Long accountId, String imgUrl, String toUser) {
|
|
|
SendTextMessageRequest request = new SendTextMessageRequest();
|
|
|
List<MsgItem> list = new ArrayList<>();
|
|
|
MsgItem msgItem = new MsgItem();
|
|
|
try {
|
|
|
+ msgItem.setMsgType(0);
|
|
|
msgItem.setImageContent(ImageToBase64Util.convertImageUrlToBase64(imgUrl));
|
|
|
+ msgItem.setToUserName(toUser);
|
|
|
}catch (Exception e){
|
|
|
log.error("发送消息时,图片转换base64错误", e);
|
|
|
throw new CustomException("图片消息发送失败");
|
|
|
}
|
|
|
+ list.add(msgItem);
|
|
|
request.setMsgItem(list);
|
|
|
- ApiResponseCommon<List<SendMessageResult>> response = serviceUtils.sendPost(BASE_URL + "SendImageNewMessage", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<List<SendMessageResult>>>() {});
|
|
|
- // 第二层:检查每条消息是否真正发送成功
|
|
|
- List<SendMessageResult> results = response.getData();
|
|
|
+ ApiResponseCommon<List<SendImageMessageResult>> response = serviceUtils.sendPost(BASE_URL + "SendImageNewMessage", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<List<SendImageMessageResult>>>() {});
|
|
|
+ // 第二层:检查每条消息是否真正发送成功(根据 resp.baseResponse.ret == 0 判断)
|
|
|
+ List<SendImageMessageResult> results = response.getData();
|
|
|
List<String> failedRecipients = new ArrayList<>();
|
|
|
- for (SendMessageResult result : results) {
|
|
|
+ for (SendImageMessageResult result : results) {
|
|
|
if (!result.isSendSuccess()) {
|
|
|
failedRecipients.add(result.getToUserName());
|
|
|
}
|
|
|
}
|
|
|
if (!failedRecipients.isEmpty()) {
|
|
|
- String errorMsg = "部分消息发送失败,失败接收人: " + String.join(", ", failedRecipients);
|
|
|
- throw new CustomException("发送文本消息部分失败: " + errorMsg);
|
|
|
+ String errorMsg = "部分图片消息发送失败,失败接收人: " + String.join(", ", failedRecipients);
|
|
|
+ throw new CustomException("发送图片消息部分失败: " + errorMsg);
|
|
|
+ }
|
|
|
+ return response.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RevokeMsgResult revokeMessage(Long accountId, Long msgId, String toUserName) {
|
|
|
+ RevokeMsgRequest request = new RevokeMsgRequest();
|
|
|
+ request.setMsgId(msgId);
|
|
|
+ request.setToUserName(toUserName);
|
|
|
+ ApiResponseCommon<RevokeMsgResult> response = serviceUtils.sendPost(BASE_URL + "RevokeMsgNew", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<RevokeMsgResult>>() {});
|
|
|
+ RevokeMsgResult result = response.getData();
|
|
|
+ if (result != null && !result.isSuccess()) {
|
|
|
+ String errorMsg = result.getSysWording() != null ? result.getSysWording() : "消息撤回失败";
|
|
|
+ throw new CustomException(errorMsg);
|
|
|
}
|
|
|
- return response;
|
|
|
+ return response.getData();
|
|
|
}
|
|
|
}
|