forked from binarywang/WxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🆕 binarywang#2142 【企业微信】被动回复消息内容新增任务卡片格式
- Loading branch information
1 parent
933e058
commit 1905871
Showing
8 changed files
with
130 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...a-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamReplaceNameConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package me.chanjar.weixin.common.util.xml; | ||
|
||
public class XStreamReplaceNameConverter extends XStreamCDataConverter { | ||
@Override | ||
public String toString(Object obj) { | ||
return "<ReplaceName>" + super.toString(obj) + "</ReplaceName>"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...in-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TaskCardBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TaskCardBuilder, WxCpXmlOutTaskCardMessage> { | ||
|
||
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ava-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutTaskCardMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "<xml>" | ||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | ||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | ||
+ "<CreateTime>1122</CreateTime>" | ||
+ "<MsgType><![CDATA[update_taskcard]]></MsgType>" | ||
+ "<TaskCard><ReplaceName><![CDATA[已驳回]]></ReplaceName></TaskCard>" | ||
+ "</xml>"; | ||
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 = "<xml>" | ||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | ||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | ||
+ "<CreateTime>1122</CreateTime>" | ||
+ "<MsgType><![CDATA[update_taskcard]]></MsgType>" | ||
+ "<TaskCard><ReplaceName><![CDATA[已驳回]]></ReplaceName></TaskCard>" | ||
+ "</xml>"; | ||
System.out.println(m.toXml()); | ||
Assert.assertEquals( | ||
m | ||
.toXml() | ||
.replaceAll("\\s", "") | ||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | ||
expected | ||
.replaceAll("\\s", "") | ||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | ||
); | ||
} | ||
|
||
} |