33import java .io .File ;
44import java .util .Date ;
55
6+ import org .slf4j .Logger ;
7+ import org .slf4j .LoggerFactory ;
8+
69import com .google .gson .JsonObject ;
710
811import me .chanjar .weixin .common .bean .result .WxError ;
12+ import me .chanjar .weixin .common .bean .result .WxMediaUploadResult ;
913import me .chanjar .weixin .common .exception .WxErrorException ;
1014import me .chanjar .weixin .common .util .http .MediaUploadRequestExecutor ;
11- import me .chanjar .weixin .common .util .http .SimpleGetRequestExecutor ;
12- import me .chanjar .weixin .common .util .http .SimplePostRequestExecutor ;
1315import me .chanjar .weixin .mp .api .WxMpKefuService ;
1416import me .chanjar .weixin .mp .api .WxMpService ;
17+ import me .chanjar .weixin .mp .bean .WxMpCustomMessage ;
1518import me .chanjar .weixin .mp .bean .kefu .request .WxMpKfAccountRequest ;
1619import me .chanjar .weixin .mp .bean .kefu .request .WxMpKfSessionRequest ;
1720import me .chanjar .weixin .mp .bean .kefu .result .WxMpKfList ;
2730 *
2831 */
2932public class WxMpKefuServiceImpl implements WxMpKefuService {
33+ protected final Logger log = LoggerFactory
34+ .getLogger (WxMpKefuServiceImpl .class );
3035 private static final String API_URL_PREFIX = "https://api.weixin.qq.com/customservice" ;
3136 private WxMpService wxMpService ;
3237
3338 public WxMpKefuServiceImpl (WxMpService wxMpService ) {
3439 this .wxMpService = wxMpService ;
3540 }
3641
42+ @ Override
43+ public boolean customMessageSend (WxMpCustomMessage message )
44+ throws WxErrorException {
45+ String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send" ;
46+ String responseContent = this .wxMpService .post (url , message .toJson ());
47+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , message .toJson (),
48+ responseContent );
49+ return true ;
50+ }
51+
3752 @ Override
3853 public WxMpKfList kfList () throws WxErrorException {
39- String url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist" ;
40- String responseContent = this .wxMpService
41- .execute (new SimpleGetRequestExecutor (), url , null );
54+ String url = API_URL_PREFIX + "/getkflist" ;
55+ String responseContent = this .wxMpService .get (url , null );
56+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , null ,
57+ responseContent );
4258 return WxMpKfList .fromJson (responseContent );
4359 }
4460
4561 @ Override
4662 public WxMpKfOnlineList kfOnlineList () throws WxErrorException {
47- String url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist" ;
48- String responseContent = this .wxMpService
49- .execute (new SimpleGetRequestExecutor (), url , null );
63+ String url = API_URL_PREFIX + "/getonlinekflist" ;
64+ String responseContent = this .wxMpService .get (url , null );
65+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , null ,
66+ responseContent );
5067 return WxMpKfOnlineList .fromJson (responseContent );
5168 }
5269
5370 @ Override
5471 public boolean kfAccountAdd (WxMpKfAccountRequest request )
5572 throws WxErrorException {
5673 String url = API_URL_PREFIX + "/kfaccount/add" ;
57- this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
58- request .toJson ());
74+ String responseContent = this .wxMpService .post (url , request .toJson ());
75+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , request .toJson (),
76+ responseContent );
5977 return true ;
6078 }
6179
6280 @ Override
6381 public boolean kfAccountUpdate (WxMpKfAccountRequest request )
6482 throws WxErrorException {
6583 String url = API_URL_PREFIX + "/kfaccount/update" ;
66- this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
67- request .toJson ());
84+ String responseContent = this .wxMpService .post (url , request .toJson ());
85+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , request .toJson (),
86+ responseContent );
6887 return true ;
6988 }
7089
7190 @ Override
7291 public boolean kfAccountInviteWorker (WxMpKfAccountRequest request ) throws WxErrorException {
7392 String url = API_URL_PREFIX + "/kfaccount/inviteworker" ;
74- this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
75- request .toJson ());
93+ String responseContent = this .wxMpService .post (url , request .toJson ());
94+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , request .toJson (),
95+ responseContent );
7696 return true ;
7797 }
7898
7999 @ Override
80100 public boolean kfAccountUploadHeadImg (String kfAccount , File imgFile )
81101 throws WxErrorException {
82102 String url = API_URL_PREFIX + "/kfaccount/uploadheadimg?kf_account=" + kfAccount ;
83- this .wxMpService .execute (new MediaUploadRequestExecutor (), url , imgFile );
103+ WxMediaUploadResult responseContent = this .wxMpService
104+ .execute (new MediaUploadRequestExecutor (), url , imgFile );
105+ this .log .debug ("\n url:{}\n params:{}&file:{}\n response:{}" , url , kfAccount ,
106+ imgFile .getAbsolutePath (),
107+ responseContent );
84108 return true ;
85109 }
86110
87111 @ Override
88112 public boolean kfAccountDel (String kfAccount ) throws WxErrorException {
89113 String url = API_URL_PREFIX + "/kfaccount/del?kf_account=" + kfAccount ;
90- this .wxMpService .execute (new SimpleGetRequestExecutor (), url , null );
114+ String responseContent = this .wxMpService .get (url , null );
115+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , null ,
116+ responseContent );
91117 return true ;
92118 }
93119
@@ -96,8 +122,9 @@ public boolean kfSessionCreate(String openid, String kfAccount)
96122 throws WxErrorException {
97123 WxMpKfSessionRequest request = new WxMpKfSessionRequest (kfAccount , openid );
98124 String url = API_URL_PREFIX + "/kfsession/create" ;
99- this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
100- request .toJson ());
125+ String responseContent = this .wxMpService .post (url , request .toJson ());
126+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , request .toJson (),
127+ responseContent );
101128 return true ;
102129 }
103130
@@ -106,35 +133,39 @@ public boolean kfSessionClose(String openid, String kfAccount)
106133 throws WxErrorException {
107134 WxMpKfSessionRequest request = new WxMpKfSessionRequest (kfAccount , openid );
108135 String url = API_URL_PREFIX + "/kfsession/close" ;
109- this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
110- request .toJson ());
136+ String responseContent = this .wxMpService .post (url , request .toJson ());
137+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , request .toJson (),
138+ responseContent );
111139 return true ;
112140 }
113141
114142 @ Override
115143 public WxMpKfSessionGetResult kfSessionGet (String openid )
116144 throws WxErrorException {
117145 String url = API_URL_PREFIX + "/kfsession/getsession?openid=" + openid ;
118- String responseContent = this .wxMpService
119- .execute (new SimpleGetRequestExecutor (), url , null );
146+ String responseContent = this .wxMpService .get (url , null );
147+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , null ,
148+ responseContent );
120149 return WxMpKfSessionGetResult .fromJson (responseContent );
121150 }
122151
123152 @ Override
124153 public WxMpKfSessionList kfSessionList (String kfAccount )
125154 throws WxErrorException {
126155 String url = API_URL_PREFIX + "/kfsession/getsessionlist?kf_account=" + kfAccount ;
127- String responseContent = this .wxMpService
128- .execute (new SimpleGetRequestExecutor (), url , null );
156+ String responseContent = this .wxMpService .get (url , null );
157+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , null ,
158+ responseContent );
129159 return WxMpKfSessionList .fromJson (responseContent );
130160 }
131161
132162 @ Override
133163 public WxMpKfSessionWaitCaseList kfSessionGetWaitCase ()
134164 throws WxErrorException {
135165 String url = API_URL_PREFIX + "/kfsession/getwaitcase" ;
136- String responseContent = this .wxMpService
137- .execute (new SimpleGetRequestExecutor (), url , null );
166+ String responseContent = this .wxMpService .get (url , null );
167+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , null ,
168+ responseContent );
138169 return WxMpKfSessionWaitCaseList .fromJson (responseContent );
139170 }
140171
@@ -156,7 +187,9 @@ public WxMpKfMsgList kfMsgList(Date startTime, Date endTime, Long msgId, Integer
156187 param .addProperty ("msgid" , msgId ); //msgid 消息id顺序从小到大,从1开始
157188 param .addProperty ("number" , number ); //number 每次获取条数,最多10000条
158189
159- String responseContent = this .wxMpService .execute (new SimplePostRequestExecutor (), url , param .toString ());
190+ String responseContent = this .wxMpService .post (url , param .toString ());
191+ this .log .debug ("\n url:{}\n params:{}\n response:{}" , url , param .toString (),
192+ responseContent );
160193 return WxMpKfMsgList .fromJson (responseContent );
161194 }
162195
0 commit comments