mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 #3218【企业微信】增加获客助手事件回调通知
This commit is contained in:
parent
596bc33960
commit
44ec8b2669
@ -302,10 +302,6 @@ public class WxConsts {
|
||||
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";
|
||||
/**
|
||||
* 扫码推事件的事件推送
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -159,6 +159,60 @@ public class WxCpConsts {
|
||||
*/
|
||||
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";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.api.impl;
|
||||
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.Attachment;
|
||||
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 class WxCpExternalContactServiceImplTest {
|
||||
this.wxCpService.getExternalContactService()
|
||||
.cancelGroupMsgSend("msgGCAAAXtWyujaWJHDDGi0mACAAAA");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获客助手事件通知
|
||||
* https://developer.work.weixin.qq.com/document/path/97299
|
||||
*
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
@Test
|
||||
public void testEvent() throws WxErrorException {
|
||||
|
||||
/**
|
||||
* 获客额度即将耗尽事件
|
||||
*/
|
||||
String xml1 = "<xml>\n" +
|
||||
"\t<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
|
||||
"\t<FromUserName><![CDATA[sys]]></FromUserName> \n" +
|
||||
"\t<CreateTime>1403610513</CreateTime>\n" +
|
||||
"\t<MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
"\t<Event><![CDATA[customer_acquisition]]></Event>\n" +
|
||||
"\t<ChangeType><![CDATA[balance_low]]></ChangeType>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxCpXmlMessage msg1 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml1);
|
||||
msg1.setAllFieldsMap(XmlUtils.xml2Map(xml1));
|
||||
System.out.println("获客额度即将耗尽事件:" + WxCpGsonBuilder.create().toJson(msg1));
|
||||
|
||||
/**
|
||||
* 使用量已经耗尽事件
|
||||
*/
|
||||
String xml2 = "<xml>\n" +
|
||||
"\t<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
|
||||
"\t<FromUserName><![CDATA[sys]]></FromUserName> \n" +
|
||||
"\t<CreateTime>1403610513</CreateTime>\n" +
|
||||
"\t<MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
"\t<Event><![CDATA[customer_acquisition]]></Event>\n" +
|
||||
"\t<ChangeType><![CDATA[balance_exhausted]]></ChangeType>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxCpXmlMessage msg2 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml2);
|
||||
msg2.setAllFieldsMap(XmlUtils.xml2Map(xml2));
|
||||
System.out.println("使用量已经耗尽事件:" + WxCpGsonBuilder.create().toJson(msg2));
|
||||
|
||||
/**
|
||||
* 获客链接不可用事件
|
||||
*/
|
||||
String xml3 = "<xml>\n" +
|
||||
"\t<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
|
||||
"\t<FromUserName><![CDATA[sys]]></FromUserName> \n" +
|
||||
"\t<CreateTime>1403610513</CreateTime>\n" +
|
||||
"\t<MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
"\t<Event><![CDATA[customer_acquisition]]></Event>\n" +
|
||||
"\t<ChangeType><![CDATA[link_unavailable]]></ChangeType>\n" +
|
||||
"\t<LinkId><![CDATA[cawcdea7783d7330b4]]></LinkId>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxCpXmlMessage msg3 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml3);
|
||||
msg3.setAllFieldsMap(XmlUtils.xml2Map(xml3));
|
||||
System.out.println("获客链接不可用事件:" + WxCpGsonBuilder.create().toJson(msg3));
|
||||
|
||||
/**
|
||||
* 微信客户发起会话事件
|
||||
*/
|
||||
String xml4 = "<xml>\n" +
|
||||
"<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
|
||||
"<FromUserName><![CDATA[sys]]></FromUserName> \n" +
|
||||
"<CreateTime>1403610513</CreateTime>\n" +
|
||||
"<MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
"<Event><![CDATA[customer_acquisition]]></Event>\n" +
|
||||
"<ChangeType><![CDATA[customer_start_chat]]></ChangeType>\n" +
|
||||
"<UserID><![CDATA[zhangsan]]></UserID>\n" +
|
||||
"<ExternalUserID><![CDATA[woAJ2GCAAAXtWyujaWJHDDGi0mAAAA]]></ExternalUserID>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxCpXmlMessage msg4 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml4);
|
||||
msg4.setAllFieldsMap(XmlUtils.xml2Map(xml4));
|
||||
System.out.println("微信客户发起会话事件:" + WxCpGsonBuilder.create().toJson(msg4));
|
||||
|
||||
/**
|
||||
* 删除获客链接事件
|
||||
*/
|
||||
String xml5 = "<xml>\n" +
|
||||
"\t<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
|
||||
"\t<FromUserName><![CDATA[sys]]></FromUserName> \n" +
|
||||
"\t<CreateTime>1403610513</CreateTime>\n" +
|
||||
"\t<MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
"\t<Event><![CDATA[customer_acquisition]]></Event>\n" +
|
||||
"\t<ChangeType><![CDATA[delete_link]]></ChangeType>\n" +
|
||||
"\t<LinkId><![CDATA[cawcdea7783d7330b4]]></LinkId>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxCpXmlMessage msg5 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml5);
|
||||
msg5.setAllFieldsMap(XmlUtils.xml2Map(xml5));
|
||||
System.out.println("删除获客链接事件:" + WxCpGsonBuilder.create().toJson(msg5));
|
||||
|
||||
/**
|
||||
* 通过获客链接申请好友事件
|
||||
*/
|
||||
String xml6 = "<xml>\n" +
|
||||
"\t<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
|
||||
"\t<FromUserName><![CDATA[sys]]></FromUserName> \n" +
|
||||
"\t<CreateTime>1689171577</CreateTime>\n" +
|
||||
"\t<MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
"\t<Event><![CDATA[customer_acquisition]]></Event>\n" +
|
||||
"\t<ChangeType><![CDATA[friend_request]]></ChangeType>\n" +
|
||||
"\t<LinkId><![CDATA[cawcdea7783d7330b4]]></LinkId>\n" +
|
||||
"\t<State><![CDATA[STATE]]></State>\n" +
|
||||
"</xml>";
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -106,12 +106,28 @@ public class WxCpKfServiceImplTest {
|
||||
/**
|
||||
* 测试回调事件
|
||||
* 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 = "<xml>\n" +
|
||||
" <ToUserName><![CDATA[toUser]]></ToUserName>\n" +
|
||||
" <FromUserName><![CDATA[sys]]></FromUserName> \n" +
|
||||
" <CreateTime>1348831860</CreateTime>\n" +
|
||||
" <MsgType><![CDATA[event]]></MsgType>\n" +
|
||||
" <Event><![CDATA[kf_account_auth_change]]></Event>\n" +
|
||||
" <AuthAddOpenKfId><![CDATA[wkxxxx1]]></AuthAddOpenKfId>\n" +
|
||||
" <AuthDelOpenKfId><![CDATA[wkxxxx2]]></AuthDelOpenKfId>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxCpXmlMessage xmlMsg1 = XStreamTransformer.fromXml(WxCpXmlMessage.class, xml1);
|
||||
xmlMsg1.setAllFieldsMap(XmlUtils.xml2Map(xml1));
|
||||
System.out.println(WxCpGsonBuilder.create().toJson(xmlMsg1));
|
||||
|
||||
String xml = "<xml>\n" +
|
||||
" <ToUserName><![CDATA[ww12345678910]]></ToUserName>\n" +
|
||||
" <CreateTime>1348831860</CreateTime>\n" +
|
||||
@ -124,13 +140,15 @@ public class WxCpKfServiceImplTest {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user