|
@@ -1,9 +1,17 @@
|
|
package me.chanjar.weixin.cp.api.impl;
|
|
package me.chanjar.weixin.cp.api.impl;
|
|
|
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import com.google.gson.JsonObject;
|
|
|
|
+import com.google.gson.JsonParser;
|
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
|
+import me.chanjar.weixin.common.error.WxError;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.cp.api.WxCpAgentService;
|
|
import me.chanjar.weixin.cp.api.WxCpAgentService;
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
import me.chanjar.weixin.cp.bean.WxCpAgent;
|
|
import me.chanjar.weixin.cp.bean.WxCpAgent;
|
|
|
|
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -15,6 +23,8 @@ import me.chanjar.weixin.cp.bean.WxCpAgent;
|
|
* @author <a href="https://github.com/huansinho">huansinho</a>
|
|
* @author <a href="https://github.com/huansinho">huansinho</a>
|
|
*/
|
|
*/
|
|
public class WxCpAgentServiceImpl implements WxCpAgentService {
|
|
public class WxCpAgentServiceImpl implements WxCpAgentService {
|
|
|
|
+ private static final JsonParser JSON_PARSER = new JsonParser();
|
|
|
|
+
|
|
private WxCpService mainService;
|
|
private WxCpService mainService;
|
|
|
|
|
|
public WxCpAgentServiceImpl(WxCpService mainService) {
|
|
public WxCpAgentServiceImpl(WxCpService mainService) {
|
|
@@ -32,4 +42,27 @@ public class WxCpAgentServiceImpl implements WxCpAgentService {
|
|
return WxCpAgent.fromJson(responseContent);
|
|
return WxCpAgent.fromJson(responseContent);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void set(WxCpAgent agentInfo) throws WxErrorException {
|
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/set";
|
|
|
|
+ String responseContent = this.mainService.post(url, agentInfo.toJson());
|
|
|
|
+ JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
|
|
|
+ if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
+ throw new WxErrorException(WxError.fromJson(responseContent));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<WxCpAgent> list() throws WxErrorException {
|
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/list";
|
|
|
|
+ String responseContent = this.mainService.get(url, null);
|
|
|
|
+ JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
|
|
|
+ if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
+ throw new WxErrorException(WxError.fromJson(responseContent));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return WxCpGsonBuilder.create().fromJson(jsonObject.get("agentlist").toString(), new TypeToken<List<WxCpAgent>>() {
|
|
|
|
+ }.getType());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|