|
8 | 8 | */ |
9 | 9 | package me.chanjar.weixin.mp.util.json; |
10 | 10 |
|
11 | | -import java.lang.reflect.Type; |
12 | | - |
13 | 11 | import com.google.gson.JsonElement; |
14 | 12 | import com.google.gson.JsonObject; |
15 | 13 | import com.google.gson.JsonSerializationContext; |
16 | 14 | import com.google.gson.JsonSerializer; |
17 | | - |
18 | 15 | import me.chanjar.weixin.common.api.WxConsts; |
19 | 16 | import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; |
20 | 17 |
|
| 18 | +import java.lang.reflect.Type; |
| 19 | + |
21 | 20 | public class WxMpMassTagMessageGsonAdapter implements JsonSerializer<WxMpMassTagMessage> { |
22 | 21 |
|
23 | 22 | @Override |
24 | 23 | public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSerializationContext context) { |
25 | 24 | JsonObject messageJson = new JsonObject(); |
26 | | - |
| 25 | + |
27 | 26 | JsonObject filter = new JsonObject(); |
28 | | - if(null == message.getTagId()) { |
| 27 | + if (null == message.getTagId()) { |
29 | 28 | filter.addProperty("is_to_all", true); |
30 | 29 | } else { |
31 | 30 | filter.addProperty("is_to_all", false); |
32 | 31 | filter.addProperty("tag_id", message.getTagId()); |
33 | 32 | } |
34 | 33 | messageJson.add("filter", filter); |
35 | | - |
36 | | - if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { |
| 34 | + |
| 35 | + if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { |
37 | 36 | JsonObject sub = new JsonObject(); |
38 | 37 | sub.addProperty("media_id", message.getMediaId()); |
39 | 38 | messageJson.add(WxConsts.MASS_MSG_NEWS, sub); |
40 | 39 | } |
41 | | - if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) { |
| 40 | + if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) { |
42 | 41 | JsonObject sub = new JsonObject(); |
43 | 42 | sub.addProperty("content", message.getContent()); |
44 | 43 | messageJson.add(WxConsts.MASS_MSG_TEXT, sub); |
45 | 44 | } |
46 | | - if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) { |
| 45 | + if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) { |
47 | 46 | JsonObject sub = new JsonObject(); |
48 | 47 | sub.addProperty("media_id", message.getMediaId()); |
49 | 48 | messageJson.add(WxConsts.MASS_MSG_VOICE, sub); |
50 | 49 | } |
51 | | - if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) { |
| 50 | + if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) { |
52 | 51 | JsonObject sub = new JsonObject(); |
53 | 52 | sub.addProperty("media_id", message.getMediaId()); |
54 | 53 | messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); |
55 | 54 | } |
56 | | - if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) { |
| 55 | + if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) { |
57 | 56 | JsonObject sub = new JsonObject(); |
58 | 57 | sub.addProperty("media_id", message.getMediaId()); |
59 | 58 | messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); |
60 | 59 | } |
61 | | - messageJson.addProperty("msgtype", message.getMsgtype()); |
| 60 | + messageJson.addProperty("msgtype", message.getMsgType()); |
| 61 | + messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); |
62 | 62 | return messageJson; |
63 | 63 | } |
64 | 64 |
|
|
0 commit comments