Skip to content

Commit f221ea3

Browse files
committed
公众平台增加群发接口对原创校验逻辑的支持
1 parent 515ef7c commit f221ea3

File tree

6 files changed

+65
-42
lines changed

6 files changed

+65
-42
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
package me.chanjar.weixin.mp.bean;
22

3+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
4+
35
import java.io.Serializable;
46
import java.util.ArrayList;
57
import java.util.List;
68

7-
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
8-
99
/**
1010
* openid列表群发的消息
11-
*
11+
*
1212
* @author chanjarster
1313
*/
1414
public class WxMpMassOpenIdsMessage implements Serializable {
1515
private static final long serialVersionUID = -8022910911104788999L;
16-
16+
1717
private List<String> toUsers = new ArrayList<>();
1818
private String msgType;
1919
private String content;
2020
private String mediaId;
21+
private boolean sendIgnoreReprint = false;
2122

2223
public WxMpMassOpenIdsMessage() {
2324
super();
2425
}
25-
26+
2627
public String getMsgType() {
2728
return this.msgType;
2829
}
@@ -86,4 +87,15 @@ public void setToUsers(List<String> toUsers) {
8687
this.toUsers = toUsers;
8788
}
8889

90+
public boolean isSendIgnoreReprint() {
91+
return sendIgnoreReprint;
92+
}
93+
94+
/**
95+
*
96+
* @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。
97+
*/
98+
public void setSendIgnoreReprint(boolean sendIgnoreReprint) {
99+
this.sendIgnoreReprint = sendIgnoreReprint;
100+
}
89101
}

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
package me.chanjar.weixin.mp.bean;
22

3-
import java.io.Serializable;
4-
53
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
64

5+
import java.io.Serializable;
6+
77
/**
88
* 按标签群发的消息
9-
*
9+
*
1010
* @author chanjarster
1111
*/
1212
public class WxMpMassTagMessage implements Serializable {
13-
13+
1414
private static final long serialVersionUID = -6625914040986749286L;
1515
private Long tagId;
16-
private String msgtype;
16+
private String msgType;
1717
private String content;
1818
private String mediaId;
19+
private boolean sendIgnoreReprint = false;
1920

2021
public WxMpMassTagMessage() {
2122
super();
2223
}
23-
24-
public String getMsgtype() {
25-
return this.msgtype;
24+
25+
public String getMsgType() {
26+
return this.msgType;
2627
}
2728

2829
/**
@@ -35,10 +36,11 @@ public String getMsgtype() {
3536
* {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VOICE}
3637
* 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
3738
* </pre>
38-
* @param msgtype
39+
*
40+
* @param msgType 消息类型
3941
*/
40-
public void setMsgtype(String msgtype) {
41-
this.msgtype = msgtype;
42+
public void setMsgType(String msgType) {
43+
this.msgType = msgType;
4244
}
4345

4446
public String getContent() {
@@ -67,10 +69,23 @@ public Long getTagId() {
6769

6870
/**
6971
* 如果不设置则就意味着发给所有用户
70-
* @param tagId
72+
*
73+
* @param tagId 标签id
7174
*/
7275
public void setTagId(Long tagId) {
7376
this.tagId = tagId;
7477
}
7578

79+
public boolean isSendIgnoreReprint() {
80+
return sendIgnoreReprint;
81+
}
82+
83+
/**
84+
*
85+
* @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。
86+
*/
87+
public void setSendIgnoreReprint(boolean sendIgnoreReprint) {
88+
this.sendIgnoreReprint = sendIgnoreReprint;
89+
}
90+
7691
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package me.chanjar.weixin.mp.bean.result;
22

3+
import me.chanjar.weixin.common.util.ToStringUtils;
34
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
45

56
import java.io.Serializable;
67

78
/**
89
* <pre>
910
* 群发消息一发送就返回的结果
10-
*
11+
*
1112
* 真正的群发消息是否发送成功要看
1213
* http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口#.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81.E7.BE.A4.E5.8F.91.E7.BB.93.E6.9E.9C
13-
*
14+
*
1415
* </pre>
1516
* @author chanjarster
1617
*
1718
*/
1819
public class WxMpMassSendResult implements Serializable {
19-
20-
/**
21-
*
22-
*/
2320
private static final long serialVersionUID = -4816336807575562818L;
2421
private String errorCode;
2522
private String errorMsg;
@@ -64,7 +61,7 @@ public static WxMpMassSendResult fromJson(String json) {
6461

6562
@Override
6663
public String toString() {
67-
return "WxMassSendResult [errcode=" + this.errorCode + ", errmsg=" + this.errorMsg + ", msg_id=" + this.msgId + "]";
64+
return ToStringUtils.toSimpleString(this);
6865
}
69-
66+
7067
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMpMas
1919
@Override
2020
public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, JsonSerializationContext context) {
2121
JsonObject messageJson = new JsonObject();
22-
22+
2323
JsonArray toUsers = new JsonArray();
2424
for (String openId : message.getToUsers()) {
2525
toUsers.add(new JsonPrimitive(openId));
2626
}
2727
messageJson.add("touser", toUsers);
28-
28+
2929
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) {
3030
JsonObject sub = new JsonObject();
3131
sub.addProperty("media_id", message.getMediaId());
@@ -52,6 +52,7 @@ public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, Jso
5252
messageJson.add(WxConsts.MASS_MSG_VIDEO, sub);
5353
}
5454
messageJson.addProperty("msgtype", message.getMsgType());
55+
messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1);
5556
return messageJson;
5657
}
5758

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import java.lang.reflect.Type;
1616

1717
/**
18-
*
1918
* @author Daniel Qian
20-
*
2119
*/
2220
public class WxMpMassSendResultAdapter implements JsonDeserializer<WxMpMassSendResult> {
2321

@@ -40,5 +38,5 @@ public WxMpMassSendResult deserialize(JsonElement json, Type typeOfT, JsonDeseri
4038
}
4139
return sendResult;
4240
}
43-
41+
4442
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,57 @@
88
*/
99
package me.chanjar.weixin.mp.util.json;
1010

11-
import java.lang.reflect.Type;
12-
1311
import com.google.gson.JsonElement;
1412
import com.google.gson.JsonObject;
1513
import com.google.gson.JsonSerializationContext;
1614
import com.google.gson.JsonSerializer;
17-
1815
import me.chanjar.weixin.common.api.WxConsts;
1916
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
2017

18+
import java.lang.reflect.Type;
19+
2120
public class WxMpMassTagMessageGsonAdapter implements JsonSerializer<WxMpMassTagMessage> {
2221

2322
@Override
2423
public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSerializationContext context) {
2524
JsonObject messageJson = new JsonObject();
26-
25+
2726
JsonObject filter = new JsonObject();
28-
if(null == message.getTagId()) {
27+
if (null == message.getTagId()) {
2928
filter.addProperty("is_to_all", true);
3029
} else {
3130
filter.addProperty("is_to_all", false);
3231
filter.addProperty("tag_id", message.getTagId());
3332
}
3433
messageJson.add("filter", filter);
35-
36-
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) {
34+
35+
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) {
3736
JsonObject sub = new JsonObject();
3837
sub.addProperty("media_id", message.getMediaId());
3938
messageJson.add(WxConsts.MASS_MSG_NEWS, sub);
4039
}
41-
if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) {
40+
if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) {
4241
JsonObject sub = new JsonObject();
4342
sub.addProperty("content", message.getContent());
4443
messageJson.add(WxConsts.MASS_MSG_TEXT, sub);
4544
}
46-
if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) {
45+
if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) {
4746
JsonObject sub = new JsonObject();
4847
sub.addProperty("media_id", message.getMediaId());
4948
messageJson.add(WxConsts.MASS_MSG_VOICE, sub);
5049
}
51-
if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) {
50+
if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) {
5251
JsonObject sub = new JsonObject();
5352
sub.addProperty("media_id", message.getMediaId());
5453
messageJson.add(WxConsts.MASS_MSG_IMAGE, sub);
5554
}
56-
if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) {
55+
if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) {
5756
JsonObject sub = new JsonObject();
5857
sub.addProperty("media_id", message.getMediaId());
5958
messageJson.add(WxConsts.MASS_MSG_VIDEO, sub);
6059
}
61-
messageJson.addProperty("msgtype", message.getMsgtype());
60+
messageJson.addProperty("msgtype", message.getMsgType());
61+
messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1);
6262
return messageJson;
6363
}
6464

0 commit comments

Comments
 (0)