|
@@ -1,7 +1,10 @@ |
|
|
package me.chanjar.weixin.mp.api.impl; |
|
|
package me.chanjar.weixin.mp.api.impl; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject; |
|
|
|
|
|
import me.chanjar.weixin.common.bean.result.WxError; |
|
|
import me.chanjar.weixin.common.exception.WxErrorException; |
|
|
import me.chanjar.weixin.common.exception.WxErrorException; |
|
|
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; |
|
|
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; |
|
|
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; |
|
|
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; |
|
@@ -10,11 +13,7 @@ import me.chanjar.weixin.mp.api.WxMpKefuService; |
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; |
|
|
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; |
|
|
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest; |
|
|
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfSessionRequest; |
|
|
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList; |
|
|
|
|
|
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; |
|
|
|
|
|
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult; |
|
|
|
|
|
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList; |
|
|
|
|
|
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList; |
|
|
|
|
|
|
|
|
import me.chanjar.weixin.mp.bean.kefu.result.*; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
@@ -22,6 +21,7 @@ import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList; |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
|
|
|
public static final String API_URL_PREFIX = "https://api.weixin.qq.com/customservice"; |
|
|
private WxMpService wxMpService; |
|
|
private WxMpService wxMpService; |
|
|
|
|
|
|
|
|
public WxMpKefuServiceImpl(WxMpService wxMpService) { |
|
|
public WxMpKefuServiceImpl(WxMpService wxMpService) { |
|
@@ -30,7 +30,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxMpKfList kfList() throws WxErrorException { |
|
|
public WxMpKfList kfList() throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/getkflist"; |
|
|
String responseContent = this.wxMpService |
|
|
String responseContent = this.wxMpService |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
return WxMpKfList.fromJson(responseContent); |
|
|
return WxMpKfList.fromJson(responseContent); |
|
@@ -38,7 +38,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxMpKfOnlineList kfOnlineList() throws WxErrorException { |
|
|
public WxMpKfOnlineList kfOnlineList() throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/getonlinekflist"; |
|
|
String responseContent = this.wxMpService |
|
|
String responseContent = this.wxMpService |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
return WxMpKfOnlineList.fromJson(responseContent); |
|
|
return WxMpKfOnlineList.fromJson(responseContent); |
|
@@ -47,7 +47,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
@Override |
|
|
@Override |
|
|
public boolean kfAccountAdd(WxMpKfAccountRequest request) |
|
|
public boolean kfAccountAdd(WxMpKfAccountRequest request) |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfaccount/add"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfaccount/add"; |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
request.toJson()); |
|
|
request.toJson()); |
|
|
return true; |
|
|
return true; |
|
@@ -56,7 +56,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
@Override |
|
|
@Override |
|
|
public boolean kfAccountUpdate(WxMpKfAccountRequest request) |
|
|
public boolean kfAccountUpdate(WxMpKfAccountRequest request) |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfaccount/update"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfaccount/update"; |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
request.toJson()); |
|
|
request.toJson()); |
|
|
return true; |
|
|
return true; |
|
@@ -64,7 +64,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErrorException { |
|
|
public boolean kfAccountInviteWorker(WxMpKfAccountRequest request) throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfaccount/inviteworker"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfaccount/inviteworker"; |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
request.toJson()); |
|
|
request.toJson()); |
|
|
return true; |
|
|
return true; |
|
@@ -73,16 +73,14 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
@Override |
|
|
@Override |
|
|
public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) |
|
|
public boolean kfAccountUploadHeadImg(String kfAccount, File imgFile) |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?kf_account=" |
|
|
|
|
|
+ kfAccount; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfaccount/uploadheadimg?kf_account=" + kfAccount; |
|
|
this.wxMpService.execute(new MediaUploadRequestExecutor(), url, imgFile); |
|
|
this.wxMpService.execute(new MediaUploadRequestExecutor(), url, imgFile); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean kfAccountDel(String kfAccount) throws WxErrorException { |
|
|
public boolean kfAccountDel(String kfAccount) throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account=" |
|
|
|
|
|
+ kfAccount; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfaccount/del?kf_account=" + kfAccount; |
|
|
this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@@ -91,7 +89,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
public boolean kfSessionCreate(String openid, String kfAccount) |
|
|
public boolean kfSessionCreate(String openid, String kfAccount) |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid); |
|
|
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid); |
|
|
String url = "https://api.weixin.qq.com/customservice/kfsession/create"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfsession/create"; |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
request.toJson()); |
|
|
request.toJson()); |
|
|
return true; |
|
|
return true; |
|
@@ -101,7 +99,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
public boolean kfSessionClose(String openid, String kfAccount) |
|
|
public boolean kfSessionClose(String openid, String kfAccount) |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid); |
|
|
WxMpKfSessionRequest request = new WxMpKfSessionRequest(kfAccount, openid); |
|
|
String url = "https://api.weixin.qq.com/customservice/kfsession/close"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfsession/close"; |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
this.wxMpService.execute(new SimplePostRequestExecutor(), url, |
|
|
request.toJson()); |
|
|
request.toJson()); |
|
|
return true; |
|
|
return true; |
|
@@ -110,8 +108,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
@Override |
|
|
@Override |
|
|
public WxMpKfSessionGetResult kfSessionGet(String openid) |
|
|
public WxMpKfSessionGetResult kfSessionGet(String openid) |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfsession/getsession?openid=" |
|
|
|
|
|
+ openid; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfsession/getsession?openid=" + openid; |
|
|
String responseContent = this.wxMpService |
|
|
String responseContent = this.wxMpService |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
return WxMpKfSessionGetResult.fromJson(responseContent); |
|
|
return WxMpKfSessionGetResult.fromJson(responseContent); |
|
@@ -120,8 +117,7 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
@Override |
|
|
@Override |
|
|
public WxMpKfSessionList kfSessionList(String kfAccount) |
|
|
public WxMpKfSessionList kfSessionList(String kfAccount) |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?kf_account=" |
|
|
|
|
|
+ kfAccount; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfsession/getsessionlist?kf_account=" + kfAccount; |
|
|
String responseContent = this.wxMpService |
|
|
String responseContent = this.wxMpService |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
return WxMpKfSessionList.fromJson(responseContent); |
|
|
return WxMpKfSessionList.fromJson(responseContent); |
|
@@ -130,10 +126,28 @@ public class WxMpKefuServiceImpl implements WxMpKefuService { |
|
|
@Override |
|
|
@Override |
|
|
public WxMpKfSessionWaitCaseList kfSessionGetWaitCase() |
|
|
public WxMpKfSessionWaitCaseList kfSessionGetWaitCase() |
|
|
throws WxErrorException { |
|
|
throws WxErrorException { |
|
|
String url = "https://api.weixin.qq.com/customservice/kfsession/getwaitcase"; |
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/kfsession/getwaitcase"; |
|
|
String responseContent = this.wxMpService |
|
|
String responseContent = this.wxMpService |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
.execute(new SimpleGetRequestExecutor(), url, null); |
|
|
return WxMpKfSessionWaitCaseList.fromJson(responseContent); |
|
|
return WxMpKfSessionWaitCaseList.fromJson(responseContent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public WxMpKfMsgList kfMsgList(Date startTime, Date endTime, Integer msgId, Integer number) throws WxErrorException { |
|
|
|
|
|
if(startTime.after(endTime)){ |
|
|
|
|
|
throw new WxErrorException(WxError.newBuilder().setErrorMsg("起始时间不能晚于结束时间!").build()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String url = API_URL_PREFIX + "/msgrecord/getmsglist"; |
|
|
|
|
|
|
|
|
|
|
|
JsonObject param = new JsonObject(); |
|
|
|
|
|
param.addProperty("starttime", startTime.getTime() / 1000); //starttime 起始时间,unix时间戳 |
|
|
|
|
|
param.addProperty("endtime", endTime.getTime() / 1000); //endtime 结束时间,unix时间戳,每次查询时段不能超过24小时 |
|
|
|
|
|
param.addProperty("msgid", msgId); //msgid 消息id顺序从小到大,从1开始 |
|
|
|
|
|
param.addProperty("number", number); //number 每次获取条数,最多10000条 |
|
|
|
|
|
|
|
|
|
|
|
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, param.toString()); |
|
|
|
|
|
return WxMpKfMsgList.fromJson(responseContent); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |