@@ -1,28 +1,29 @@ | |||
package me.chanjar.weixin.mp.bean; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import java.io.Serializable; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
/** | |||
* openid列表群发的消息 | |||
* | |||
* | |||
* @author chanjarster | |||
*/ | |||
public class WxMpMassOpenIdsMessage implements Serializable { | |||
private static final long serialVersionUID = -8022910911104788999L; | |||
private List<String> toUsers = new ArrayList<>(); | |||
private String msgType; | |||
private String content; | |||
private String mediaId; | |||
private boolean sendIgnoreReprint = false; | |||
public WxMpMassOpenIdsMessage() { | |||
super(); | |||
} | |||
public String getMsgType() { | |||
return this.msgType; | |||
} | |||
@@ -86,4 +87,15 @@ public class WxMpMassOpenIdsMessage implements Serializable { | |||
this.toUsers = toUsers; | |||
} | |||
public boolean isSendIgnoreReprint() { | |||
return sendIgnoreReprint; | |||
} | |||
/** | |||
* | |||
* @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。 | |||
*/ | |||
public void setSendIgnoreReprint(boolean sendIgnoreReprint) { | |||
this.sendIgnoreReprint = sendIgnoreReprint; | |||
} | |||
} |
@@ -1,28 +1,29 @@ | |||
package me.chanjar.weixin.mp.bean; | |||
import java.io.Serializable; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import java.io.Serializable; | |||
/** | |||
* 按标签群发的消息 | |||
* | |||
* | |||
* @author chanjarster | |||
*/ | |||
public class WxMpMassTagMessage implements Serializable { | |||
private static final long serialVersionUID = -6625914040986749286L; | |||
private Long tagId; | |||
private String msgtype; | |||
private String msgType; | |||
private String content; | |||
private String mediaId; | |||
private boolean sendIgnoreReprint = false; | |||
public WxMpMassTagMessage() { | |||
super(); | |||
} | |||
public String getMsgtype() { | |||
return this.msgtype; | |||
public String getMsgType() { | |||
return this.msgType; | |||
} | |||
/** | |||
@@ -35,10 +36,11 @@ public class WxMpMassTagMessage implements Serializable { | |||
* {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VOICE} | |||
* 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误 | |||
* </pre> | |||
* @param msgtype | |||
* | |||
* @param msgType 消息类型 | |||
*/ | |||
public void setMsgtype(String msgtype) { | |||
this.msgtype = msgtype; | |||
public void setMsgType(String msgType) { | |||
this.msgType = msgType; | |||
} | |||
public String getContent() { | |||
@@ -67,10 +69,23 @@ public class WxMpMassTagMessage implements Serializable { | |||
/** | |||
* 如果不设置则就意味着发给所有用户 | |||
* @param tagId | |||
* | |||
* @param tagId 标签id | |||
*/ | |||
public void setTagId(Long tagId) { | |||
this.tagId = tagId; | |||
} | |||
public boolean isSendIgnoreReprint() { | |||
return sendIgnoreReprint; | |||
} | |||
/** | |||
* | |||
* @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。 | |||
*/ | |||
public void setSendIgnoreReprint(boolean sendIgnoreReprint) { | |||
this.sendIgnoreReprint = sendIgnoreReprint; | |||
} | |||
} |
@@ -1,5 +1,6 @@ | |||
package me.chanjar.weixin.mp.bean.result; | |||
import me.chanjar.weixin.common.util.ToStringUtils; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import java.io.Serializable; | |||
@@ -7,19 +8,15 @@ import java.io.Serializable; | |||
/** | |||
* <pre> | |||
* 群发消息一发送就返回的结果 | |||
* | |||
* | |||
* 真正的群发消息是否发送成功要看 | |||
* 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 | |||
* | |||
* | |||
* </pre> | |||
* @author chanjarster | |||
* | |||
*/ | |||
public class WxMpMassSendResult implements Serializable { | |||
/** | |||
* | |||
*/ | |||
private static final long serialVersionUID = -4816336807575562818L; | |||
private String errorCode; | |||
private String errorMsg; | |||
@@ -64,7 +61,7 @@ public class WxMpMassSendResult implements Serializable { | |||
@Override | |||
public String toString() { | |||
return "WxMassSendResult [errcode=" + this.errorCode + ", errmsg=" + this.errorMsg + ", msg_id=" + this.msgId + "]"; | |||
return ToStringUtils.toSimpleString(this); | |||
} | |||
} |
@@ -19,13 +19,13 @@ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMpMas | |||
@Override | |||
public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject messageJson = new JsonObject(); | |||
JsonArray toUsers = new JsonArray(); | |||
for (String openId : message.getToUsers()) { | |||
toUsers.add(new JsonPrimitive(openId)); | |||
} | |||
messageJson.add("touser", toUsers); | |||
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
@@ -52,6 +52,7 @@ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMpMas | |||
messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); | |||
} | |||
messageJson.addProperty("msgtype", message.getMsgType()); | |||
messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); | |||
return messageJson; | |||
} | |||
@@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMpMassSendResultAdapter implements JsonDeserializer<WxMpMassSendResult> { | |||
@@ -40,5 +38,5 @@ public class WxMpMassSendResultAdapter implements JsonDeserializer<WxMpMassSendR | |||
} | |||
return sendResult; | |||
} | |||
} |
@@ -8,57 +8,57 @@ | |||
*/ | |||
package me.chanjar.weixin.mp.util.json; | |||
import java.lang.reflect.Type; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonSerializationContext; | |||
import com.google.gson.JsonSerializer; | |||
import me.chanjar.weixin.common.api.WxConsts; | |||
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||
import java.lang.reflect.Type; | |||
public class WxMpMassTagMessageGsonAdapter implements JsonSerializer<WxMpMassTagMessage> { | |||
@Override | |||
public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
JsonObject messageJson = new JsonObject(); | |||
JsonObject filter = new JsonObject(); | |||
if(null == message.getTagId()) { | |||
if (null == message.getTagId()) { | |||
filter.addProperty("is_to_all", true); | |||
} else { | |||
filter.addProperty("is_to_all", false); | |||
filter.addProperty("tag_id", message.getTagId()); | |||
} | |||
messageJson.add("filter", filter); | |||
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { | |||
if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_NEWS, sub); | |||
} | |||
if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) { | |||
if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("content", message.getContent()); | |||
messageJson.add(WxConsts.MASS_MSG_TEXT, sub); | |||
} | |||
if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) { | |||
if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_VOICE, sub); | |||
} | |||
if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) { | |||
if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); | |||
} | |||
if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) { | |||
if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) { | |||
JsonObject sub = new JsonObject(); | |||
sub.addProperty("media_id", message.getMediaId()); | |||
messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); | |||
} | |||
messageJson.addProperty("msgtype", message.getMsgtype()); | |||
messageJson.addProperty("msgtype", message.getMsgType()); | |||
messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); | |||
return messageJson; | |||
} | |||