1+ package cn .binarywang .wx .miniapp .api .impl ;
2+
3+ import cn .binarywang .wx .miniapp .api .WxMaKefuService ;
4+ import cn .binarywang .wx .miniapp .api .WxMaService ;
5+ import cn .binarywang .wx .miniapp .bean .kefu .WxMaKfInfo ;
6+ import cn .binarywang .wx .miniapp .bean .kefu .WxMaKfList ;
7+ import cn .binarywang .wx .miniapp .bean .kefu .WxMaKfSession ;
8+ import cn .binarywang .wx .miniapp .bean .kefu .WxMaKfSessionList ;
9+ import cn .binarywang .wx .miniapp .bean .kefu .request .WxMaKfAccountRequest ;
10+ import cn .binarywang .wx .miniapp .bean .kefu .request .WxMaKfSessionRequest ;
11+ import lombok .RequiredArgsConstructor ;
12+ import me .chanjar .weixin .common .error .WxErrorException ;
13+
14+ /**
15+ * 小程序客服管理服务实现.
16+ *
17+ * @author <a href="https://github.com/binarywang">Binary Wang</a>
18+ */
19+ @ RequiredArgsConstructor
20+ public class WxMaKefuServiceImpl implements WxMaKefuService {
21+
22+ // 小程序客服管理接口URL
23+ private static final String KFLIST_GET_URL = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist" ;
24+ private static final String KFACCOUNT_ADD_URL = "https://api.weixin.qq.com/customservice/kfaccount/add" ;
25+ private static final String KFACCOUNT_UPDATE_URL = "https://api.weixin.qq.com/customservice/kfaccount/update" ;
26+ private static final String KFACCOUNT_DEL_URL = "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account=%s" ;
27+ private static final String KFSESSION_CREATE_URL = "https://api.weixin.qq.com/customservice/kfsession/create" ;
28+ private static final String KFSESSION_CLOSE_URL = "https://api.weixin.qq.com/customservice/kfsession/close" ;
29+ private static final String KFSESSION_GET_URL = "https://api.weixin.qq.com/customservice/kfsession/getsession?openid=%s" ;
30+ private static final String KFSESSION_LIST_URL = "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?kf_account=%s" ;
31+
32+ private final WxMaService service ;
33+
34+ @ Override
35+ public WxMaKfList kfList () throws WxErrorException {
36+ String responseContent = this .service .get (KFLIST_GET_URL , null );
37+ return WxMaKfList .fromJson (responseContent );
38+ }
39+
40+ @ Override
41+ public boolean kfAccountAdd (WxMaKfAccountRequest request ) throws WxErrorException {
42+ String responseContent = this .service .post (KFACCOUNT_ADD_URL , request .toJson ());
43+ return responseContent != null ;
44+ }
45+
46+ @ Override
47+ public boolean kfAccountUpdate (WxMaKfAccountRequest request ) throws WxErrorException {
48+ String responseContent = this .service .post (KFACCOUNT_UPDATE_URL , request .toJson ());
49+ return responseContent != null ;
50+ }
51+
52+ @ Override
53+ public boolean kfAccountDel (String kfAccount ) throws WxErrorException {
54+ String url = String .format (KFACCOUNT_DEL_URL , kfAccount );
55+ String responseContent = this .service .get (url , null );
56+ return responseContent != null ;
57+ }
58+
59+ @ Override
60+ public boolean kfSessionCreate (String openid , String kfAccount ) throws WxErrorException {
61+ WxMaKfSessionRequest request = WxMaKfSessionRequest .builder ()
62+ .kfAccount (kfAccount )
63+ .openid (openid )
64+ .build ();
65+ String responseContent = this .service .post (KFSESSION_CREATE_URL , request .toJson ());
66+ return responseContent != null ;
67+ }
68+
69+ @ Override
70+ public boolean kfSessionClose (String openid , String kfAccount ) throws WxErrorException {
71+ WxMaKfSessionRequest request = WxMaKfSessionRequest .builder ()
72+ .kfAccount (kfAccount )
73+ .openid (openid )
74+ .build ();
75+ String responseContent = this .service .post (KFSESSION_CLOSE_URL , request .toJson ());
76+ return responseContent != null ;
77+ }
78+
79+ @ Override
80+ public WxMaKfSession kfSessionGet (String openid ) throws WxErrorException {
81+ String url = String .format (KFSESSION_GET_URL , openid );
82+ String responseContent = this .service .get (url , null );
83+ return WxMaKfSession .fromJson (responseContent );
84+ }
85+
86+ @ Override
87+ public WxMaKfSessionList kfSessionList (String kfAccount ) throws WxErrorException {
88+ String url = String .format (KFSESSION_LIST_URL , kfAccount );
89+ String responseContent = this .service .get (url , null );
90+ return WxMaKfSessionList .fromJson (responseContent );
91+ }
92+ }
0 commit comments