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 3d2f62affe..a82ed86ef2 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
@@ -301,6 +301,11 @@ public static class EventType {
public static final String CLICK = "CLICK";
public static final String VIEW = "VIEW";
public static final String MASS_SEND_JOB_FINISH = "MASSSENDJOBFINISH";
+
+ /**
+ * 微信客服消息事件推送
+ */
+ public static final String KF_MSG_OR_EVENT = "kf_msg_or_event";
/**
* 扫码推事件的事件推送
*/
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java
index 51e395ab13..6f18a8572b 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java
@@ -187,6 +187,21 @@ public class WxCpXmlMessage implements Serializable {
@XStreamConverter(value = XStreamCDataConverter.class)
private String taskId;
+ /**
+ * 微信客服
+ * 调用拉取消息接口时,需要传此token,用于校验请求的合法性
+ */
+ @XStreamAlias("Token")
+ @XStreamConverter(value = XStreamCDataConverter.class)
+ private String token;
+
+ /**
+ * 有新消息的客服账号。可通过sync_msg接口指定open_kfid获取此客服账号的消息
+ */
+ @XStreamAlias("OpenKfId")
+ @XStreamConverter(value = XStreamCDataConverter.class)
+ private String openKfId;
+
/**
* 通讯录变更事件.
* 请参考常量 me.chanjar.weixin.cp.constant.WxCpConsts.ContactChangeType
@@ -222,6 +237,7 @@ public class WxCpXmlMessage implements Serializable {
@XStreamAlias("WelcomeCode")
@XStreamConverter(value = XStreamCDataConverter.class)
private String welcomeCode;
+
/**
* 新的UserID,变更时推送(userid由系统生成时可更改一次).
*/
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImplTest.java
index c918c297bb..74b6266f04 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImplTest.java
@@ -3,10 +3,14 @@
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
+import me.chanjar.weixin.common.util.XmlUtils;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.kf.*;
+import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -14,7 +18,9 @@
/**
* WxCpKfServiceImpl-测试类
- * 需要用到专门的 secret https://kf.weixin.qq.com/api/doc/path/93304#secret
+ * 需要用到专门的secret
+ * 官方文档1
+ * 官方文档2
*
* @author Fu created on 2022/1/19 20:12
*/
@@ -97,4 +103,34 @@ public void testAccountDel() throws Exception {
System.out.println(resp);
}
+ /**
+ * 测试回调事件
+ * https://developer.work.weixin.qq.com/document/path/94670
+ *
+ * @throws Exception
+ */
+ @Test(priority = 6)
+ public void testEvent() throws Exception {
+
+ String xml = "\n" +
+ " \n" +
+ " 1348831860\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "";
+
+ WxCpXmlMessage xmlMsg = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml);
+ xmlMsg.setAllFieldsMap(XmlUtils.xml2Map(xml));
+ System.out.println(WxCpGsonBuilder.create().toJson(xmlMsg));
+
+ /**
+ * 微信客服事件推送
+ * @see WxConsts.EventType.KF_MSG_OR_EVENT
+ */
+ System.out.println("token:" + xmlMsg.getToken());
+ System.out.println("openKfId:" + xmlMsg.getOpenKfId());
+ }
+
}