mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 18:46:10 +08:00 
			
		
		
		
	🎨 #3212【企业微信】增加微信客服回调事件支持
This commit is contained in:
		| @ -301,6 +301,11 @@ public class WxConsts { | ||||
|     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"; | ||||
|     /** | ||||
|      * 扫码推事件的事件推送 | ||||
|      */ | ||||
|  | ||||
| @ -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由系统生成时可更改一次). | ||||
|    */ | ||||
|  | ||||
| @ -3,10 +3,14 @@ package me.chanjar.weixin.cp.api.impl; | ||||
| 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 @@ import java.io.InputStream; | ||||
|  | ||||
| /** | ||||
|  * 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 | ||||
|  */ | ||||
| @ -97,4 +103,34 @@ public class WxCpKfServiceImplTest { | ||||
|     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()); | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 0katekate0
					0katekate0