diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java
index 1e953d080b..cfc7fc0f37 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java
@@ -44,6 +44,7 @@ public static class XmlMsgType {
public static final String DEVICE_STATUS = "device_status";
public static final String HARDWARE = "hardware";
public static final String TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
+ public static final String UPDATE_TASKCARD = "update_taskcard";
}
/**
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java
index cf0fbb5ae9..6997eb490d 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java
@@ -28,6 +28,8 @@ public HierarchicalStreamWriter createWriter(Writer out) {
private static final String SUFFIX_CDATA = "]]>";
private static final String PREFIX_MEDIA_ID = "";
private static final String SUFFIX_MEDIA_ID = "";
+ private static final String PREFIX_REPLACE_NAME = "";
+ private static final String SUFFIX_REPLACE_NAME = "";
@Override
protected void writeText(QuickWriter writer, String text) {
@@ -35,6 +37,8 @@ protected void writeText(QuickWriter writer, String text) {
writer.write(text);
} else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) {
writer.write(text);
+ } else if (text.startsWith(PREFIX_REPLACE_NAME) && text.endsWith(SUFFIX_REPLACE_NAME)){
+ writer.write(text);
} else {
super.writeText(writer, text);
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamReplaceNameConverter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamReplaceNameConverter.java
new file mode 100644
index 0000000000..a136934383
--- /dev/null
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamReplaceNameConverter.java
@@ -0,0 +1,8 @@
+package me.chanjar.weixin.common.util.xml;
+
+public class XStreamReplaceNameConverter extends XStreamCDataConverter {
+ @Override
+ public String toString(Object obj) {
+ return "" + super.toString(obj) + "";
+ }
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutMessage.java
index 96991a5403..ff036b4c0e 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutMessage.java
@@ -6,11 +6,7 @@
import com.thoughtworks.xstream.annotations.XStreamConverter;
import lombok.Data;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
-import me.chanjar.weixin.cp.bean.outxmlbuilder.ImageBuilder;
-import me.chanjar.weixin.cp.bean.outxmlbuilder.NewsBuilder;
-import me.chanjar.weixin.cp.bean.outxmlbuilder.TextBuilder;
-import me.chanjar.weixin.cp.bean.outxmlbuilder.VideoBuilder;
-import me.chanjar.weixin.cp.bean.outxmlbuilder.VoiceBuilder;
+import me.chanjar.weixin.cp.bean.outxmlbuilder.*;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
@@ -76,6 +72,12 @@ public static NewsBuilder NEWS() {
return new NewsBuilder();
}
+ /**
+ * 获得任务卡片消息builder.
+ */
+ public static TaskCardBuilder TASK_CARD() {
+ return new TaskCardBuilder();
+ }
protected String toXml() {
return XStreamTransformer.toXml((Class) this.getClass(), this);
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessage.java
new file mode 100644
index 0000000000..63816f7e4c
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessage.java
@@ -0,0 +1,24 @@
+package me.chanjar.weixin.cp.bean.message;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamConverter;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.util.xml.XStreamReplaceNameConverter;
+
+@XStreamAlias("xml")
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class WxCpXmlOutTaskCardMessage extends WxCpXmlOutMessage {
+ private static final long serialVersionUID = 7028014900972827324L;
+
+ @XStreamAlias("TaskCard")
+ @XStreamConverter(value = XStreamReplaceNameConverter.class)
+ private String replaceName;
+
+ public WxCpXmlOutTaskCardMessage() {
+ this.msgType = WxConsts.XmlMsgType.UPDATE_TASKCARD;
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TaskCardBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TaskCardBuilder.java
new file mode 100644
index 0000000000..e71c5bd71d
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TaskCardBuilder.java
@@ -0,0 +1,27 @@
+package me.chanjar.weixin.cp.bean.outxmlbuilder;
+
+import me.chanjar.weixin.cp.bean.message.WxCpXmlOutTaskCardMessage;
+
+/**
+ * 任务卡片消息builder
+ *
+ * @author tao zhang
+ */
+public final class TaskCardBuilder extends BaseBuilder {
+
+ private String replaceName;
+
+ public TaskCardBuilder replaceName(String replaceName) {
+ this.replaceName = replaceName;
+ return this;
+ }
+
+ @Override
+ public WxCpXmlOutTaskCardMessage build() {
+ WxCpXmlOutTaskCardMessage m = new WxCpXmlOutTaskCardMessage();
+ setCommon(m);
+ m.setReplaceName(this.replaceName);
+ return m;
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java
index ea90231112..aa907b7288 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XStreamTransformer.java
@@ -6,15 +6,8 @@
import com.thoughtworks.xstream.XStream;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
-import me.chanjar.weixin.cp.bean.message.WxCpTpXmlMessage;
+import me.chanjar.weixin.cp.bean.message.*;
import me.chanjar.weixin.cp.bean.WxCpTpXmlPackage;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlOutImageMessage;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlOutNewsMessage;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlOutTextMessage;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlOutVideoMessage;
-import me.chanjar.weixin.cp.bean.message.WxCpXmlOutVoiceMessage;
public class XStreamTransformer {
@@ -60,6 +53,7 @@ private static Map configXStreamInstance() {
map.put(WxCpXmlOutImageMessage.class, configWxCpXmlOutImageMessage());
map.put(WxCpXmlOutVideoMessage.class, configWxCpXmlOutVideoMessage());
map.put(WxCpXmlOutVoiceMessage.class, configWxCpXmlOutVoiceMessage());
+ map.put(WxCpXmlOutTaskCardMessage.class, configWxCpXmlOutTaskCardMessage());
map.put(WxCpTpXmlPackage.class, configWxCpTpXmlPackage());
map.put(WxCpTpXmlMessage.class, configWxCpTpXmlMessage());
return map;
@@ -118,6 +112,14 @@ private static XStream configWxCpXmlOutVoiceMessage() {
return xstream;
}
+ private static XStream configWxCpXmlOutTaskCardMessage() {
+ XStream xstream = XStreamInitializer.getInstance();
+
+ xstream.processAnnotations(WxCpXmlOutMessage.class);
+ xstream.processAnnotations(WxCpXmlOutTaskCardMessage.class);
+ return xstream;
+ }
+
private static XStream configWxCpTpXmlPackage() {
XStream xstream = XStreamInitializer.getInstance();
xstream.processAnnotations(WxCpTpXmlPackage.class);
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessageTest.java
new file mode 100644
index 0000000000..bc867b72d1
--- /dev/null
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessageTest.java
@@ -0,0 +1,49 @@
+package me.chanjar.weixin.cp.bean.message;
+
+import me.chanjar.weixin.cp.bean.message.WxCpXmlOutTaskCardMessage;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+@Test
+public class WxCpXmlOutTaskCardMessageTest {
+
+ public void test() {
+ WxCpXmlOutTaskCardMessage m = new WxCpXmlOutTaskCardMessage();
+ m.setReplaceName("已驳回");
+ m.setCreateTime(1122L);
+ m.setFromUserName("from");
+ m.setToUserName("to");
+
+ String expected = ""
+ + ""
+ + ""
+ + "1122"
+ + ""
+ + ""
+ + "";
+ System.out.println(m.toXml());
+ Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
+ }
+
+ public void testBuild() {
+ WxCpXmlOutTaskCardMessage m = WxCpXmlOutMessage.TASK_CARD().replaceName("已驳回").fromUser("from").toUser("to").build();
+ String expected = ""
+ + ""
+ + ""
+ + "1122"
+ + ""
+ + ""
+ + "";
+ System.out.println(m.toXml());
+ Assert.assertEquals(
+ m
+ .toXml()
+ .replaceAll("\\s", "")
+ .replaceAll(".*?", ""),
+ expected
+ .replaceAll("\\s", "")
+ .replaceAll(".*?", "")
+ );
+ }
+
+}