1
1
package me .chanjar .weixin .mp .api .impl ;
2
2
3
3
import java .io .File ;
4
+ import java .util .Date ;
4
5
6
+ import com .google .gson .JsonObject ;
7
+ import me .chanjar .weixin .common .bean .result .WxError ;
5
8
import me .chanjar .weixin .common .exception .WxErrorException ;
6
9
import me .chanjar .weixin .common .util .http .MediaUploadRequestExecutor ;
7
10
import me .chanjar .weixin .common .util .http .SimpleGetRequestExecutor ;
10
13
import me .chanjar .weixin .mp .api .WxMpService ;
11
14
import me .chanjar .weixin .mp .bean .kefu .request .WxMpKfAccountRequest ;
12
15
import me .chanjar .weixin .mp .bean .kefu .request .WxMpKfSessionRequest ;
13
- import me .chanjar .weixin .mp .bean .kefu .result .WxMpKfList ;
14
- import me .chanjar .weixin .mp .bean .kefu .result .WxMpKfOnlineList ;
15
- import me .chanjar .weixin .mp .bean .kefu .result .WxMpKfSessionGetResult ;
16
- import me .chanjar .weixin .mp .bean .kefu .result .WxMpKfSessionList ;
17
- import me .chanjar .weixin .mp .bean .kefu .result .WxMpKfSessionWaitCaseList ;
16
+ import me .chanjar .weixin .mp .bean .kefu .result .*;
18
17
19
18
/**
20
19
*
21
20
* @author Binary Wang
22
21
*
23
22
*/
24
23
public class WxMpKefuServiceImpl implements WxMpKefuService {
24
+ public static final String API_URL_PREFIX = "https://api.weixin.qq.com/customservice" ;
25
25
private WxMpService wxMpService ;
26
26
27
27
public WxMpKefuServiceImpl (WxMpService wxMpService ) {
@@ -30,15 +30,15 @@ public WxMpKefuServiceImpl(WxMpService wxMpService) {
30
30
31
31
@ Override
32
32
public WxMpKfList kfList () throws WxErrorException {
33
- String url = "https://api.weixin.qq.com/cgi-bin/customservice /getkflist" ;
33
+ String url = API_URL_PREFIX + " /getkflist" ;
34
34
String responseContent = this .wxMpService
35
35
.execute (new SimpleGetRequestExecutor (), url , null );
36
36
return WxMpKfList .fromJson (responseContent );
37
37
}
38
38
39
39
@ Override
40
40
public WxMpKfOnlineList kfOnlineList () throws WxErrorException {
41
- String url = "https://api.weixin.qq.com/cgi-bin/customservice /getonlinekflist" ;
41
+ String url = API_URL_PREFIX + " /getonlinekflist" ;
42
42
String responseContent = this .wxMpService
43
43
.execute (new SimpleGetRequestExecutor (), url , null );
44
44
return WxMpKfOnlineList .fromJson (responseContent );
@@ -47,7 +47,7 @@ public WxMpKfOnlineList kfOnlineList() throws WxErrorException {
47
47
@ Override
48
48
public boolean kfAccountAdd (WxMpKfAccountRequest request )
49
49
throws WxErrorException {
50
- String url = "https://api.weixin.qq.com/customservice /kfaccount/add" ;
50
+ String url = API_URL_PREFIX + " /kfaccount/add" ;
51
51
this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
52
52
request .toJson ());
53
53
return true ;
@@ -56,15 +56,15 @@ public boolean kfAccountAdd(WxMpKfAccountRequest request)
56
56
@ Override
57
57
public boolean kfAccountUpdate (WxMpKfAccountRequest request )
58
58
throws WxErrorException {
59
- String url = "https://api.weixin.qq.com/customservice /kfaccount/update" ;
59
+ String url = API_URL_PREFIX + " /kfaccount/update" ;
60
60
this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
61
61
request .toJson ());
62
62
return true ;
63
63
}
64
64
65
65
@ Override
66
66
public boolean kfAccountInviteWorker (WxMpKfAccountRequest request ) throws WxErrorException {
67
- String url = "https://api.weixin.qq.com/customservice /kfaccount/inviteworker" ;
67
+ String url = API_URL_PREFIX + " /kfaccount/inviteworker" ;
68
68
this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
69
69
request .toJson ());
70
70
return true ;
@@ -73,16 +73,14 @@ public boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErro
73
73
@ Override
74
74
public boolean kfAccountUploadHeadImg (String kfAccount , File imgFile )
75
75
throws WxErrorException {
76
- String url = "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?kf_account="
77
- + kfAccount ;
76
+ String url = API_URL_PREFIX + "/kfaccount/uploadheadimg?kf_account=" + kfAccount ;
78
77
this .wxMpService .execute (new MediaUploadRequestExecutor (), url , imgFile );
79
78
return true ;
80
79
}
81
80
82
81
@ Override
83
82
public boolean kfAccountDel (String kfAccount ) throws WxErrorException {
84
- String url = "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account="
85
- + kfAccount ;
83
+ String url = API_URL_PREFIX + "/kfaccount/del?kf_account=" + kfAccount ;
86
84
this .wxMpService .execute (new SimpleGetRequestExecutor (), url , null );
87
85
return true ;
88
86
}
@@ -91,7 +89,7 @@ public boolean kfAccountDel(String kfAccount) throws WxErrorException {
91
89
public boolean kfSessionCreate (String openid , String kfAccount )
92
90
throws WxErrorException {
93
91
WxMpKfSessionRequest request = new WxMpKfSessionRequest (kfAccount , openid );
94
- String url = "https://api.weixin.qq.com/customservice /kfsession/create" ;
92
+ String url = API_URL_PREFIX + " /kfsession/create" ;
95
93
this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
96
94
request .toJson ());
97
95
return true ;
@@ -101,7 +99,7 @@ public boolean kfSessionCreate(String openid, String kfAccount)
101
99
public boolean kfSessionClose (String openid , String kfAccount )
102
100
throws WxErrorException {
103
101
WxMpKfSessionRequest request = new WxMpKfSessionRequest (kfAccount , openid );
104
- String url = "https://api.weixin.qq.com/customservice /kfsession/close" ;
102
+ String url = API_URL_PREFIX + " /kfsession/close" ;
105
103
this .wxMpService .execute (new SimplePostRequestExecutor (), url ,
106
104
request .toJson ());
107
105
return true ;
@@ -110,8 +108,7 @@ public boolean kfSessionClose(String openid, String kfAccount)
110
108
@ Override
111
109
public WxMpKfSessionGetResult kfSessionGet (String openid )
112
110
throws WxErrorException {
113
- String url = "https://api.weixin.qq.com/customservice/kfsession/getsession?openid="
114
- + openid ;
111
+ String url = API_URL_PREFIX + "/kfsession/getsession?openid=" + openid ;
115
112
String responseContent = this .wxMpService
116
113
.execute (new SimpleGetRequestExecutor (), url , null );
117
114
return WxMpKfSessionGetResult .fromJson (responseContent );
@@ -120,8 +117,7 @@ public WxMpKfSessionGetResult kfSessionGet(String openid)
120
117
@ Override
121
118
public WxMpKfSessionList kfSessionList (String kfAccount )
122
119
throws WxErrorException {
123
- String url = "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?kf_account="
124
- + kfAccount ;
120
+ String url = API_URL_PREFIX + "/kfsession/getsessionlist?kf_account=" + kfAccount ;
125
121
String responseContent = this .wxMpService
126
122
.execute (new SimpleGetRequestExecutor (), url , null );
127
123
return WxMpKfSessionList .fromJson (responseContent );
@@ -130,10 +126,28 @@ public WxMpKfSessionList kfSessionList(String kfAccount)
130
126
@ Override
131
127
public WxMpKfSessionWaitCaseList kfSessionGetWaitCase ()
132
128
throws WxErrorException {
133
- String url = "https://api.weixin.qq.com/customservice /kfsession/getwaitcase" ;
129
+ String url = API_URL_PREFIX + " /kfsession/getwaitcase" ;
134
130
String responseContent = this .wxMpService
135
131
.execute (new SimpleGetRequestExecutor (), url , null );
136
132
return WxMpKfSessionWaitCaseList .fromJson (responseContent );
137
133
}
138
134
135
+ @ Override
136
+ public WxMpKfMsgList kfMsgList (Date startTime , Date endTime , Integer msgId , Integer number ) throws WxErrorException {
137
+ if (startTime .after (endTime )){
138
+ throw new WxErrorException (WxError .newBuilder ().setErrorMsg ("起始时间不能晚于结束时间!" ).build ());
139
+ }
140
+
141
+ String url = API_URL_PREFIX + "/msgrecord/getmsglist" ;
142
+
143
+ JsonObject param = new JsonObject ();
144
+ param .addProperty ("starttime" , startTime .getTime () / 1000 ); //starttime 起始时间,unix时间戳
145
+ param .addProperty ("endtime" , endTime .getTime () / 1000 ); //endtime 结束时间,unix时间戳,每次查询时段不能超过24小时
146
+ param .addProperty ("msgid" , msgId ); //msgid 消息id顺序从小到大,从1开始
147
+ param .addProperty ("number" , number ); //number 每次获取条数,最多10000条
148
+
149
+ String responseContent = this .wxMpService .execute (new SimplePostRequestExecutor (), url , param .toString ());
150
+ return WxMpKfMsgList .fromJson (responseContent );
151
+ }
152
+
139
153
}
0 commit comments