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 a82ed86ef2..14f8424f20 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 @@ -302,10 +302,6 @@ public static class EventType { 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 6f18a8572b..11a1aa62a8 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 @@ -202,6 +202,27 @@ public class WxCpXmlMessage implements Serializable { @XStreamConverter(value = XStreamCDataConverter.class) private String openKfId; + /** + * 新增授权的客服账号列表,多个AuthAddOpenKfId节点表示多个新增账号 + */ + @XStreamAlias("AuthAddOpenKfId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String authAddOpenKfId; + + /** + * 取消授权的客服账号列表,多个AuthDelOpenKfId节点表示多个取消账号 + */ + @XStreamAlias("AuthDelOpenKfId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String authDelOpenKfId; + + /** + * 失效的获客链接ID + */ + @XStreamAlias("LinkId") + @XStreamConverter(value = XStreamCDataConverter.class) + private String linkId; + /** * 通讯录变更事件. * 请参考常量 me.chanjar.weixin.cp.constant.WxCpConsts.ContactChangeType diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java index 99191fe1aa..8101745e96 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java @@ -159,6 +159,60 @@ public static class EventType { */ public static final String LIVING_STATUS_CHANGE = "living_status_change"; + /** + * 微信客服消息事件 + */ + public static final String KF_MSG_OR_EVENT = "kf_msg_or_event"; + + /** + * 客服账号授权变更事件 + */ + public static final String KF_ACCOUNT_AUTH_CHANGE = "kf_account_auth_change"; + + /** + * 获客助手事件通知 + */ + public static final String CUSTOMER_ACQUISITION = "customer_acquisition"; + + } + + /** + * 获客助手事件通知CHANGE_TYPE + * https://developer.work.weixin.qq.com/document/path/97299 + */ + @UtilityClass + public static class CustomerAcquisitionChangeType { + + /** + * 获客额度即将耗尽事件 + */ + public static final String BALANCE_LOW = "balance_low"; + + /** + * 使用量已经耗尽事件 + */ + public static final String BALANCE_EXHAUSTED = "balance_exhausted"; + + /** + * 获客链接不可用事件 + */ + public static final String LINK_UNAVAILABLE = "link_unavailable"; + + /** + * 微信客户发起会话事件 + */ + public static final String CUSTOMER_START_CHAT = "customer_start_chat"; + + /** + * 删除获客链接事件 + */ + public static final String DELETE_LINK = "delete_link"; + + /** + * 通过获客链接申请好友事件 + */ + public static final String friend_request = "friend_request"; + } /** diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java index a33e458e0d..9f7dd8c531 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.Lists; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; +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; @@ -13,6 +14,9 @@ import me.chanjar.weixin.cp.bean.external.msg.AttachmentBuilder; import me.chanjar.weixin.cp.bean.external.msg.Image; import me.chanjar.weixin.cp.bean.external.msg.Video; +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.apache.commons.lang3.time.DateFormatUtils; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -641,4 +645,124 @@ public void testCancelGroupMsgSend() throws WxErrorException { this.wxCpService.getExternalContactService() .cancelGroupMsgSend("msgGCAAAXtWyujaWJHDDGi0mACAAAA"); } + + /** + * 获客助手事件通知 + * https://developer.work.weixin.qq.com/document/path/97299 + * + * @throws WxErrorException + */ + @Test + public void testEvent() throws WxErrorException { + + /** + * 获客额度即将耗尽事件 + */ + String xml1 = "\n" + + "\t\n" + + "\t \n" + + "\t1403610513\n" + + "\t\n" + + "\t\n" + + "\t\n" + + ""; + + WxCpXmlMessage msg1 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml1); + msg1.setAllFieldsMap(XmlUtils.xml2Map(xml1)); + System.out.println("获客额度即将耗尽事件:" + WxCpGsonBuilder.create().toJson(msg1)); + + /** + * 使用量已经耗尽事件 + */ + String xml2 = "\n" + + "\t\n" + + "\t \n" + + "\t1403610513\n" + + "\t\n" + + "\t\n" + + "\t\n" + + ""; + + WxCpXmlMessage msg2 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml2); + msg2.setAllFieldsMap(XmlUtils.xml2Map(xml2)); + System.out.println("使用量已经耗尽事件:" + WxCpGsonBuilder.create().toJson(msg2)); + + /** + * 获客链接不可用事件 + */ + String xml3 = "\n" + + "\t\n" + + "\t \n" + + "\t1403610513\n" + + "\t\n" + + "\t\n" + + "\t\n" + + "\t\n" + + ""; + + WxCpXmlMessage msg3 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml3); + msg3.setAllFieldsMap(XmlUtils.xml2Map(xml3)); + System.out.println("获客链接不可用事件:" + WxCpGsonBuilder.create().toJson(msg3)); + + /** + * 微信客户发起会话事件 + */ + String xml4 = "\n" + + "\n" + + " \n" + + "1403610513\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + ""; + + WxCpXmlMessage msg4 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml4); + msg4.setAllFieldsMap(XmlUtils.xml2Map(xml4)); + System.out.println("微信客户发起会话事件:" + WxCpGsonBuilder.create().toJson(msg4)); + + /** + * 删除获客链接事件 + */ + String xml5 = "\n" + + "\t\n" + + "\t \n" + + "\t1403610513\n" + + "\t\n" + + "\t\n" + + "\t\n" + + "\t\n" + + ""; + + WxCpXmlMessage msg5 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml5); + msg5.setAllFieldsMap(XmlUtils.xml2Map(xml5)); + System.out.println("删除获客链接事件:" + WxCpGsonBuilder.create().toJson(msg5)); + + /** + * 通过获客链接申请好友事件 + */ + String xml6 = "\n" + + "\t\n" + + "\t \n" + + "\t1689171577\n" + + "\t\n" + + "\t\n" + + "\t\n" + + "\t\n" + + "\t\n" + + ""; + + WxCpXmlMessage msg6 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml6); + msg6.setAllFieldsMap(XmlUtils.xml2Map(xml6)); + System.out.println("通过获客链接申请好友事件:" + WxCpGsonBuilder.create().toJson(msg6)); + + + /** + * 获客助手事件通知ChangeType + * @see me.chanjar.weixin.cp.constant.WxCpConsts.CustomerAcquisitionChangeType.CUSTOMER_START_CHAT + */ + + } + } 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 74b6266f04..1ab6fdb068 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 @@ -106,12 +106,28 @@ public void testAccountDel() throws Exception { /** * 测试回调事件 * https://developer.work.weixin.qq.com/document/path/94670 + * https://developer.work.weixin.qq.com/document/path/97712 * * @throws Exception */ @Test(priority = 6) public void testEvent() throws Exception { + // 客服账号授权变更事件 + String xml1 = "\n" + + " \n" + + " \n" + + " 1348831860\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + WxCpXmlMessage xmlMsg1 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml1); + xmlMsg1.setAllFieldsMap(XmlUtils.xml2Map(xml1)); + System.out.println(WxCpGsonBuilder.create().toJson(xmlMsg1)); + String xml = "\n" + " \n" + " 1348831860\n" + @@ -124,13 +140,15 @@ public void testEvent() throws Exception { WxCpXmlMessage xmlMsg = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml); xmlMsg.setAllFieldsMap(XmlUtils.xml2Map(xml)); System.out.println(WxCpGsonBuilder.create().toJson(xmlMsg)); + System.out.println("token:" + xmlMsg.getToken()); + System.out.println("openKfId:" + xmlMsg.getOpenKfId()); /** * 微信客服事件推送 - * @see WxConsts.EventType.KF_MSG_OR_EVENT + * @see me.chanjar.weixin.cp.constant.WxCpConsts.EventType.KF_MSG_OR_EVENT + * @see me.chanjar.weixin.cp.constant.WxCpConsts.EventType.KF_ACCOUNT_AUTH_CHANGE */ - System.out.println("token:" + xmlMsg.getToken()); - System.out.println("openKfId:" + xmlMsg.getOpenKfId()); + System.out.println("微信客服事件:" + me.chanjar.weixin.cp.constant.WxCpConsts.EventType.KF_MSG_OR_EVENT); } }