QyAttachmentTest.java
4.54 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
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.constants.DracConstant;
import cn.com.glsx.entmicro.request.one.template.QyAttachmentVo;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
/**
* @author wangxw
* @version 1.0.0
* @ClassName QyAttachmentTest.java
* @description: ${description}
* @createTime 2021年11月13日 16:04:00
*/
public class QyAttachmentTest {
/*
public static final Integer TEXT = 1;
public static final Integer IMAGE = 2;
public static final Integer VEDIO = 3;
public static final Integer URI = 4;
public static final Integer MINIPROGRAM = 5;
public static final Integer FILE = 6;
public static final String TEXT = "text";
public static final String IMAGE = "image";
public static final String VEDIO = "video";
public static final String URI = "link";
public static final String MINIPROGRAM = "miniprogram";
public static final String FILE = "file";
*/
@Test
public void testQyAttachment() {
QyAttachmentVo textAtt = initTextAttachment();
QyAttachmentVo imageAtt = initImageAttachment();
QyAttachmentVo videoAtt = initVideoAttachment();
QyAttachmentVo linkAtt = initLinkAttachment();
QyAttachmentVo miniAtt = initMiniAttachment();
QyAttachmentVo fileAtt = initFileAttachment();
List<QyAttachmentVo> attList = new ArrayList<>();
attList.add(textAtt);
attList.add(imageAtt);
attList.add(videoAtt);
attList.add(linkAtt);
attList.add(miniAtt);
attList.add(fileAtt);
System.out.println("==" + JSONObject.toJSONString(attList).replace("\\", "").replace("\"{", "{").replace("}\"", "}"));
}
private QyAttachmentVo initTextAttachment() {
QyAttachmentVo att = new QyAttachmentVo();
att.setAttType(DracConstant.AttType.TEXT);
att.setAttContent("欢迎加我为好友");
return att;
}
private QyAttachmentVo initImageAttachment() {
QyAttachmentVo att = new QyAttachmentVo();
att.setAttType(DracConstant.AttType.IMAGE);
att.setAttContent("http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png");
return att;
}
private QyAttachmentVo initVideoAttachment() {
QyAttachmentVo att = new QyAttachmentVo();
att.setAttType(DracConstant.AttType.VEDIO);
att.setAttContent("http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png");
return att;
}
private QyAttachmentVo initLinkAttachment() {
QyAttachmentVo att = new QyAttachmentVo();
att.setAttType(DracConstant.AttType.URI);
att.setAttContent("{\"title\": \"消息标题\",\"url\": \"https://example.link.com/path\"}");
return att;
}
private QyAttachmentVo initMiniAttachment() {
QyAttachmentVo att = new QyAttachmentVo();
att.setAttType(DracConstant.AttType.MINIPROGRAM);
att.setAttContent("{\"title\": \"消息标题\",\"pic_url\": \"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"appid\": \"wx8bd80126147dfAAA\",\"page\": \"/path/index.html\"}");
return att;
}
private QyAttachmentVo initFileAttachment() {
QyAttachmentVo att = new QyAttachmentVo();
att.setAttType(DracConstant.AttType.FILE);
att.setAttContent("http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png");
return att;
}
@Test
public void testParseAttJson() {
String base = "[{\"attContent\":\"欢迎加我为好友\",\"attType\":1},{\"attContent\":\"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"attType\":2},{\"attContent\":\"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"attType\":3},{\"attContent\":{\"title\": \"消息标题\",\"url\": \"https://example.link.com/path\"},\"attType\":4},{\"attContent\":{\"title\": \"消息标题\",\"pic_url\": \"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"appid\": \"wx8bd80126147dfAAA\",\"page\": \"/path/index.html\"},\"attType\":5},{\"attContent\":\"http://qcimg01.glsx.net:7060/upload/account/37aebeeb-5186-41af-9695-d361b321125e.png\",\"attType\":6}]";
List<QyAttachmentVo> attachmentVoList = JSONObject.parseArray(base, QyAttachmentVo.class);
System.out.println("==" + JSONObject.toJSONString(attachmentVoList));
}
}