🎨 #3395【企业微信】增加"模板卡片事件推送"事件的相关属性

This commit is contained in:
小梁 2024-10-30 13:04:01 +08:00 committed by GitHub
parent 3e25e409b0
commit bf7356e808
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 78 additions and 0 deletions

View File

@ -187,6 +187,17 @@ public class WxCpXmlMessage implements Serializable {
@XStreamConverter(value = XStreamCDataConverter.class)
private String taskId;
@XStreamAlias("CardType")
@XStreamConverter(value = XStreamCDataConverter.class)
private String cardType;
@XStreamAlias("ResponseCode")
@XStreamConverter(value = XStreamCDataConverter.class)
private String responseCode;
@XStreamAlias("SelectedItems")
private List<SelectedItem> selectedItems;
/**
* 微信客服
* 调用拉取消息接口时需要传此token用于校验请求的合法性
@ -750,4 +761,21 @@ public class WxCpXmlMessage implements Serializable {
}
/**
* The type selected Items.
*/
@Data
@XStreamAlias("SelectedItem")
public static class SelectedItem implements Serializable {
private static final long serialVersionUID = 6319921121637597406L;
@XStreamAlias("QuestionKey")
@XStreamConverter(value = XStreamCDataConverter.class)
private String questionKey;
@XStreamAlias(value = "OptionIds")
private List<String> optionIds;
}
}

View File

@ -48,6 +48,11 @@ public class WxCpConsts {
*/
public static final String CHANGE_CONTACT = "change_contact";
/**
* 企业微信模板卡片事件推送
*/
public static final String TEMPLATE_CARD_EVENT = "template_card_event";
/**
* 点击菜单拉取消息的事件推送.
*/

View File

@ -93,6 +93,11 @@ public class XStreamTransformer {
xstream.processAnnotations(WxCpXmlMessage.SendPicsInfo.class);
xstream.processAnnotations(WxCpXmlMessage.SendPicsInfo.Item.class);
xstream.processAnnotations(WxCpXmlMessage.SendLocationInfo.class);
xstream.processAnnotations(WxCpXmlMessage.SelectedItem.class);
// 显式允许 String
xstream.allowTypes(new Class[]{String.class});
// 模板卡片事件推送独属
xstream.alias("OptionId",String.class);
return xstream;
}

View File

@ -302,6 +302,46 @@ public class WxCpXmlMessageTest {
System.out.println(XStreamTransformer.toXml(WxCpXmlMessage.class, wxCpXmlMessage));
}
/**
* Test template card event.
*/
public void testTemplateCardEvent() {
String xml = "<xml>\n" +
"<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
"<FromUserName><![CDATA[FromUser]]></FromUserName>\n" +
"<CreateTime>123456789</CreateTime>\n" +
"<MsgType><![CDATA[event]]></MsgType>\n" +
"<Event><![CDATA[template_card_event]]></Event>\n" +
"<EventKey><![CDATA[key111]]></EventKey>\n" +
"<TaskId><![CDATA[taskid111]]></TaskId>\n" +
"<CardType><![CDATA[text_notice]]></CardType>\n" +
"<ResponseCode><![CDATA[ResponseCode]]></ResponseCode>\n" +
"<AgentID>1</AgentID>\n" +
"<SelectedItems>\n" +
" <SelectedItem>\n" +
" <QuestionKey><![CDATA[QuestionKey1]]></QuestionKey>\n" +
" <OptionIds>\n" +
" <OptionId><![CDATA[OptionId1]]></OptionId>\n" +
" <OptionId><![CDATA[OptionId2]]></OptionId>\n" +
" </OptionIds>\n" +
" </SelectedItem>\n" +
" <SelectedItem>\n" +
" <QuestionKey><![CDATA[QuestionKey2]]></QuestionKey>\n" +
" <OptionIds>\n" +
" <OptionId><![CDATA[OptionId3]]></OptionId>\n" +
" <OptionId><![CDATA[OptionId4]]></OptionId>\n" +
" </OptionIds>\n" +
" </SelectedItem>\n" +
"</SelectedItems>\n" +
"</xml>";
WxCpXmlMessage wxCpXmlMessage = WxCpXmlMessage.fromXml(xml);
assertThat(wxCpXmlMessage).isNotNull();
assertThat(wxCpXmlMessage.getSelectedItems()).isNotEmpty();
assertThat(wxCpXmlMessage.getSelectedItems().get(0).getQuestionKey()).isNotEmpty();
assertThat(wxCpXmlMessage.getSelectedItems().get(0).getOptionIds().get(0)).isNotEmpty();
}
/**
* Test open approval change.
*/