| @@ -9,7 +9,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
| */ | */ | ||||
| public class WxMpMassGroupMessage { | public class WxMpMassGroupMessage { | ||||
| private long groupId; | |||||
| private Long groupId; | |||||
| private String msgtype; | private String msgtype; | ||||
| private String content; | private String content; | ||||
| private String mediaId; | private String mediaId; | ||||
| @@ -58,11 +58,15 @@ public class WxMpMassGroupMessage { | |||||
| return WxMpGsonBuilder.INSTANCE.create().toJson(this); | return WxMpGsonBuilder.INSTANCE.create().toJson(this); | ||||
| } | } | ||||
| public long getGroupId() { | |||||
| public Long getGroupId() { | |||||
| return groupId; | return groupId; | ||||
| } | } | ||||
| public void setGroupId(long groupId) { | |||||
| /** | |||||
| * 如果不设置则就意味着发给所有用户 | |||||
| * @param groupId | |||||
| */ | |||||
| public void setGroupId(Long groupId) { | |||||
| this.groupId = groupId; | this.groupId = groupId; | ||||
| } | } | ||||
| @@ -14,7 +14,7 @@ public class WxMpGsonBuilder { | |||||
| INSTANCE.disableHtmlEscaping(); | INSTANCE.disableHtmlEscaping(); | ||||
| INSTANCE.registerTypeAdapter(WxMpCustomMessage.class, new WxMpCustomMessageGsonAdapter()); | INSTANCE.registerTypeAdapter(WxMpCustomMessage.class, new WxMpCustomMessageGsonAdapter()); | ||||
| INSTANCE.registerTypeAdapter(WxMpMassNews.class, new WxMpMassNewsGsonAdapter()); | INSTANCE.registerTypeAdapter(WxMpMassNews.class, new WxMpMassNewsGsonAdapter()); | ||||
| INSTANCE.registerTypeAdapter(WxMpMassGroupMessage.class, new WxMpMassMessageGsonAdapter()); | |||||
| INSTANCE.registerTypeAdapter(WxMpMassGroupMessage.class, new WxMpMassGroupMessageGsonAdapter()); | |||||
| INSTANCE.registerTypeAdapter(WxMpMassOpenIdsMessage.class, new WxMpMassOpenIdsMessageGsonAdapter()); | INSTANCE.registerTypeAdapter(WxMpMassOpenIdsMessage.class, new WxMpMassOpenIdsMessageGsonAdapter()); | ||||
| INSTANCE.registerTypeAdapter(WxMpGroup.class, new WxMpGroupGsonAdapter()); | INSTANCE.registerTypeAdapter(WxMpGroup.class, new WxMpGroupGsonAdapter()); | ||||
| INSTANCE.registerTypeAdapter(WxMpUser.class, new WxUserGsonAdapter()); | INSTANCE.registerTypeAdapter(WxMpUser.class, new WxUserGsonAdapter()); | ||||
| @@ -22,13 +22,18 @@ import java.lang.reflect.Type; | |||||
| * @author qianjia | * @author qianjia | ||||
| * | * | ||||
| */ | */ | ||||
| public class WxMpMassMessageGsonAdapter implements JsonSerializer<WxMpMassGroupMessage> { | |||||
| public class WxMpMassGroupMessageGsonAdapter implements JsonSerializer<WxMpMassGroupMessage> { | |||||
| public JsonElement serialize(WxMpMassGroupMessage message, Type typeOfSrc, JsonSerializationContext context) { | public JsonElement serialize(WxMpMassGroupMessage message, Type typeOfSrc, JsonSerializationContext context) { | ||||
| JsonObject messageJson = new JsonObject(); | JsonObject messageJson = new JsonObject(); | ||||
| JsonObject filter = new JsonObject(); | JsonObject filter = new JsonObject(); | ||||
| filter.addProperty("group_id", message.getGroupId()); | |||||
| if(null == message.getGroupId()) { | |||||
| filter.addProperty("is_to_all", true); | |||||
| } else { | |||||
| filter.addProperty("is_to_all", false); | |||||
| filter.addProperty("group_id", message.getGroupId()); | |||||
| } | |||||
| messageJson.add("filter", filter); | messageJson.add("filter", filter); | ||||
| if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { | if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { | ||||