Skip to content

Commit b47cd3a

Browse files
committed
fix binarywang#56 分组群发消息没有 is_to_all 字段
1 parent c6b5ce6 commit b47cd3a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassGroupMessage.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
public class WxMpMassGroupMessage {
1111

12-
private long groupId;
12+
private Long groupId;
1313
private String msgtype;
1414
private String content;
1515
private String mediaId;
@@ -58,11 +58,15 @@ public String toJson() {
5858
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
5959
}
6060

61-
public long getGroupId() {
61+
public Long getGroupId() {
6262
return groupId;
6363
}
6464

65-
public void setGroupId(long groupId) {
65+
/**
66+
* 如果不设置则就意味着发给所有用户
67+
* @param groupId
68+
*/
69+
public void setGroupId(Long groupId) {
6670
this.groupId = groupId;
6771
}
6872

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class WxMpGsonBuilder {
1414
INSTANCE.disableHtmlEscaping();
1515
INSTANCE.registerTypeAdapter(WxMpCustomMessage.class, new WxMpCustomMessageGsonAdapter());
1616
INSTANCE.registerTypeAdapter(WxMpMassNews.class, new WxMpMassNewsGsonAdapter());
17-
INSTANCE.registerTypeAdapter(WxMpMassGroupMessage.class, new WxMpMassMessageGsonAdapter());
17+
INSTANCE.registerTypeAdapter(WxMpMassGroupMessage.class, new WxMpMassGroupMessageGsonAdapter());
1818
INSTANCE.registerTypeAdapter(WxMpMassOpenIdsMessage.class, new WxMpMassOpenIdsMessageGsonAdapter());
1919
INSTANCE.registerTypeAdapter(WxMpGroup.class, new WxMpGroupGsonAdapter());
2020
INSTANCE.registerTypeAdapter(WxMpUser.class, new WxUserGsonAdapter());

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassMessageGsonAdapter.java renamed to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassGroupMessageGsonAdapter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
* @author qianjia
2323
*
2424
*/
25-
public class WxMpMassMessageGsonAdapter implements JsonSerializer<WxMpMassGroupMessage> {
25+
public class WxMpMassGroupMessageGsonAdapter implements JsonSerializer<WxMpMassGroupMessage> {
2626

2727
public JsonElement serialize(WxMpMassGroupMessage message, Type typeOfSrc, JsonSerializationContext context) {
2828
JsonObject messageJson = new JsonObject();
2929

3030
JsonObject filter = new JsonObject();
31-
filter.addProperty("group_id", message.getGroupId());
31+
if(null == message.getGroupId()) {
32+
filter.addProperty("is_to_all", true);
33+
} else {
34+
filter.addProperty("is_to_all", false);
35+
filter.addProperty("group_id", message.getGroupId());
36+
}
3237
messageJson.add("filter", filter);
3338

3439
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) {

0 commit comments

Comments
 (0)