Skip to content

Commit 0c2768d

Browse files
committed
实现多客服会话控制的接口
1 parent 065156e commit 0c2768d

16 files changed

Lines changed: 592 additions & 91 deletions

File tree

‎weixin-java-demo-with-spring/src/main/java/com/github/binarywang/demo/spring/service/BaseWxService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
2323
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
2424
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
25-
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfOnlineList;
25+
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList;
2626

2727
/**
2828
*

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpKefuService.java‎

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import java.io.File;
44

55
import me.chanjar.weixin.common.exception.WxErrorException;
6-
import me.chanjar.weixin.mp.bean.customerservice.request.WxMpKfAccountRequest;
7-
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfList;
8-
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfOnlineList;
6+
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
7+
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList;
8+
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList;
9+
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult;
10+
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList;
11+
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList;
912

1013
/**
1114
* 客服接口 ,
@@ -15,59 +18,112 @@
1518
* @author Binary Wang
1619
*
1720
*/
18-
public interface WxMpKefuService {
21+
public interface WxMpKefuService {
22+
23+
//*******************客服管理接口***********************//
1924
/**
2025
* <pre>
2126
* 获取客服基本信息
2227
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/18/749901f4e123170fb8a4d447ae6040ba.html">客服管理</a>
23-
* https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=ACCESS_TOKEN
28+
* 接口url格式:https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=ACCESS_TOKEN
2429
* </pre>
2530
*/
2631
WxMpKfList kfList() throws WxErrorException;
27-
32+
2833
/**
2934
* <pre>
3035
* 获取在线客服接待信息
3136
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/18/749901f4e123170fb8a4d447ae6040ba.html">客服管理</a>
32-
* https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token=ACCESS_TOKEN
37+
* 接口url格式:https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token=ACCESS_TOKEN
3338
* </pre>
3439
*/
3540
WxMpKfOnlineList kfOnlineList() throws WxErrorException;
36-
41+
3742
/**
3843
* <pre>
3944
* 添加客服账号
4045
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/18/749901f4e123170fb8a4d447ae6040ba.html">客服管理</a>
41-
* https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN
46+
* 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN
4247
* </pre>
4348
*/
4449
boolean kfAccountAdd(WxMpKfAccountRequest request) throws WxErrorException;
45-
50+
4651
/**
4752
* <pre>
4853
* 设置客服信息(更新)
4954
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/18/749901f4e123170fb8a4d447ae6040ba.html">客服管理</a>
50-
* https://api.weixin.qq.com/customservice/kfaccount/update?access_token=ACCESS_TOKEN
55+
* 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/update?access_token=ACCESS_TOKEN
5156
* </pre>
5257
*/
5358
boolean kfAccountUpdate(WxMpKfAccountRequest request) throws WxErrorException;
54-
59+
5560
/**
5661
* <pre>
5762
* 上传客服头像
5863
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/18/749901f4e123170fb8a4d447ae6040ba.html">客服管理</a>
59-
* http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
64+
* 接口url格式:http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
6065
* </pre>
6166
*/
62-
63-
boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException;
64-
67+
boolean kfAccountUploadHeadImg(String kfAccount, File imgFile)
68+
throws WxErrorException;
69+
6570
/**
6671
* <pre>
6772
* 删除客服账号
6873
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/18/749901f4e123170fb8a4d447ae6040ba.html">客服管理</a>
69-
* https://api.weixin.qq.com/customservice/kfaccount/del?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
74+
* 接口url格式:https://api.weixin.qq.com/customservice/kfaccount/del?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
7075
* </pre>
7176
*/
7277
boolean kfAccountDel(String kfAccount) throws WxErrorException;
78+
79+
//*******************多客服会话控制接口***********************//
80+
/**
81+
* <pre>
82+
* 创建会话
83+
* 开发者可以使用本接口,为多客服的客服工号创建会话,将某个客户直接指定给客服工号接待,需要注意此接口不会受客服自动接入数以及自动接入开关限制。只能为在线的客服(PC客户端在线,或者已绑定多客服助手)创建会话。
84+
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/4/4b256cfb246b22ad020e07cf8a61a738.html">多客服会话控制接口</a>
85+
* 接口url格式: https://api.weixin.qq.com/customservice/kfsession/create?access_token=ACCESS_TOKEN
86+
* </pre>
87+
*/
88+
boolean kfSessionCreate(String openid, String kfAccount, String text) throws WxErrorException;
89+
90+
/**
91+
* <pre>
92+
* 关闭会话
93+
* 开发者可以使用本接口,关闭一个会话。
94+
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/4/4b256cfb246b22ad020e07cf8a61a738.html">多客服会话控制接口</a>
95+
* 接口url格式: https://api.weixin.qq.com/customservice/kfsession/close?access_token=ACCESS_TOKEN
96+
* </pre>
97+
*/
98+
boolean kfSessionClose(String openid, String kfAccount, String text) throws WxErrorException;
99+
100+
/**
101+
* <pre>
102+
* 获取客户的会话状态
103+
* 开发者可以通过本接口获取客户当前的会话状态。
104+
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/4/4b256cfb246b22ad020e07cf8a61a738.html">多客服会话控制接口</a>
105+
* 接口url格式: https://api.weixin.qq.com/customservice/kfsession/getsession?access_token=ACCESS_TOKEN&openid=OPENID
106+
* </pre>
107+
*/
108+
WxMpKfSessionGetResult kfSessionGet(String openid) throws WxErrorException;
109+
110+
/**
111+
* <pre>
112+
* 获取客服的会话列表
113+
* 开发者可以通过本接口获取某个客服正在接待的会话列表。
114+
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/4/4b256cfb246b22ad020e07cf8a61a738.html">多客服会话控制接口</a>
115+
* 接口url格式: https://api.weixin.qq.com/customservice/kfsession/getsessionlist?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
116+
* </pre>
117+
*/
118+
WxMpKfSessionList kfSessionList(String kfAccount) throws WxErrorException;
119+
120+
/**
121+
* <pre>
122+
* 获取未接入会话列表
123+
* 开发者可以通过本接口获取当前正在等待队列中的会话列表,此接口最多返回最早进入队列的100个未接入会话。
124+
* 详情请见:<a href="http://mp.weixin.qq.com/wiki/4/4b256cfb246b22ad020e07cf8a61a738.html">多客服会话控制接口</a>
125+
* 接口url格式: https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token=ACCESS_TOKEN
126+
* </pre>
127+
*/
128+
WxMpKfSessionWaitCaseList kfSessionGetWaitCase() throws WxErrorException;
73129
}

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java‎

Lines changed: 89 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
11
package me.chanjar.weixin.mp.api;
22

3-
import com.google.gson.*;
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.StringReader;
7+
import java.io.UnsupportedEncodingException;
8+
import java.net.URLEncoder;
9+
import java.nio.charset.StandardCharsets;
10+
import java.security.NoSuchAlgorithmException;
11+
import java.util.Arrays;
12+
import java.util.Date;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.Map;
16+
import java.util.Map.Entry;
17+
import java.util.SortedMap;
18+
import java.util.TreeMap;
19+
import java.util.UUID;
20+
21+
import org.apache.http.Consts;
22+
import org.apache.http.HttpHost;
23+
import org.apache.http.client.ClientProtocolException;
24+
import org.apache.http.client.config.RequestConfig;
25+
import org.apache.http.client.methods.CloseableHttpResponse;
26+
import org.apache.http.client.methods.HttpGet;
27+
import org.apache.http.client.methods.HttpPost;
28+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
29+
import org.apache.http.entity.StringEntity;
30+
import org.apache.http.impl.client.BasicResponseHandler;
31+
import org.apache.http.impl.client.CloseableHttpClient;
32+
import org.slf4j.Logger;
33+
import org.slf4j.LoggerFactory;
34+
import org.slf4j.helpers.MessageFormatter;
35+
36+
import com.google.gson.JsonArray;
37+
import com.google.gson.JsonElement;
38+
import com.google.gson.JsonObject;
39+
import com.google.gson.JsonParser;
40+
import com.google.gson.JsonPrimitive;
441
import com.google.gson.internal.Streams;
542
import com.google.gson.reflect.TypeToken;
643
import com.google.gson.stream.JsonReader;
744
import com.thoughtworks.xstream.XStream;
45+
846
import me.chanjar.weixin.common.api.WxConsts;
947
import me.chanjar.weixin.common.bean.WxAccessToken;
1048
import me.chanjar.weixin.common.bean.WxCardApiSignature;
@@ -19,43 +57,62 @@
1957
import me.chanjar.weixin.common.util.crypto.SHA1;
2058
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
2159
import me.chanjar.weixin.common.util.fs.FileUtils;
22-
import me.chanjar.weixin.common.util.http.*;
60+
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
61+
import me.chanjar.weixin.common.util.http.DefaultApacheHttpHttpClientBuilder;
62+
import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor;
63+
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
64+
import me.chanjar.weixin.common.util.http.RequestExecutor;
65+
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
66+
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
67+
import me.chanjar.weixin.common.util.http.URIUtil;
68+
import me.chanjar.weixin.common.util.http.Utf8ResponseHandler;
2369
import me.chanjar.weixin.common.util.json.GsonHelper;
2470
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
2571
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
2672
import me.chanjar.weixin.mp.api.impl.WxMpKefuServiceImpl;
27-
import me.chanjar.weixin.mp.bean.*;
28-
import me.chanjar.weixin.mp.bean.result.*;
29-
import me.chanjar.weixin.mp.util.http.*;
73+
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
74+
import me.chanjar.weixin.mp.bean.WxMpGroup;
75+
import me.chanjar.weixin.mp.bean.WxMpIndustry;
76+
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
77+
import me.chanjar.weixin.mp.bean.WxMpMassNews;
78+
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
79+
import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage;
80+
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
81+
import me.chanjar.weixin.mp.bean.WxMpMaterial;
82+
import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate;
83+
import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
84+
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
85+
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
86+
import me.chanjar.weixin.mp.bean.result.WxMediaImgUploadResult;
87+
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
88+
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
89+
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
90+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialCountResult;
91+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialFileBatchGetResult;
92+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialNewsBatchGetResult;
93+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult;
94+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult;
95+
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
96+
import me.chanjar.weixin.mp.bean.result.WxMpPayCallback;
97+
import me.chanjar.weixin.mp.bean.result.WxMpPayRefundResult;
98+
import me.chanjar.weixin.mp.bean.result.WxMpPayResult;
99+
import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult;
100+
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
101+
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
102+
import me.chanjar.weixin.mp.bean.result.WxMpUser;
103+
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
104+
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
105+
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
106+
import me.chanjar.weixin.mp.bean.result.WxRedpackResult;
107+
import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor;
108+
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
109+
import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor;
110+
import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor;
111+
import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor;
112+
import me.chanjar.weixin.mp.util.http.MediaImgUploadRequestExecutor;
113+
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
30114
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
31115

32-
import org.apache.commons.io.Charsets;
33-
import org.apache.http.Consts;
34-
import org.apache.http.HttpHost;
35-
import org.apache.http.client.ClientProtocolException;
36-
import org.apache.http.client.config.RequestConfig;
37-
import org.apache.http.client.methods.CloseableHttpResponse;
38-
import org.apache.http.client.methods.HttpGet;
39-
import org.apache.http.client.methods.HttpPost;
40-
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
41-
import org.apache.http.entity.StringEntity;
42-
import org.apache.http.impl.client.BasicResponseHandler;
43-
import org.apache.http.impl.client.CloseableHttpClient;
44-
import org.slf4j.Logger;
45-
import org.slf4j.LoggerFactory;
46-
import org.slf4j.helpers.MessageFormatter;
47-
48-
import java.io.File;
49-
import java.io.IOException;
50-
import java.io.InputStream;
51-
import java.io.StringReader;
52-
import java.io.UnsupportedEncodingException;
53-
import java.net.URLEncoder;
54-
import java.nio.charset.StandardCharsets;
55-
import java.security.NoSuchAlgorithmException;
56-
import java.util.*;
57-
import java.util.Map.Entry;
58-
59116
public class WxMpServiceImpl implements WxMpService {
60117

61118
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);

0 commit comments

Comments
 (0)