|
@@ -2,18 +2,21 @@ package com.fs.wxcid.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
-import com.fs.wxcid.ImageToBase64Util;
|
|
|
|
|
|
|
+import com.fs.wxcid.FileToBase64Util;
|
|
|
import com.fs.wxcid.ServiceUtils;
|
|
import com.fs.wxcid.ServiceUtils;
|
|
|
import com.fs.wxcid.dto.common.ApiResponseCommon;
|
|
import com.fs.wxcid.dto.common.ApiResponseCommon;
|
|
|
import com.fs.wxcid.dto.login.RequestBaseVo;
|
|
import com.fs.wxcid.dto.login.RequestBaseVo;
|
|
|
|
|
+import com.fs.wxcid.dto.message.CdnUploadVideoResult;
|
|
|
import com.fs.wxcid.dto.message.MsgItem;
|
|
import com.fs.wxcid.dto.message.MsgItem;
|
|
|
import com.fs.wxcid.dto.message.RevokeMsgRequest;
|
|
import com.fs.wxcid.dto.message.RevokeMsgRequest;
|
|
|
import com.fs.wxcid.dto.message.SendImageMessageParam;
|
|
import com.fs.wxcid.dto.message.SendImageMessageParam;
|
|
|
import com.fs.wxcid.dto.message.SendTextMessageParam;
|
|
import com.fs.wxcid.dto.message.SendTextMessageParam;
|
|
|
|
|
+import com.fs.wxcid.dto.message.SendVideoMessageParam;
|
|
|
import com.fs.wxcid.dto.message.RevokeMsgResult;
|
|
import com.fs.wxcid.dto.message.RevokeMsgResult;
|
|
|
import com.fs.wxcid.dto.message.SendImageMessageResult;
|
|
import com.fs.wxcid.dto.message.SendImageMessageResult;
|
|
|
import com.fs.wxcid.dto.message.SendMessageResult;
|
|
import com.fs.wxcid.dto.message.SendMessageResult;
|
|
|
import com.fs.wxcid.dto.message.SendTextMessageRequest;
|
|
import com.fs.wxcid.dto.message.SendTextMessageRequest;
|
|
|
|
|
+import com.fs.wxcid.dto.message.SendVideoMessageRequest;
|
|
|
import com.fs.wxcid.service.MessageService;
|
|
import com.fs.wxcid.service.MessageService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -59,7 +62,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
MsgItem msgItem = new MsgItem();
|
|
MsgItem msgItem = new MsgItem();
|
|
|
try {
|
|
try {
|
|
|
msgItem.setMsgType(0);
|
|
msgItem.setMsgType(0);
|
|
|
- msgItem.setImageContent(ImageToBase64Util.convertImageUrlToBase64(param.getImgUrl()));
|
|
|
|
|
|
|
+ msgItem.setImageContent(FileToBase64Util.convertImageUrlToBase64(param.getImgUrl()));
|
|
|
msgItem.setToUserName(param.getToUser());
|
|
msgItem.setToUserName(param.getToUser());
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
log.error("发送消息时,图片转换base64错误", e);
|
|
log.error("发送消息时,图片转换base64错误", e);
|
|
@@ -93,4 +96,27 @@ public class MessageServiceImpl implements MessageService {
|
|
|
}
|
|
}
|
|
|
return response.getData();
|
|
return response.getData();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CdnUploadVideoResult sendVideoMessage(SendVideoMessageParam param) {
|
|
|
|
|
+ SendVideoMessageRequest request = new SendVideoMessageRequest();
|
|
|
|
|
+ request.setToUserName(param.getToUser());
|
|
|
|
|
+ try {
|
|
|
|
|
+ request.setThumbData(FileToBase64Util.downloadToBytes(param.getThumbUrl()));
|
|
|
|
|
+ request.setVideoData(FileToBase64Util.downloadToBytes(param.getVideoUrl()));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("发送视频消息时,文件下载失败", e);
|
|
|
|
|
+ throw new CustomException("视频消息发送失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ ApiResponseCommon<CdnUploadVideoResult> response = serviceUtils.sendPost(
|
|
|
|
|
+ BASE_URL + "CdnUploadVideo",
|
|
|
|
|
+ RequestBaseVo.builder().accountId(param.getAccountId()).data(request).build(),
|
|
|
|
|
+ new TypeReference<ApiResponseCommon<CdnUploadVideoResult>>() {}
|
|
|
|
|
+ );
|
|
|
|
|
+ CdnUploadVideoResult result = response.getData();
|
|
|
|
|
+ if (result != null && result.getRetCode() != null && result.getRetCode() != 0) {
|
|
|
|
|
+ throw new CustomException("视频上传失败,RetCode=" + result.getRetCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|