mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-17 13:49:26 +08:00
发送客服消息接口转移到客服专用service中,使用时需要加入getKefuService()
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfMsgList;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList;
|
||||
|
||||
/**
|
||||
* 客服接口 ,
|
||||
* 命名采用kefu拼音的原因是:
|
||||
@@ -17,6 +23,14 @@ import java.util.Date;
|
||||
*/
|
||||
public interface WxMpKefuService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 发送客服消息
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547&token=&lang=zh_CN">发送客服消息</a>
|
||||
* </pre>
|
||||
*/
|
||||
boolean customMessageSend(WxMpCustomMessage message) throws WxErrorException;
|
||||
|
||||
//*******************客服管理接口***********************//
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@ package me.chanjar.weixin.mp.api;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpIndustry;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassNews;
|
||||
@@ -82,14 +81,6 @@ public interface WxMpService {
|
||||
*/
|
||||
WxJsapiSignature createJsapiSignature(String url) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 发送客服消息
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
|
||||
* </pre>
|
||||
*/
|
||||
void customMessageSend(WxMpCustomMessage message) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 上传群发用的图文消息,上传后才能群发图文消息
|
||||
|
||||
@@ -3,15 +3,18 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpKefuService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList;
|
||||
@@ -27,6 +30,8 @@ import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList;
|
||||
*
|
||||
*/
|
||||
public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
protected final Logger log = LoggerFactory
|
||||
.getLogger(WxMpKefuServiceImpl.class);
|
||||
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/customservice";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
@@ -34,19 +39,31 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean customMessageSend(WxMpCustomMessage message)
|
||||
throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
|
||||
String responseContent = this.wxMpService.post(url, message.toJson());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, message.toJson(),
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKfList kfList() throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist";
|
||||
String responseContent = this.wxMpService
|
||||
.execute(new SimpleGetRequestExecutor(), url, null);
|
||||
String url = API_URL_PREFIX + "/getkflist";
|
||||
String responseContent = this.wxMpService.get(url, null);
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
|
||||
responseContent);
|
||||
return WxMpKfList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKfOnlineList kfOnlineList() throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist";
|
||||
String responseContent = this.wxMpService
|
||||
.execute(new SimpleGetRequestExecutor(), url, null);
|
||||
String url = API_URL_PREFIX + "/getonlinekflist";
|
||||
String responseContent = this.wxMpService.get(url, null);
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
|
||||
responseContent);
|
||||
return WxMpKfOnlineList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@@ -54,8 +71,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
public boolean kfAccountAdd(WxMpKfAccountRequest request)
|
||||
throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfaccount/add";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url,
|
||||
request.toJson());
|
||||
String responseContent = this.wxMpService.post(url, request.toJson());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -63,16 +81,18 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
public boolean kfAccountUpdate(WxMpKfAccountRequest request)
|
||||
throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfaccount/update";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url,
|
||||
request.toJson());
|
||||
String responseContent = this.wxMpService.post(url, request.toJson());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfaccount/inviteworker";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url,
|
||||
request.toJson());
|
||||
String responseContent = this.wxMpService.post(url, request.toJson());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -80,14 +100,20 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile)
|
||||
throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfaccount/uploadheadimg?kf_account=" + kfAccount;
|
||||
this.wxMpService.execute(new MediaUploadRequestExecutor(), url, imgFile);
|
||||
WxMediaUploadResult responseContent = this.wxMpService
|
||||
.execute(new MediaUploadRequestExecutor(), url, imgFile);
|
||||
this.log.debug("\nurl:{}\nparams:{}&file:{}\nresponse:{}", url, kfAccount,
|
||||
imgFile.getAbsolutePath(),
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean kfAccountDel(String kfAccount) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfaccount/del?kf_account=" + kfAccount;
|
||||
this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null);
|
||||
String responseContent = this.wxMpService.get(url, null);
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -96,8 +122,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
throws WxErrorException {
|
||||
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid);
|
||||
String url = API_URL_PREFIX + "/kfsession/create";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url,
|
||||
request.toJson());
|
||||
String responseContent = this.wxMpService.post(url, request.toJson());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -106,8 +133,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
throws WxErrorException {
|
||||
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid);
|
||||
String url = API_URL_PREFIX + "/kfsession/close";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url,
|
||||
request.toJson());
|
||||
String responseContent = this.wxMpService.post(url, request.toJson());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, request.toJson(),
|
||||
responseContent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -115,8 +143,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
public WxMpKfSessionGetResult kfSessionGet(String openid)
|
||||
throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfsession/getsession?openid=" + openid;
|
||||
String responseContent = this.wxMpService
|
||||
.execute(new SimpleGetRequestExecutor(), url, null);
|
||||
String responseContent = this.wxMpService.get(url, null);
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
|
||||
responseContent);
|
||||
return WxMpKfSessionGetResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@@ -124,8 +153,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
public WxMpKfSessionList kfSessionList(String kfAccount)
|
||||
throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfsession/getsessionlist?kf_account=" + kfAccount;
|
||||
String responseContent = this.wxMpService
|
||||
.execute(new SimpleGetRequestExecutor(), url, null);
|
||||
String responseContent = this.wxMpService.get(url, null);
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
|
||||
responseContent);
|
||||
return WxMpKfSessionList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@@ -133,8 +163,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
public WxMpKfSessionWaitCaseList kfSessionGetWaitCase()
|
||||
throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/kfsession/getwaitcase";
|
||||
String responseContent = this.wxMpService
|
||||
.execute(new SimpleGetRequestExecutor(), url, null);
|
||||
String responseContent = this.wxMpService.get(url, null);
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, null,
|
||||
responseContent);
|
||||
return WxMpKfSessionWaitCaseList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@@ -156,7 +187,9 @@ public class WxMpKefuServiceImpl implements WxMpKefuService {
|
||||
param.addProperty("msgid", msgId); //msgid 消息id顺序从小到大,从1开始
|
||||
param.addProperty("number", number); //number 每次获取条数,最多10000条
|
||||
|
||||
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, param.toString());
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}", url, param.toString(),
|
||||
responseContent);
|
||||
return WxMpKfMsgList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ import me.chanjar.weixin.mp.api.WxMpQrcodeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserTagService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpIndustry;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassNews;
|
||||
@@ -203,12 +202,6 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
return jsapiSignature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customMessageSend(WxMpCustomMessage message) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
|
||||
execute(new SimplePostRequestExecutor(), url, message.toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews";
|
||||
|
||||
Reference in New Issue
Block a user