Просмотр исходного кода

:new: 【公众号】增加返回响应信息完整内容的客服消息发送接口的方法

Binary Wang 4 лет назад
Родитель
Сommit
37ae6807e6

+ 1 - 1
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java

@@ -267,7 +267,7 @@ public interface WxCpTpService {
    * 获取WxMpConfigStorage 对象.
    *
    * @return WxMpConfigStorage wx cp tp config storage
-   * @Deprecated storage应该在service内部使用,提供这个接口,容易破坏这个封装
+   * @deprecated storage应该在service内部使用,提供这个接口,容易破坏这个封装
    */
   @Deprecated
   WxCpTpConfigStorage getWxCpTpConfigStorage();

+ 45 - 3
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java

@@ -25,14 +25,29 @@ public interface WxMpKefuService {
   /**
    * <pre>
    * 发送客服消息
-   * 详情请见: <a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547&token=&lang=zh_CN">发送客服消息</a>
+   * 详情请见: <a href="https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html">发送客服消息</a>
    * 接口url格式:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @param message the message
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean sendKefuMessage(WxMpKefuMessage message) throws WxErrorException;
 
+  /**
+   * <pre>
+   * 发送客服消息
+   * 详情请见: <a href="https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html">发送客服消息</a>
+   * 接口url格式:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
+   * </pre>
+   *
+   * @param message the message
+   * @return the response
+   * @throws WxErrorException 异常
+   */
+  String sendKefuMessageWithResponse(WxMpKefuMessage message) throws WxErrorException;
+
   //*******************客服管理接口***********************//
 
   /**
@@ -42,6 +57,7 @@ public interface WxMpKefuService {
    * 接口url格式:https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @return the wx mp kf list
    * @throws WxErrorException 异常
    */
   WxMpKfList kfList() throws WxErrorException;
@@ -53,6 +69,7 @@ public interface WxMpKefuService {
    * 接口url格式:https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @return the wx mp kf online list
    * @throws WxErrorException 异常
    */
   WxMpKfOnlineList kfOnlineList() throws WxErrorException;
@@ -64,6 +81,8 @@ public interface WxMpKefuService {
    * 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @param request the request
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean kfAccountAdd(WxMpKfAccountRequest request) throws WxErrorException;
@@ -74,6 +93,10 @@ public interface WxMpKefuService {
    * 详情请见:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1458044813&token=&lang=zh_CN">客服管理</a>
    * 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/update?access_token=ACCESS_TOKEN
    * </pre>
+   *
+   * @param request the request
+   * @return the boolean
+   * @throws WxErrorException the wx error exception
    */
   boolean kfAccountUpdate(WxMpKfAccountRequest request) throws WxErrorException;
 
@@ -84,6 +107,8 @@ public interface WxMpKefuService {
    * 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/inviteworker?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @param request the request
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErrorException;
@@ -95,6 +120,9 @@ public interface WxMpKefuService {
    * 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
    * </pre>
    *
+   * @param kfAccount the kf account
+   * @param imgFile   the img file
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException;
@@ -106,6 +134,8 @@ public interface WxMpKefuService {
    * 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/del?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
    * </pre>
    *
+   * @param kfAccount the kf account
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean kfAccountDel(String kfAccount) throws WxErrorException;
@@ -120,6 +150,9 @@ public interface WxMpKefuService {
    * 接口url格式: https://api.weixin.qq.com/customservice/kfsession/create?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @param openid    the openid
+   * @param kfAccount the kf account
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean kfSessionCreate(String openid, String kfAccount) throws WxErrorException;
@@ -132,6 +165,9 @@ public interface WxMpKefuService {
    * 接口url格式: https://api.weixin.qq.com/customservice/kfsession/close?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @param openid    the openid
+   * @param kfAccount the kf account
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean kfSessionClose(String openid, String kfAccount) throws WxErrorException;
@@ -144,6 +180,8 @@ public interface WxMpKefuService {
    * 接口url格式: https://api.weixin.qq.com/customservice/kfsession/getsession?access_token=ACCESS_TOKEN&openid=OPENID
    * </pre>
    *
+   * @param openid the openid
+   * @return the wx mp kf session get result
    * @throws WxErrorException 异常
    */
   WxMpKfSessionGetResult kfSessionGet(String openid) throws WxErrorException;
@@ -156,6 +194,8 @@ public interface WxMpKefuService {
    * 接口url格式: https://api.weixin.qq.com/customservice/kfsession/getsessionlist?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
    * </pre>
    *
+   * @param kfAccount the kf account
+   * @return the wx mp kf session list
    * @throws WxErrorException 异常
    */
   WxMpKfSessionList kfSessionList(String kfAccount) throws WxErrorException;
@@ -168,6 +208,7 @@ public interface WxMpKefuService {
    * 接口url格式: https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token=ACCESS_TOKEN
    * </pre>
    *
+   * @return the wx mp kf session wait case list
    * @throws WxErrorException 异常
    */
   WxMpKfSessionWaitCaseList kfSessionGetWaitCase() throws WxErrorException;
@@ -186,7 +227,7 @@ public interface WxMpKefuService {
    * @param endTime   结束时间
    * @param msgId     消息id顺序从小到大,从1开始
    * @param number    每次获取条数,最多10000条
-   * @return 聊天记录对象
+   * @return 聊天记录对象 wx mp kf msg list
    * @throws WxErrorException 异常
    */
   WxMpKfMsgList kfMsgList(Date startTime, Date endTime, Long msgId, Integer number) throws WxErrorException;
@@ -201,7 +242,7 @@ public interface WxMpKefuService {
    *
    * @param startTime 起始时间
    * @param endTime   结束时间
-   * @return 聊天记录对象
+   * @return 聊天记录对象 wx mp kf msg list
    * @throws WxErrorException 异常
    */
   WxMpKfMsgList kfMsgList(Date startTime, Date endTime) throws WxErrorException;
@@ -222,6 +263,7 @@ public interface WxMpKefuService {
    *
    * @param openid  用户id
    * @param command "Typing":对用户下发“正在输入"状态 "CancelTyping":取消对用户的”正在输入"状态
+   * @return the boolean
    * @throws WxErrorException 异常
    */
   boolean sendKfTypingState(String openid, String command) throws WxErrorException;

+ 6 - 3
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImpl.java

@@ -4,7 +4,6 @@ import com.google.gson.JsonObject;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
-import me.chanjar.weixin.common.error.WxError;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
 import me.chanjar.weixin.mp.api.WxMpKefuService;
@@ -29,8 +28,12 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
 
   @Override
   public boolean sendKefuMessage(WxMpKefuMessage message) throws WxErrorException {
-    String responseContent = this.wxMpService.post(MESSAGE_CUSTOM_SEND, message.toJson());
-    return responseContent != null;
+    return this.sendKefuMessageWithResponse(message) != null;
+  }
+
+  @Override
+  public String sendKefuMessageWithResponse(WxMpKefuMessage message) throws WxErrorException {
+    return this.wxMpService.post(MESSAGE_CUSTOM_SEND, message.toJson());
   }
 
   @Override