🎨 #3212【企业微信】增加微信客服回调事件支持

This commit is contained in:
0katekate0 2024-01-12 19:53:37 +08:00 committed by GitHub
parent d0324c6771
commit d957896ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 1 deletions

View File

@ -301,6 +301,11 @@ public class WxConsts {
public static final String CLICK = "CLICK"; public static final String CLICK = "CLICK";
public static final String VIEW = "VIEW"; public static final String VIEW = "VIEW";
public static final String MASS_SEND_JOB_FINISH = "MASSSENDJOBFINISH"; public static final String MASS_SEND_JOB_FINISH = "MASSSENDJOBFINISH";
/**
* 微信客服消息事件推送
*/
public static final String KF_MSG_OR_EVENT = "kf_msg_or_event";
/** /**
* 扫码推事件的事件推送 * 扫码推事件的事件推送
*/ */

View File

@ -187,6 +187,21 @@ public class WxCpXmlMessage implements Serializable {
@XStreamConverter(value = XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String taskId; 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 * 请参考常量 me.chanjar.weixin.cp.constant.WxCpConsts.ContactChangeType
@ -222,6 +237,7 @@ public class WxCpXmlMessage implements Serializable {
@XStreamAlias("WelcomeCode") @XStreamAlias("WelcomeCode")
@XStreamConverter(value = XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String welcomeCode; private String welcomeCode;
/** /**
* 新的UserID变更时推送userid由系统生成时可更改一次. * 新的UserID变更时推送userid由系统生成时可更改一次.
*/ */

View File

@ -3,10 +3,14 @@ package me.chanjar.weixin.cp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; 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.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp; import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.kf.*; 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.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -14,7 +18,9 @@ import java.io.InputStream;
/** /**
* WxCpKfServiceImpl-测试类 * WxCpKfServiceImpl-测试类
* 需要用到专门的 secret https://kf.weixin.qq.com/api/doc/path/93304#secret * 需要用到专门的secret
* <a href="https://developer.work.weixin.qq.com/document/path/94638">官方文档1</a>
* <a href="https://kf.weixin.qq.com/api/doc/path/93304#secret">官方文档2</a>
* *
* @author Fu created on 2022/1/19 20:12 * @author Fu created on 2022/1/19 20:12
*/ */
@ -97,4 +103,34 @@ public class WxCpKfServiceImplTest {
System.out.println(resp); 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 = "<xml>\n" +
" <ToUserName><![CDATA[ww12345678910]]></ToUserName>\n" +
" <CreateTime>1348831860</CreateTime>\n" +
" <MsgType><![CDATA[event]]></MsgType>\n" +
" <Event><![CDATA[kf_msg_or_event]]></Event>\n" +
" <Token><![CDATA[ENCApHxnGDNAVNY4AaSJKj4Tb5mwsEMzxhFmHVGcra996NR]]></Token>\n" +
" <OpenKfId><![CDATA[wkxxxxxxx]]></OpenKfId>\n" +
"</xml>";
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());
}
} }