QyMsgAttachmentConvert.java
6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package cn.com.glsx.entmicro.converter;
import cn.com.glsx.entmicro.constants.DracConstant;
import cn.com.glsx.entmicro.dto.DracScrmWelcomeConfigDTO;
import cn.com.glsx.scrm.wechat.dto.workwechat.externalmsg.*;
import com.alibaba.fastjson.JSONObject;
/**
* @author wangxw
* @version 1.0.0
* @ClassName QyMsgAttachmentConvert.java
* @description: ${description}
* @createTime 2021年11月11日 11:53:00
*/
public class QyMsgAttachmentConvert {
private static final int TEXT = 1;
private static final int IMAGE = 2;
private static final int VEDIO = 3;
private static final int URI = 4;
private static final int MINIPROGRAM = 5;
private static final int FILE = 6;
private static final String link_title_key = "title";
private static final String link_desc_key = "desc";
private static final String link_picurl_key = "picurl";
private static final String link_url_key = "url";
private static final String miniprogram_appid_key = "appId";
private static final String miniprogram_title_key = "title";
private static final String miniprogram_page_key = "page";
private static final String miniprogram_mediaid_key = "mediaId";
/**
* 支持的资源内容:
* 第一种:图片
* 第二种:视频
* 第三种:链接
* 第四种:小程序
* 第五种:文件
*
* @param dracWelcomeConfig
* @return
*/
public static WorkWechatExternalContactMsgAttachmentDTO convertAttachment(DracScrmWelcomeConfigDTO dracWelcomeConfig) {
WorkWechatExternalContactMsgAttachmentDTO attachmentDTO = null;
switch (dracWelcomeConfig.getAttType()) {
case IMAGE:
attachmentDTO = convertImageAttachment(dracWelcomeConfig);
break;
case VEDIO:
attachmentDTO = convertVedioAttachment(dracWelcomeConfig);
break;
case URI:
attachmentDTO = convertUriAttachment(dracWelcomeConfig);
break;
case MINIPROGRAM:
attachmentDTO = convertMiniprogramAttachment(dracWelcomeConfig);
break;
case FILE:
attachmentDTO = convertFileAttachment(dracWelcomeConfig);
break;
default:
break;
}
return attachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertImageAttachment(DracScrmWelcomeConfigDTO dracWelcomeConfig) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachImageDTO imageAtt = new WorkWechatExternalContactMsgAttachImageDTO();
imageAtt.setMediaId(dracWelcomeConfig.getMediaId());
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.IMAGE);
workWechatExternalContactMsgAttachmentDTO.setImage(imageAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertVedioAttachment(DracScrmWelcomeConfigDTO dracWelcomeConfig) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachVideoDTO vedioAtt = new WorkWechatExternalContactMsgAttachVideoDTO();
vedioAtt.setMediaId(dracWelcomeConfig.getMediaId());
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.VEDIO);
workWechatExternalContactMsgAttachmentDTO.setVideo(vedioAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertUriAttachment(DracScrmWelcomeConfigDTO dracWelcomeConfig) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachLinkDTO linkAtt = new WorkWechatExternalContactMsgAttachLinkDTO();
JSONObject contentJson = JSONObject.parseObject(dracWelcomeConfig.getAttContent());
// {"title":"头号新闻","url":"http://xxxxx/yy/xx"}
linkAtt.setTitle(contentJson.getString(link_title_key));
linkAtt.setUrl(contentJson.getString(link_url_key));
linkAtt.setDesc(contentJson.getString(link_desc_key));
linkAtt.setPicUrl(contentJson.getString(link_picurl_key));
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.URI);
workWechatExternalContactMsgAttachmentDTO.setLink(linkAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertMiniprogramAttachment(DracScrmWelcomeConfigDTO dracWelcomeConfig) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachMiniprogramDTO miniprogramAtt = new WorkWechatExternalContactMsgAttachMiniprogramDTO();
JSONObject contentJson = JSONObject.parseObject(dracWelcomeConfig.getAttContent());
// {"appId":"","title":"头号新闻","page":"http://xxxxx/yy/xx","pic_url":"http://xxxxx/yy/xx","mediaId":""}
miniprogramAtt.setAppId(contentJson.getString(miniprogram_appid_key));
miniprogramAtt.setTitle(contentJson.getString(miniprogram_title_key));
miniprogramAtt.setPage(contentJson.getString(miniprogram_page_key));
miniprogramAtt.setPicMediaId(contentJson.getString(miniprogram_mediaid_key));
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.MINIPROGRAM);
workWechatExternalContactMsgAttachmentDTO.setMiniprogram(miniprogramAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertFileAttachment(DracScrmWelcomeConfigDTO dracWelcomeConfig) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachFileDTO fileAtt = new WorkWechatExternalContactMsgAttachFileDTO();
fileAtt.setMediaId(dracWelcomeConfig.getMediaId());
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.FILE);
workWechatExternalContactMsgAttachmentDTO.setFile(fileAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
/**
* 转换文本内容资源
* @param dracWelcomeConfig
* @return
*/
public static WorkWechatExternalContactMsgTextDTO convertTextAttachment(DracScrmWelcomeConfigDTO dracWelcomeConfig) {
WorkWechatExternalContactMsgTextDTO workWechatExternalContactMsgTextDTO = new WorkWechatExternalContactMsgTextDTO();
workWechatExternalContactMsgTextDTO.setContent(dracWelcomeConfig.getAttContent());
return workWechatExternalContactMsgTextDTO;
}
}