|
14 | 14 | </a> |
15 | 15 | </p> |
16 | 16 |
|
| 17 | + |
| 18 | +**v1与v2版本存在差异,v1版本为原始版本,v2版本为重构版本,v2版本支持更多消息类型,更加灵活,v1版本不再维护,建议使用v2版本** |
| 19 | + |
17 | 20 | # pom |
18 | 21 |
|
19 | 22 | ```xml |
|
25 | 28 | </dependency> |
26 | 29 | ``` |
27 | 30 |
|
| 31 | +# 功能列表 |
| 32 | + |
| 33 | +- [x] 发送文本消息 |
| 34 | +- [x] 发送富文本消息 |
| 35 | +- [x] 发送群名片消息 |
| 36 | +- [x] 发送图片消息 |
| 37 | + |
| 38 | +<!-- @formatter:off --> |
28 | 39 | # example |
29 | 40 |
|
30 | | -## text |
| 41 | +## 发送文本消息 |
31 | 42 |
|
32 | 43 | ```java |
33 | | -TextMessage message = TextMessage |
34 | | - .builder() |
35 | | - .content("test") |
36 | | - .atAll(false) |
37 | | - .build(); |
38 | | -String webhok = System.getenv("webhok"); |
39 | | -String secret = System.getenv("secret"); |
| 44 | +TextMessage message = TextMessage.of("新更新提醒"); |
| 45 | +String secret = ""; |
| 46 | +String webhook = ""; |
40 | 47 | FeishuRobotClient send = new FeishuRobotClient(); |
41 | | - send. |
42 | | - |
43 | | -setSecret(secret); |
44 | | - send. |
45 | | - |
46 | | -setWebhook(webhok); |
| 48 | +send.setSecret(secret); |
| 49 | +send.setWebhook(webhook); |
47 | 50 |
|
48 | 51 | FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message); |
49 | 52 | ``` |
50 | 53 |
|
51 | | -## image |
| 54 | +## 发送富文本消息 |
52 | 55 |
|
53 | | -```java |
54 | | -ImageMessage message = ImageMessage |
55 | | - .builder() |
56 | | - .imageKey("img_7ea74629-9191-4176-998c-2e603c9c5e8g") |
57 | | - .build(); |
58 | | -String webhok = System.getenv("webhok"); |
59 | | -String secret = System.getenv("secret"); |
60 | | -FeishuRobotClient send = new FeishuRobotClient(); |
61 | | - send. |
| 56 | +```java |
| 57 | + PostMessage message = PostMessage.of() |
| 58 | + .addContent(Paragraph |
| 59 | + .of() |
| 60 | + .setTitle("项目更新通知") |
| 61 | + .newLine() |
| 62 | + .addContent(TextTag.of("项目有更新: ")) |
| 63 | + .addContent(ATag.of("请查看", "http://www.example.com/")) |
| 64 | + .addContent(AtTag.of().atAll())); |
62 | 65 |
|
63 | | -setSecret(secret); |
64 | | - send. |
65 | | - |
66 | | -setWebhook(webhok); |
| 66 | +String webhook = ""; |
| 67 | +String secret = ""; |
| 68 | +FeishuRobotClient send = new FeishuRobotClient(); |
| 69 | +send.setSecret(secret); |
| 70 | +send.setWebhook(webhook); |
67 | 71 |
|
68 | 72 | FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message); |
69 | 73 | ``` |
70 | 74 |
|
71 | | -## post |
| 75 | +## 发送群名片消息 |
72 | 76 |
|
73 | 77 | ```java |
74 | | -PostMessage message = PostMessage.build().lang( |
75 | | - PostLang.builder() |
76 | | - .lang("zh_cn") |
77 | | - .unit( |
78 | | - PostUnit.build() |
79 | | - .title("项目更新通知") |
80 | | - .addTags( |
81 | | - PostTags.build().addTags( |
82 | | - TextTag.builder().text("项目有更新: ").enter().build(), |
83 | | - ATag.builder().text("请查看").href("http://www.example.com/").build(), |
84 | | - AtTag.builder().atAll(true).build() |
85 | | - ) |
86 | | - ) |
87 | | - ) |
88 | | - .build() |
89 | | -); |
90 | | -String webhok = System.getenv("webhok"); |
91 | | -String secret = System.getenv("secret"); |
| 78 | + ShareChatMessage message = ShareChatMessage.of("oc_f5b1a7eb27ae2****339ff"); |
| 79 | +String webhook = ""; |
| 80 | +String secret = ""; |
92 | 81 | FeishuRobotClient send = new FeishuRobotClient(); |
93 | | - send. |
94 | | - |
95 | | -setSecret(secret); |
96 | | - send. |
97 | | - |
98 | | -setWebhook(webhok); |
99 | | - |
| 82 | +send.setSecret(secret); |
| 83 | +send.setWebhook(webhook); |
100 | 84 | FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message); |
101 | 85 | ``` |
102 | 86 |
|
103 | | -## interactive |
| 87 | +## 发送图片消息 |
104 | 88 |
|
105 | 89 | ```java |
106 | | -InteractiveMessage message = InteractiveMessage.build(); |
107 | | - message. |
108 | | - |
109 | | -config(CardConfig.builder(). |
110 | | - |
111 | | -wideScreenMode(true). |
112 | | - |
113 | | -build()); |
114 | | - message. |
115 | | - |
116 | | -setHeader(CardHeader.builder(). |
117 | | - |
118 | | -title(CardTitle.build(). |
119 | | - |
120 | | -content("\uD83D\uDC08 英国短毛猫")). |
121 | | - |
122 | | -template("indigo"). |
123 | | - |
124 | | -build()); |
125 | | - message. |
126 | | - |
127 | | -addElements( |
128 | | - ContentModule.build() |
129 | | - . |
130 | | - |
131 | | -text(Text.builder(). |
132 | | - |
133 | | -tag(TextTag.LARK_MD). |
134 | | - |
135 | | -content("英国短毛猫,体形圆胖,四肢短粗发达,毛短而密,头大脸圆,对人友善。 "+ |
136 | | - "\n其历史可追溯至古罗马时期的家猫,由于拥有悠久的育种历史,称得上是猫家族中的典范。"). |
137 | | - |
138 | | -build()) |
139 | | - . |
140 | | - |
141 | | -extra(Image.builder(). |
142 | | - |
143 | | -imgKey("img_70558e3a-2eef-4e8f-9a07-a701c165431g"). |
144 | | - |
145 | | -alt( |
146 | | - Text.builder(). |
147 | | - |
148 | | -tag(TextTag.PLAIN_TEXT). |
149 | | - |
150 | | -content("图片"). |
151 | | - |
152 | | -build()). |
153 | | - |
154 | | -build()), |
155 | | - ContentModule. |
156 | | - |
157 | | -build() |
158 | | - . |
159 | | - |
160 | | -addField( |
161 | | - Field.builder(). |
162 | | - |
163 | | -isShort(true). |
164 | | - |
165 | | -text(Text.builder(). |
166 | | - |
167 | | -tag(TextTag.LARK_MD). |
168 | | - |
169 | | -content("**中文学名:**\n英国短毛猫"). |
170 | | - |
171 | | -build()). |
172 | | - |
173 | | -build(), |
174 | | - Field. |
175 | | - |
176 | | -builder(). |
177 | | - |
178 | | -isShort(true). |
179 | | - |
180 | | -text(Text.builder(). |
181 | | - |
182 | | -tag(TextTag.LARK_MD). |
183 | | - |
184 | | -content("**拉丁学名:**\nFelinae"). |
185 | | - |
186 | | -build()). |
187 | | - |
188 | | -build(), |
189 | | - Field. |
190 | | - |
191 | | -builder(). |
192 | | - |
193 | | -isShort(false). |
194 | | - |
195 | | -text(Text.builder(). |
196 | | - |
197 | | -tag(TextTag.LARK_MD). |
198 | | - |
199 | | -content(" "). |
200 | | - |
201 | | -build()). |
202 | | - |
203 | | -build(), |
204 | | - Field. |
205 | | - |
206 | | -builder(). |
207 | | - |
208 | | -isShort(true). |
209 | | - |
210 | | -text(Text.builder(). |
211 | | - |
212 | | -tag(TextTag.LARK_MD). |
213 | | - |
214 | | -content("**体形:**\n圆胖"). |
215 | | - |
216 | | -build()). |
217 | | - |
218 | | -build(), |
219 | | - Field. |
220 | | - |
221 | | -builder(). |
222 | | - |
223 | | -isShort(true). |
224 | | - |
225 | | -text(Text.builder(). |
226 | | - |
227 | | -tag(TextTag.LARK_MD). |
228 | | - |
229 | | -content("**被毛:**\n短而浓密、俗称地毯毛"). |
230 | | - |
231 | | -build()). |
232 | | - |
233 | | -build() |
234 | | - ), |
235 | | - HrModule. |
236 | | - |
237 | | -builder(). |
238 | | - |
239 | | -build(), |
240 | | - ContentModule. |
241 | | - |
242 | | -build() |
243 | | - . |
244 | | - |
245 | | -text(Text.builder(). |
246 | | - |
247 | | -tag(TextTag.LARK_MD). |
248 | | - |
249 | | -content("**1 形态特征**\n\n 🔵 外形:身体厚实,胸部饱满宽阔,腿部粗壮,爪子浑圆,尾巴的根部粗壮,尾尖钝圆。\n\n🔵 毛色:共有十五种品种被承认,其中最著名的是蓝色系的英国短毛猫。 "). |
250 | | - |
251 | | -build()) |
252 | | - . |
253 | | - |
254 | | -extra(Image.builder(). |
255 | | - |
256 | | -imgKey("img_70558e3a-2eef-4e8f-9a07-a701c165431g"). |
257 | | - |
258 | | -alt(Text.builder(). |
259 | | - |
260 | | -tag(TextTag.PLAIN_TEXT). |
261 | | - |
262 | | -content("图片"). |
263 | | - |
264 | | -build()). |
265 | | - |
266 | | -build()), |
267 | | - NoteModule. |
268 | | - |
269 | | -build(). |
270 | | - |
271 | | -addElement( |
272 | | - Image.builder(). |
273 | | - |
274 | | -imgKey("img_e61db329-2469-4da7-8f13-2d2f284c3b1g"). |
275 | | - |
276 | | -alt(Text.builder(). |
277 | | - |
278 | | -tag(TextTag.PLAIN_TEXT). |
279 | | - |
280 | | -content("图片"). |
281 | | - |
282 | | -build()). |
283 | | - |
284 | | -build(), |
285 | | - Text. |
286 | | - |
287 | | -builder(). |
288 | | - |
289 | | -tag(TextTag.PLAIN_TEXT). |
290 | | - |
291 | | -content("以上资料来自百度百科"). |
292 | | - |
293 | | -build() |
294 | | - ) |
295 | | - ); |
296 | | -String webhok = System.getenv("webhok"); |
297 | | -String secret = System.getenv("secret"); |
| 90 | + ImageMessage message = ImageMessage.of("img_7ea74629-9191-4176-998c-2e603c9c5e8g"); |
| 91 | +String webhook = ""; |
| 92 | +String secret = ""; |
298 | 93 | FeishuRobotClient send = new FeishuRobotClient(); |
299 | | - send. |
300 | | - |
301 | | -setSecret(secret); |
302 | | - send. |
303 | | - |
304 | | -setWebhook(webhok); |
305 | | - |
| 94 | +send.setSecret(secret); |
| 95 | +send.setWebhook(webhook); |
306 | 96 | FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message); |
307 | 97 | ``` |
308 | 98 |
|
309 | | -```java |
310 | | - String json = "{\"config\":{\"enable_forward\":true,\"wide_screen_mode\":true}," + |
311 | | - "\"elements\":[{\"extra\":{\"alt\":{\"content\":\"图片\",\"tag\":\"plain_text\"},\"compact_width\":false,\"img_key\":\"img_1cad0e51-26f6-492a-8280-a47057b09a0g\",\"mode\":\"crop_center\",\"preview\":true,\"tag\":\"img\"},\"fields\":null,\"tag\":\"div\",\"text\":{\"content\":\"英国短毛猫,体形圆胖,四肢短粗发达,毛短而密,头大脸圆,对人友善。 \\n其历史可追溯至古罗马时期的家猫,由于拥有悠久的育种历史,称得上是猫家族中的典范。\",\"tag\":\"lark_md\"}},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"**中文学名:**\\n英国短毛猫\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"**拉丁学名:**\\nFelinae\",\"tag\":\"lark_md\"}},{\"is_short\":false,\"text\":{\"content\":\"\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"**体形:**\\n圆胖\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"**被毛:**\\n短而浓密、俗称地毯毛\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"extra\":{\"alt\":{\"content\":\"图片\",\"tag\":\"plain_text\"},\"compact_width\":false,\"img_key\":\"img_70558e3a-2eef-4e8f-9a07-a701c165431g\",\"mode\":\"crop_center\",\"preview\":true,\"tag\":\"img\"},\"fields\":null,\"tag\":\"div\",\"text\":{\"content\":\"**1 形态特征**\\n\\n \uD83D\uDD35 外形:身体厚实,胸部饱满宽阔,腿部粗壮,爪子浑圆,尾巴的根部粗壮,尾尖钝圆。\\n\\n\uD83D\uDD35 毛色:共有十五种品种被承认,其中最著名的是蓝色系的英国短毛猫。 \",\"tag\":\"lark_md\"}},{\"elements\":[{\"alt\":{\"content\":\"图片\",\"tag\":\"plain_text\"},\"compact_width\":false,\"img_key\":\"img_7ea74629-9191-4176-998c-2e603c9c5e8g\",\"mode\":\"crop_center\",\"preview\":true,\"tag\":\"img\"},{\"content\":\"以上资料来自百度百科\",\"tag\":\"plain_text\"}],\"tag\":\"note\"}],\"header\":{\"template\":\"indigo\",\"title\":{\"content\":\"\uD83D\uDC08 英国短毛猫\",\"tag\":\"plain_text\"}}}"; |
312 | | -InteractiveMessage message = InteractiveMessage.build().cardJsonStr(json); |
313 | | -String webhok = System.getenv("webhok"); |
314 | | -String secret = System.getenv("secret"); |
315 | | -FeishuRobotClient send = new FeishuRobotClient(); |
316 | | - send. |
317 | | - |
318 | | -setSecret(secret); |
319 | | - send. |
| 99 | +## 发送卡片消息 |
320 | 100 |
|
321 | | -setWebhook(webhok); |
| 101 | +```java |
| 102 | + CardHeader cardHeader = CardHeader.of( |
| 103 | + CardTitle |
| 104 | + .builder() |
| 105 | + .setTitle(Title.of("今日旅游推荐")) |
| 106 | + .build() |
| 107 | +); |
| 108 | +CardBody cardBody = CardBody |
| 109 | + .of() |
| 110 | + .add(Text.builder().setText(TextEl.builder() |
| 111 | + .setContent(ContentI18n.of(TextTag.LARK_MD, "**西湖**,位于浙江省杭州市西湖区龙井路1号,杭州市区西部,景区总面积49平方千米,汇水面积为21" + |
| 112 | + ".22平方千米,湖面面积为6.38平方千米。")) |
| 113 | + .build()).build()) |
| 114 | + .add(Button.builder() |
| 115 | + .setText("更多景点介绍 :玫瑰:") |
| 116 | + .setType(ButtonType.DEFAULT) |
| 117 | + .build()); |
| 118 | + |
| 119 | + |
| 120 | +CardV2Message cardV2Message = CardV2Message |
| 121 | + .builder() |
| 122 | + .setHeader(cardHeader) |
| 123 | + .setBody(cardBody) |
| 124 | + .build(); |
322 | 125 |
|
323 | | -FeishuRobotResponse feiShuRobotResponse = send.sendMessage(message); |
| 126 | +String webhok = ""; |
| 127 | +String secret = ""; |
| 128 | +FeishuRobotClient send = new FeishuRobotClient(); |
| 129 | +send.setSecret(secret); |
| 130 | +send.setWebhook(webhok); |
| 131 | +FeishuRobotResponse feiShuRobotResponse = send.sendMessage(cardV2Message); |
324 | 132 | ``` |
325 | 133 |
|
| 134 | +<!-- @formatter:on --> |
| 135 | + |
326 | 136 | # Http,JSON Library 选择 |
327 | 137 |
|
328 | 138 | ## JSON |
|
0 commit comments