|
|
@@ -0,0 +1,125 @@
|
|
|
+package com.usoftchina.qywx.sdk.dto;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 群聊机器人消息推送
|
|
|
+ * @author wuyx
|
|
|
+ */
|
|
|
+public class SendRobMessageReq {
|
|
|
+ /**
|
|
|
+ * 消息类型
|
|
|
+ * text:文本类型
|
|
|
+ * {
|
|
|
+ * "msgtype": "text",
|
|
|
+ * "text": {
|
|
|
+ * "content": "广州今日天气:29度,大部分多云,降雨概率:60%",
|
|
|
+ * "mentioned_list":["wangqing","@all"],
|
|
|
+ * "mentioned_mobile_list":["13800001111","@all"]
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * markdown:markdown类型
|
|
|
+ * {
|
|
|
+ * "msgtype": "markdown",
|
|
|
+ * "markdown": {
|
|
|
+ * "content": "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n
|
|
|
+ * >类型:<font color=\"comment\">用户反馈</font>
|
|
|
+ * >普通用户反馈:<font color=\"comment\">117例</font>
|
|
|
+ * >VIP用户反馈:<font color=\"comment\">15例</font>"
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * image:图片类型
|
|
|
+ * file:文件类型
|
|
|
+ * template_card:模版卡片类型
|
|
|
+ * ...
|
|
|
+ */
|
|
|
+ private String msgtype;
|
|
|
+ /**
|
|
|
+ * 消息内容
|
|
|
+ */
|
|
|
+ private AbstractMessageBody body;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文本消息
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public SendRobMessageReq text(String content, String[] mentionedList, String[] mentionedMobileList) {
|
|
|
+ this.msgtype = "text";
|
|
|
+ this.body = new Text(content,mentionedList,mentionedMobileList);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * markdown消息
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public SendRobMessageReq markdown(String content) {
|
|
|
+ this.msgtype = "markdown";
|
|
|
+ this.body = new Markdown(content);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> build() {
|
|
|
+ Map<String, Object> message = new HashMap<>(3);
|
|
|
+ if (null != msgtype) {
|
|
|
+ message.put("msgtype", msgtype);
|
|
|
+ message.put(msgtype, body.build());
|
|
|
+ }
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ interface AbstractMessageBody {
|
|
|
+ Map<String, Object> build();
|
|
|
+ }
|
|
|
+
|
|
|
+ class Text implements AbstractMessageBody {
|
|
|
+ //文本内容,最长不超过2048个字节,必须是utf8编码
|
|
|
+ private final String content;
|
|
|
+ //userid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list
|
|
|
+ private final String[] mentionedList;
|
|
|
+ //手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人
|
|
|
+ private final String[] mentionedMobileList;
|
|
|
+
|
|
|
+ public Text(String content,String[] mentionedList,String[] mentionedMobileList) {
|
|
|
+ this.content = content;
|
|
|
+ this.mentionedList = mentionedList;
|
|
|
+ this.mentionedMobileList = mentionedMobileList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> build() {
|
|
|
+ Map<String, Object> data = new HashMap<>(1);
|
|
|
+ data.put("content", content);
|
|
|
+ if(mentionedList!=null && mentionedList.length>0){
|
|
|
+ data.put("mentioned_list", mentionedList);
|
|
|
+ }
|
|
|
+ if(mentionedMobileList!=null && mentionedMobileList.length>0){
|
|
|
+ data.put("mentioned_mobile_list", mentionedMobileList);
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class Markdown implements AbstractMessageBody {
|
|
|
+ //markdown内容,最长不超过4096个字节,必须是utf8编码
|
|
|
+ private final String content;
|
|
|
+
|
|
|
+ public Markdown(String content) {
|
|
|
+ this.content = content;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> build() {
|
|
|
+ Map<String, Object> data = new HashMap<>(1);
|
|
|
+ data.put("content", content);
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|