Skip to content

Commit e169bcc

Browse files
committed
添加多客服中客服管理的6个接口
1 parent 1ebcd9c commit e169bcc

13 files changed

Lines changed: 725 additions & 24 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
/**
4+
*
5+
* @author Binary Wang
6+
*
7+
*/
8+
9+
public interface WxMpBaseChildService {
10+
/**
11+
* 设置WxMpService对象
12+
* @return
13+
*/
14+
void setWxMpService(WxMpService wxMpService);
15+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import java.io.File;
4+
5+
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;
9+
10+
/**
11+
* 客服接口 ,
12+
* 命名采用kefu拼音的原因是:
13+
* 其英文CustomerService如果再加上Service后缀显得有点啰嗦,
14+
* 如果不加又显得表意不完整
15+
* @author Binary Wang
16+
*
17+
*/
18+
public interface WxMpKefuService extends WxMpBaseChildService {
19+
/**
20+
* <pre>
21+
* 获取客服基本信息
22+
* 详情请见:<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
24+
* </pre>
25+
*/
26+
WxMpKfList kfList() throws WxErrorException;
27+
28+
/**
29+
* <pre>
30+
* 获取在线客服接待信息
31+
* 详情请见:<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
33+
* </pre>
34+
*/
35+
WxMpKfOnlineList kfOnlineList() throws WxErrorException;
36+
37+
/**
38+
* <pre>
39+
* 添加客服账号
40+
* 详情请见:<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
42+
* </pre>
43+
*/
44+
boolean kfAccountAdd(WxMpKfAccountRequest request) throws WxErrorException;
45+
46+
/**
47+
* <pre>
48+
* 设置客服信息(更新)
49+
* 详情请见:<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
51+
* </pre>
52+
*/
53+
boolean kfAccountUpdate(WxMpKfAccountRequest request) throws WxErrorException;
54+
55+
/**
56+
* <pre>
57+
* 上传客服头像
58+
* 详情请见:<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
60+
* </pre>
61+
*/
62+
63+
boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException;
64+
65+
/**
66+
* <pre>
67+
* 删除客服账号
68+
* 详情请见:<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
70+
* </pre>
71+
*/
72+
boolean kfAccountDel(String kfAccount) throws WxErrorException;
73+
}

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

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

3-
import me.chanjar.weixin.common.bean.WxCardApiSignature;
4-
import me.chanjar.weixin.common.bean.WxMenu;
5-
import me.chanjar.weixin.common.bean.WxJsapiSignature;
6-
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
7-
import me.chanjar.weixin.common.exception.WxErrorException;
8-
import me.chanjar.weixin.common.util.http.RequestExecutor;
9-
import me.chanjar.weixin.mp.bean.*;
10-
import me.chanjar.weixin.mp.bean.result.*;
11-
123
import java.io.File;
134
import java.io.IOException;
145
import java.io.InputStream;
@@ -17,6 +8,47 @@
178
import java.util.List;
189
import java.util.Map;
1910

11+
import me.chanjar.weixin.common.bean.WxCardApiSignature;
12+
import me.chanjar.weixin.common.bean.WxJsapiSignature;
13+
import me.chanjar.weixin.common.bean.WxMenu;
14+
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
15+
import me.chanjar.weixin.common.exception.WxErrorException;
16+
import me.chanjar.weixin.common.util.http.RequestExecutor;
17+
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
18+
import me.chanjar.weixin.mp.bean.WxMpGroup;
19+
import me.chanjar.weixin.mp.bean.WxMpIndustry;
20+
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
21+
import me.chanjar.weixin.mp.bean.WxMpMassNews;
22+
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
23+
import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage;
24+
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
25+
import me.chanjar.weixin.mp.bean.WxMpMaterial;
26+
import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate;
27+
import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
28+
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
29+
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
30+
import me.chanjar.weixin.mp.bean.result.WxMediaImgUploadResult;
31+
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
32+
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
33+
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
34+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialCountResult;
35+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialFileBatchGetResult;
36+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialNewsBatchGetResult;
37+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialUploadResult;
38+
import me.chanjar.weixin.mp.bean.result.WxMpMaterialVideoInfoResult;
39+
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
40+
import me.chanjar.weixin.mp.bean.result.WxMpPayCallback;
41+
import me.chanjar.weixin.mp.bean.result.WxMpPayRefundResult;
42+
import me.chanjar.weixin.mp.bean.result.WxMpPayResult;
43+
import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult;
44+
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
45+
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
46+
import me.chanjar.weixin.mp.bean.result.WxMpUser;
47+
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
48+
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
49+
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
50+
import me.chanjar.weixin.mp.bean.result.WxRedpackResult;
51+
2052
/**
2153
* 微信API的Service
2254
*/
@@ -1001,4 +1033,11 @@ public void markCardCode(String code, String cardId, String openId, boolean isMa
10011033
* @throws WxErrorException
10021034
*/
10031035
WxMpIndustry getIndustry() throws WxErrorException;
1036+
1037+
/**
1038+
* 返回客服接口方法实现类,以方便调用个其各种接口
1039+
* @return WxMpKefuService
1040+
*/
1041+
WxMpKefuService getKefuService();
1042+
10041043
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class WxMpServiceImpl implements WxMpService {
7474
protected final Object globalCardApiTicketRefreshLock = new Object();
7575

7676
protected WxMpConfigStorage wxMpConfigStorage;
77+
78+
protected WxMpKefuService kefuService;
7779

7880
protected CloseableHttpClient httpClient;
7981

@@ -1369,4 +1371,14 @@ public WxMpIndustry getIndustry() throws WxErrorException {
13691371
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
13701372
return WxMpIndustry.fromJson(responseContent);
13711373
}
1374+
1375+
@Override
1376+
public WxMpKefuService getKefuService() {
1377+
return this.kefuService;
1378+
}
1379+
1380+
public void setCustomerService(WxMpKefuService kefuService) {
1381+
this.kefuService = kefuService;
1382+
this.kefuService.setWxMpService(this);
1383+
}
13721384
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package me.chanjar.weixin.mp.api.impl;
2+
3+
import java.io.File;
4+
5+
import me.chanjar.weixin.common.exception.WxErrorException;
6+
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
7+
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
8+
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
9+
import me.chanjar.weixin.mp.api.WxMpKefuService;
10+
import me.chanjar.weixin.mp.api.WxMpService;
11+
import me.chanjar.weixin.mp.bean.customerservice.request.WxMpKfAccountRequest;
12+
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfList;
13+
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfOnlineList;
14+
15+
/**
16+
*
17+
* @author Binary Wang
18+
*
19+
*/
20+
public class WxMpKefuServiceImpl implements WxMpKefuService {
21+
private WxMpService wxMpService;
22+
23+
@Override
24+
public void setWxMpService(WxMpService wxMpService) {
25+
this.wxMpService = wxMpService;
26+
}
27+
28+
@Override
29+
public WxMpKfList kfList() throws WxErrorException {
30+
String url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist";
31+
String responseContent = this.wxMpService.execute(
32+
new SimpleGetRequestExecutor(), url, null);
33+
return WxMpKfList.fromJson(responseContent);
34+
}
35+
36+
@Override
37+
public WxMpKfOnlineList kfOnlineList() throws WxErrorException {
38+
String url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist";
39+
String responseContent = this.wxMpService.execute(
40+
new SimpleGetRequestExecutor(), url, null);
41+
return WxMpKfOnlineList.fromJson(responseContent);
42+
}
43+
44+
@Override
45+
public boolean kfAccountAdd(WxMpKfAccountRequest request) throws WxErrorException {
46+
String url = "https://api.weixin.qq.com/customservice/kfaccount/add";
47+
this.wxMpService.execute(new SimplePostRequestExecutor(), url, request.toJson());
48+
return true;
49+
}
50+
51+
@Override
52+
public boolean kfAccountUpdate(WxMpKfAccountRequest request) throws WxErrorException {
53+
String url = "https://api.weixin.qq.com/customservice/kfaccount/update";
54+
this.wxMpService.execute(new SimplePostRequestExecutor(), url, request.toJson());
55+
return true;
56+
}
57+
58+
@Override
59+
public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) throws WxErrorException {
60+
String url = "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?kf_account=" + kfAccount ;
61+
this.wxMpService.execute(new MediaUploadRequestExecutor(), url, imgFile);
62+
return true;
63+
}
64+
65+
@Override
66+
public boolean kfAccountDel(String kfAccount) throws WxErrorException {
67+
String url = "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account=" + kfAccount;
68+
this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null);
69+
return true;
70+
}
71+
72+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package me.chanjar.weixin.mp.bean.customerservice.request;
2+
3+
import java.io.Serializable;
4+
5+
import org.apache.commons.codec.digest.Md5Crypt;
6+
import org.apache.commons.lang3.builder.ToStringBuilder;
7+
8+
import com.google.gson.annotations.SerializedName;
9+
10+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
11+
12+
public class WxMpKfAccountRequest implements Serializable {
13+
private static final long serialVersionUID = -5451863610674856927L;
14+
15+
/**
16+
* kf_account 完整客服账号,格式为:账号前缀@公众号微信号
17+
*/
18+
@SerializedName("kf_account")
19+
private String kfAccount;
20+
21+
/**
22+
* nickname 客服昵称,最长6个汉字或12个英文字符
23+
*/
24+
@SerializedName("nickname")
25+
private String nickName;
26+
27+
/**
28+
* password 客服账号登录密码,格式为密码明文的32位加密MD5值
29+
*/
30+
@SerializedName("password")
31+
private String password;
32+
33+
/**
34+
* rawPassword 客服账号登录密码,明文密码,仅用于辅助操作
35+
*/
36+
@SerializedName("rawPassword")
37+
private String rawPassword;
38+
39+
@Override
40+
public String toString() {
41+
return ToStringBuilder.reflectionToString(this);
42+
}
43+
44+
public String toJson() {
45+
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
46+
}
47+
48+
public String getKfAccount() {
49+
return this.kfAccount;
50+
}
51+
52+
public void setKfAccount(String kfAccount) {
53+
this.kfAccount = kfAccount;
54+
}
55+
56+
public String getNickName() {
57+
return this.nickName;
58+
}
59+
60+
public void setNickName(String nickName) {
61+
this.nickName = nickName;
62+
}
63+
64+
public String getPassword() {
65+
return this.password;
66+
}
67+
68+
public void setPassword(String password) {
69+
this.password = password;
70+
}
71+
72+
public String getRawPassword() {
73+
return this.rawPassword;
74+
}
75+
76+
public void setRawPassword(String rawPassword) {
77+
this.rawPassword = rawPassword;
78+
}
79+
80+
public static Builder builder() {
81+
return new Builder();
82+
}
83+
84+
public static class Builder {
85+
private String kfAccount;
86+
private String nickName;
87+
private String password;
88+
private String rawPassword;
89+
90+
@SuppressWarnings("hiding")
91+
public Builder kfAccount(String kfAccount) {
92+
this.kfAccount = kfAccount;
93+
return this;
94+
}
95+
96+
@SuppressWarnings("hiding")
97+
public Builder nickName(String nickName) {
98+
this.nickName = nickName;
99+
return this;
100+
}
101+
102+
@SuppressWarnings("hiding")
103+
public Builder password(String password) {
104+
this.password = password;
105+
return this;
106+
}
107+
108+
@SuppressWarnings("hiding")
109+
public Builder rawPassword(String rawPassword) {
110+
this.rawPassword = rawPassword;
111+
this.password(Md5Crypt.md5Crypt(rawPassword.getBytes()));
112+
return this;
113+
}
114+
115+
public Builder from(WxMpKfAccountRequest origin) {
116+
this.kfAccount(origin.kfAccount);
117+
this.nickName(origin.nickName);
118+
this.password(origin.password);
119+
this.rawPassword(origin.rawPassword);
120+
return this;
121+
}
122+
123+
public WxMpKfAccountRequest build() {
124+
WxMpKfAccountRequest m = new WxMpKfAccountRequest();
125+
m.kfAccount = this.kfAccount;
126+
m.nickName = this.nickName;
127+
m.password = this.password;
128+
m.rawPassword = this.rawPassword;
129+
return m;
130+
}
131+
}
132+
133+
}

0 commit comments

Comments
 (0)